1.1: Setting ImageUrl of ImageButton does not work

Discussion in 'ASP .Net' started by DC, Jul 27, 2007.

  1. DC

    DC Guest

    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, Jul 27, 2007
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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, Jul 27, 2007
    #2
    1. Advertising

  3. DC

    DC Guest

    Re: Setting ImageUrl of ImageButton does not work

    On 27 Jul., 15:01, "George Ter-Saakov" <> 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" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > 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
    DC, Jul 30, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gary K
    Replies:
    2
    Views:
    440
    Gary K
    Jan 8, 2008
  2. doll
    Replies:
    0
    Views:
    565
  3. Pat
    Replies:
    2
    Views:
    619
    Göran Andersson
    Nov 6, 2008
  4. Pradeep

    ImageButton ImageURL question

    Pradeep, Jan 27, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    198
    Pradeep
    Jan 27, 2005
  5. Replies:
    0
    Views:
    624
Loading...

Share This Page