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

S

sonic

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?
 
J

John Saunders

sonic said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top