Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

1.1: Setting ImageUrl of ImageButton does not work

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DC - 27 Jul 2007 10:37 GMT
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 - 27 Jul 2007 14:01 GMT
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.

> Hi,
>
[quoted text clipped - 22 lines]
> Regards
> DC
DC - 30 Jul 2007 14:56 GMT
> The <%=  ... %> executed during rendering. But the object ImageButton is
> created at the very beginning when Page is initialized.
[quoted text clipped - 43 lines]
>
> - Zitierten Text anzeigen -

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

Regards
DC

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.