1.1: Setting ImageUrl of ImageButton does not work

D

DC

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
 
G

George Ter-Saakov

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.
 
D

DC

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.












- Zitierten Text anzeigen -

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

Regards
DC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top