Strange Issue on replacing Image control with ImageButton control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jens.buchta@gmx.net

    Strange Issue on replacing Image control with ImageButton control

    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:TemplateCo lumn HeaderText="Ima ges">
    <ItemTemplate >
    <asp:Image id="imgPic" runat="server"
    OnPreRender="im gPic_PreRender" ></asp:Image>&nbsp ;
    <asp:ImageButto n id="ibtnPic" runat="server"
    OnPreRender="ib tnPic_PreRender "></asp:ImageButton >
    </ItemTemplate>
    </asp:TemplateCol umn>

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

    protected void imgPic_PreRende r(object sender, System.EventArg s e)
    {
    //this works as expected
    Image img = sender as Image;
    if (img == null)
    {
    return;
    }
    img.ImageURL = "dynamicall y-assigned.jpg";
    }

    protected void ibtnPic_PreRend er(object sender, System.EventArg s 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 = "dynamicall y-assigned.jpg";
    }

  • Eliyahu Goldin

    #2
    Re: Strange Issue on replacing Image control with ImageButton control

    Jens,

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

    Eliyahu

    <jens.buchta@gm x.net> wrote in message
    news:1125557636 .729770.63420@g 49g2000cwa.goog legroups.com...[color=blue]
    > 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:TemplateCo lumn HeaderText="Ima ges">
    > <ItemTemplate >
    > <asp:Image id="imgPic" runat="server"
    > OnPreRender="im gPic_PreRender" ></asp:Image>&nbsp ;
    > <asp:ImageButto n id="ibtnPic" runat="server"
    > OnPreRender="ib tnPic_PreRender "></asp:ImageButton >
    > </ItemTemplate>
    > </asp:TemplateCol umn>
    >
    > -------------------
    > CodeBehind
    >
    > protected void imgPic_PreRende r(object sender, System.EventArg s e)
    > {
    > //this works as expected
    > Image img = sender as Image;
    > if (img == null)
    > {
    > return;
    > }
    > img.ImageURL = "dynamicall y-assigned.jpg";
    > }
    >
    > protected void ibtnPic_PreRend er(object sender, System.EventArg s 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 = "dynamicall y-assigned.jpg";
    > }
    >[/color]


    Comment

    • jens.buchta@gmx.net

      #3
      Re: Strange Issue on replacing Image control with ImageButton control

      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

      Comment

      • Eliyahu Goldin

        #4
        Re: Strange Issue on replacing Image control with ImageButton control

        Why can't you handle the ImageUrl in Click event?

        Eliyahu

        <jens.buchta@gm x.net> wrote in message
        news:1125566088 .815538.95660@o 13g2000cwo.goog legroups.com...[color=blue]
        > 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
        >[/color]


        Comment

        Working...