G
Guest
Hi, I have built a custom control button which inherits from WebControl and
implements IPostBackEventHandler. The control also declares an event Click
and provides a method OnClick which invokes the registered delegate. All is
fine with my control until I try to add it to the page dynamically in a code
behind event handler and wire-up the click event using the normal syntax such
that;
protected void btnNew_Click(object sender, EventArgs e)
{
...
BDTextButton bdtbSave = new BDTextButton();
...
...
bdtbSave.ID = "btnSave";
bdtbSave.Click += new EventHandler(this.btnSave_OnClick);
When I do this the PostBack occurs but the event isn’t handled by the
handler I provid, i.e. the event didn’t seem to register.
After reading many posts I thought this may be because I was trying to
register the event too late in the page’s lifecycle. But, as a test I
dynamically added a Button webcontrol alongside my customcontrol and wired-up
an event handler for this which worked!
For further info my control is not a composite control it uses the Render
event to write it’s content using the HtmlTextWriter.
Why doesn’t my custom control’s event get registered when a webcontrol does?
implements IPostBackEventHandler. The control also declares an event Click
and provides a method OnClick which invokes the registered delegate. All is
fine with my control until I try to add it to the page dynamically in a code
behind event handler and wire-up the click event using the normal syntax such
that;
protected void btnNew_Click(object sender, EventArgs e)
{
...
BDTextButton bdtbSave = new BDTextButton();
...
...
bdtbSave.ID = "btnSave";
bdtbSave.Click += new EventHandler(this.btnSave_OnClick);
When I do this the PostBack occurs but the event isn’t handled by the
handler I provid, i.e. the event didn’t seem to register.
After reading many posts I thought this may be because I was trying to
register the event too late in the page’s lifecycle. But, as a test I
dynamically added a Button webcontrol alongside my customcontrol and wired-up
an event handler for this which worked!
For further info my control is not a composite control it uses the Render
event to write it’s content using the HtmlTextWriter.
Why doesn’t my custom control’s event get registered when a webcontrol does?