Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   1.1: Setting ImageUrl of ImageButton does not work (http://www.velocityreviews.com/forums/t525138-1-1-setting-imageurl-of-imagebutton-does-not-work.html)

DC 07-27-2007 09:37 AM

1.1: Setting ImageUrl of ImageButton does not work
 
Hi,

why does this not work:

<asp:ImageButton
id="myButt"
runat="server"
OnCommand="myButt_kick"
ImageUrl="<% =GetMyButtUrl() %>"
</asp:ImageButton>

( I get src="<% =GetMyButtUrl() %>" in the resulting HTML)

while this (in a DataGrid) works perfectly:

<ItemTemplate>
<asp:ImageButton
id="myButtInAGrid"
runat="server"
OnCommand="myButt_kick"
ImageUrl="<%# GetMyButtUrl() %>">
</asp:ImageButton>
</ItemTemplate>

Regards
DC


George Ter-Saakov 07-27-2007 01:01 PM

Re: Setting ImageUrl of ImageButton does not work
 
The <%= ... %> executed during rendering. But the object ImageButton is
created at the very beginning when Page is initialized.
That would explain why it does not work.

You simply can not attach to property of the ImageButton logic that is
executed during rendering. It has not run yet.

---------------------------
<%# GetMyButtUrl() %> called binding. To tell you the truth I am not sure
how it works. But my guess the .NET parser simply puts the code ImageUrl =
GetMyButtUrl(); when converts aspx page to C#.

So in your example simply replace <%= with <%# and it might work.
I am saying might because i am not sure how exactly <%# %> works and if any
additional things required from the object (in your case ImageButton) to
make it work.


George.




"DC" <dc@upsize.de> wrote in message
news:1185529063.965329.231640@22g2000hsm.googlegro ups.com...
> Hi,
>
> why does this not work:
>
> <asp:ImageButton
> id="myButt"
> runat="server"
> OnCommand="myButt_kick"
> ImageUrl="<% =GetMyButtUrl() %>"
> </asp:ImageButton>
>
> ( I get src="<% =GetMyButtUrl() %>" in the resulting HTML)
>
> while this (in a DataGrid) works perfectly:
>
> <ItemTemplate>
> <asp:ImageButton
> id="myButtInAGrid"
> runat="server"
> OnCommand="myButt_kick"
> ImageUrl="<%# GetMyButtUrl() %>">
> </asp:ImageButton>
> </ItemTemplate>
>
> Regards
> DC
>




DC 07-30-2007 01:56 PM

Re: Setting ImageUrl of ImageButton does not work
 
On 27 Jul., 15:01, "George Ter-Saakov" <gt-...@cardone.com> wrote:
> The <%= ... %> executed during rendering. But the object ImageButton is
> created at the very beginning when Page is initialized.
> That would explain why it does not work.
>
> You simply can not attach to property of the ImageButton logic that is
> executed during rendering. It has not run yet.
>
> ---------------------------
> <%# GetMyButtUrl() %> called binding. To tell you the truth I am not sure
> how it works. But my guess the .NET parser simply puts the code ImageUrl =
> GetMyButtUrl(); when converts aspx page to C#.
>
> So in your example simply replace <%= with <%# and it might work.
> I am saying might because i am not sure how exactly <%# %> works and if any
> additional things required from the object (in your case ImageButton) to
> make it work.
>
> George.
>
> "DC" <d...@upsize.de> wrote in message
>
> news:1185529063.965329.231640@22g2000hsm.googlegro ups.com...
>
>
>
> > Hi,

>
> > why does this not work:

>
> > <asp:ImageButton
> > id="myButt"
> > runat="server"
> > OnCommand="myButt_kick"
> > ImageUrl="<% =GetMyButtUrl() %>"
> > </asp:ImageButton>

>
> > ( I get src="<% =GetMyButtUrl() %>" in the resulting HTML)

>
> > while this (in a DataGrid) works perfectly:

>
> > <ItemTemplate>
> > <asp:ImageButton
> > id="myButtInAGrid"
> > runat="server"
> > OnCommand="myButt_kick"
> > ImageUrl="<%# GetMyButtUrl() %>">
> > </asp:ImageButton>
> > </ItemTemplate>

>
> > Regards
> > DC- Zitierten Text ausblenden -

>
> - Zitierten Text anzeigen -


Thank you, George. I tried using <%# ... %> outside a template, but it
does not work.

Regards
DC



All times are GMT. The time now is 05:21 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.