generated imageButton does not receive click Event

Discussion in 'ASP .Net' started by gabriel, Aug 5, 2005.

  1. gabriel

    gabriel Guest

    greetings,

    I am currently stucked with the following problem :

    I got userControl which is programmatically fed ImageButtons. Then, in
    his render method, it creates a table containing the imagebuttons.

    When I Click on the imageButton, the browser should be redirected to
    some url.
    The thing is a gallery, as you might have guessed.

    here is the method used to feed the control :

    public void addImageButton(ImageButton image)
    {
    if (this.imageButtonList == null)
    this.imageButtonList = new ArrayList();
    this.imageButtonList.Add(image);
    image.CommandArgument = "1";
    image.CommandName = "gotoanyway";
    image.Command += new
    System.Web.UI.WebControls.CommandEventHandler(this.processImageCommand);
    image.Click += new System.Web.UI.ImageClickEventHandler
    (this.processImageClick);
    }

    I played with CommandEventHandler and ImageClickEventHandler but got no
    result. In fact, the event is not even captured.

    What I think is that the event is sent to the page but since she has no
    ImageClickEventHandler, the event is just lost.

    Is it possible to delegate the processing of the event from the page to
    the imageButton ?
    I do not know much yet about the delegate pattern, thus my question :)

    many thanks for your input !
     
    gabriel, Aug 5, 2005
    #1
    1. Advertising

  2. gabriel

    Teemu Keiski Guest

    Hi,

    it is because creating dynamical controls is too late in that phase(render)
    because postback events are "detected" after Page_load and then raised right
    after that. Dynamical control needs to be recreated on postback at Page_Load
    at the latest so that it can raise events during that request (e.g recreated
    in Load on that request during which control is expected to raise postback
    events)

    You can check this thread also for explanation:
    http://forums.asp.net/1008148/ShowPost.aspx

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke



    "gabriel" <> wrote in message
    news:42f32d97$0$18769$...
    > greetings,
    >
    > I am currently stucked with the following problem :
    >
    > I got userControl which is programmatically fed ImageButtons. Then, in
    > his render method, it creates a table containing the imagebuttons.
    >
    > When I Click on the imageButton, the browser should be redirected to some
    > url.
    > The thing is a gallery, as you might have guessed.
    >
    > here is the method used to feed the control :
    >
    > public void addImageButton(ImageButton image)
    > {
    > if (this.imageButtonList == null)
    > this.imageButtonList = new ArrayList();
    > this.imageButtonList.Add(image);
    > image.CommandArgument = "1";
    > image.CommandName = "gotoanyway";
    > image.Command += new
    > System.Web.UI.WebControls.CommandEventHandler(this.processImageCommand);
    > image.Click += new System.Web.UI.ImageClickEventHandler
    > (this.processImageClick);
    > }
    >
    > I played with CommandEventHandler and ImageClickEventHandler but got no
    > result. In fact, the event is not even captured.
    >
    > What I think is that the event is sent to the page but since she has no
    > ImageClickEventHandler, the event is just lost.
    >
    > Is it possible to delegate the processing of the event from the page to
    > the imageButton ?
    > I do not know much yet about the delegate pattern, thus my question :)
    >
    > many thanks for your input !
     
    Teemu Keiski, Aug 5, 2005
    #2
    1. Advertising

  3. gabriel

    gabriel Guest

    Re: generated imageButton does not receive click Event [SOLVED]

    Dynamical control needs to be recreated on postback at Page_Load
    > at the latest so that it can raise events during that request (e.g recreated
    > in Load on that request during which control is expected to raise postback
    > events)
    >
    > You can check this thread also for explanation:
    > http://forums.asp.net/1008148/ShowPost.aspx
    >


    Yes thank you very much !
    that was it, I needed to recreate the stuff
     
    gabriel, Aug 5, 2005
    #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. =?Utf-8?B?SiBNY0Q=?=

    Click event on an ImageButton column

    =?Utf-8?B?SiBNY0Q=?=, Feb 23, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    2,443
    Martin Dechev
    Feb 24, 2004
  2. Marc ENGEL
    Replies:
    0
    Views:
    443
    Marc ENGEL
    Jul 30, 2003
  3. Replies:
    4
    Views:
    535
  4. KhurramAtk
    Replies:
    1
    Views:
    234
    Paul Glavich [MVP ASP.NET]
    Mar 26, 2005
  5. James Tsao
    Replies:
    0
    Views:
    267
    James Tsao
    Oct 25, 2004
Loading...

Share This Page