rendering Button inside Render() event, makes it loose its click event handler association

Discussion in 'ASP .Net' started by sonic, Jan 7, 2005.

  1. sonic

    sonic Guest

    I generate a button link control in following Manner.

    Button b = new Button();
    b.Click = MyEventHandler(...);

    If i add this button to current control with:
    this.Controls.Add( b );
    it will render, and its clicked event will be triggered properly.
    Unfortunately I do not have alot of control over where the button shows
    up.

    So I try to render it inside of protected override Render(...) event
    with:
    b.RenderControl( writer );

    Now the button shows up where I want it to, but its click event never
    triggers anymore.

    Any ideas why rendering it manually cancels out its click event
    association?
     
    sonic, Jan 7, 2005
    #1
    1. Advertising

  2. "sonic" <> wrote in message
    news:...
    >I generate a button link control in following Manner.
    >
    > Button b = new Button();
    > b.Click = MyEventHandler(...);
    >
    > If i add this button to current control with:
    > this.Controls.Add( b );
    > it will render, and its clicked event will be triggered properly.
    > Unfortunately I do not have alot of control over where the button shows
    > up.
    >
    > So I try to render it inside of protected override Render(...) event
    > with:
    > b.RenderControl( writer );
    >
    > Now the button shows up where I want it to, but its click event never
    > triggers anymore.
    >
    > Any ideas why rendering it manually cancels out its click event
    > association?


    Because it's not part of the control hierarchy. It's not because you
    rendered it manually, it's because you didn't add it to the Controls
    collection.

    Note that you can control where such a child control renders by using tables
    for layout and adding the child control to the appropriate TableCell.

    Also, a control in the Controls collection renders only when you call
    base.Render in your Render method. If you can do your rendering without
    calling base.Render, then you can have a control in the Controls collection
    and at the same time you can determine where it will render within the HTML:

    John Saunders
     
    John Saunders, Jan 7, 2005
    #2
    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.

Share This Page