Strange Issue on replacing Image control with ImageButton control

Discussion in 'ASP .Net' started by jens.buchta@gmx.net, Sep 1, 2005.

  1. Guest

    Hi!

    I'm using a DataGrid with a template column to display an Image inside
    of it. I'm hooking into its OnPrerender-Event to set the
    ImageURL-Property dynamically.
    Everything works just fine here, until I thought "It would be cool, if
    the user could click on that image..". So I replaced the Image-Control
    with an ImageButton.

    My Problem is, that the ImageButton doesn't fire any events. Any other
    control works just fine but I'm having no luck getting the ImageButton
    to work.

    I'm happy about any ideas..

    Regards
    Jens


    ------------------------------------------------
    Code-Snippet

    -------------------
    aspx-Page

    <asp:TemplateColumn HeaderText="Images">
    <ItemTemplate>
    <asp:Image id="imgPic" runat="server"
    OnPreRender="imgPic_PreRender"></asp:Image>&nbsp;
    <asp:ImageButton id="ibtnPic" runat="server"
    OnPreRender="ibtnPic_PreRender"></asp:ImageButton>
    </ItemTemplate>
    </asp:TemplateColumn>

    -------------------
    CodeBehind

    protected void imgPic_PreRender(object sender, System.EventArgs e)
    {
    //this works as expected
    Image img = sender as Image;
    if (img == null)
    {
    return;
    }
    img.ImageURL = "dynamically-assigned.jpg";
    }

    protected void ibtnPic_PreRender(object sender, System.EventArgs e)
    {
    //this does not work
    //
    //if I rename this Method for testing purposes, the Page can't
    //be loaded, as it doesn't find this Method
    //
    //if I set a Break-Point to first method, the program does not
    //stop
    ImageButton ibtn = sender as ImageButton;
    if (ibtn == null)
    {
    return;
    }
    ibtn.ImageURL = "dynamically-assigned.jpg";
    }
     
    , Sep 1, 2005
    #1
    1. Advertising

  2. Guest

    Thanks for your Answer!

    I can set up the Click event to parse the CommandName and
    CommandArgument. This is a way to react on the users PostBack, no
    problem here.

    The problem is, that i need the PreRender event to handle the ImageURL
    before the ImageButton is drawn. At the moment, I can't catch this
    event in the same way, as it works for the Image-control, so that the
    image, the ImageButtons renders, is "none".

    Jens
     
    , Sep 1, 2005
    #2
    1. Advertising

  3. Jens,

    With thwe ImageButton you can setup both the Click and Command events. Do
    you setup one of them?

    Eliyahu

    <> wrote in message
    news:...
    > Hi!
    >
    > I'm using a DataGrid with a template column to display an Image inside
    > of it. I'm hooking into its OnPrerender-Event to set the
    > ImageURL-Property dynamically.
    > Everything works just fine here, until I thought "It would be cool, if
    > the user could click on that image..". So I replaced the Image-Control
    > with an ImageButton.
    >
    > My Problem is, that the ImageButton doesn't fire any events. Any other
    > control works just fine but I'm having no luck getting the ImageButton
    > to work.
    >
    > I'm happy about any ideas..
    >
    > Regards
    > Jens
    >
    >
    > ------------------------------------------------
    > Code-Snippet
    >
    > -------------------
    > aspx-Page
    >
    > <asp:TemplateColumn HeaderText="Images">
    > <ItemTemplate>
    > <asp:Image id="imgPic" runat="server"
    > OnPreRender="imgPic_PreRender"></asp:Image>&nbsp;
    > <asp:ImageButton id="ibtnPic" runat="server"
    > OnPreRender="ibtnPic_PreRender"></asp:ImageButton>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    >
    > -------------------
    > CodeBehind
    >
    > protected void imgPic_PreRender(object sender, System.EventArgs e)
    > {
    > //this works as expected
    > Image img = sender as Image;
    > if (img == null)
    > {
    > return;
    > }
    > img.ImageURL = "dynamically-assigned.jpg";
    > }
    >
    > protected void ibtnPic_PreRender(object sender, System.EventArgs e)
    > {
    > //this does not work
    > //
    > //if I rename this Method for testing purposes, the Page can't
    > //be loaded, as it doesn't find this Method
    > //
    > //if I set a Break-Point to first method, the program does not
    > //stop
    > ImageButton ibtn = sender as ImageButton;
    > if (ibtn == null)
    > {
    > return;
    > }
    > ibtn.ImageURL = "dynamically-assigned.jpg";
    > }
    >
     
    Eliyahu Goldin, Sep 1, 2005
    #3
  4. Why can't you handle the ImageUrl in Click event?

    Eliyahu

    <> wrote in message
    news:...
    > Thanks for your Answer!
    >
    > I can set up the Click event to parse the CommandName and
    > CommandArgument. This is a way to react on the users PostBack, no
    > problem here.
    >
    > The problem is, that i need the PreRender event to handle the ImageURL
    > before the ImageButton is drawn. At the moment, I can't catch this
    > event in the same way, as it works for the Image-control, so that the
    > image, the ImageButtons renders, is "none".
    >
    > Jens
    >
     
    Eliyahu Goldin, Sep 1, 2005
    #4
    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. RobertH
    Replies:
    3
    Views:
    4,826
    RobertH
    Feb 17, 2004
  2. Arthur Hsu
    Replies:
    5
    Views:
    6,018
    Steven Cheng[MSFT]
    Dec 8, 2004
  3. Gary K
    Replies:
    2
    Views:
    478
    Gary K
    Jan 8, 2008
  4. Jason

    image/imagebutton control

    Jason, Jun 13, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    129
    Jason
    Jun 13, 2004
  5. Rob Meade

    Replacing - and not Replacing...

    Rob Meade, Apr 5, 2005, in forum: ASP General
    Replies:
    5
    Views:
    316
    Chris Hohmann
    Apr 11, 2005
Loading...

Share This Page