Home All Groups Group Topic Archive Search About

Events not fired for Dynamically Created Controls in VS2005 ASP.NET 2.0

Author
7 Dec 2005 9:29 PM
Richard Huang
Following code worked for VS.NET 2005 Beta 2, but not for the final
release. When clicking the button, it posted back, but the
"addQL_Click" method is not called. Any suggestion would be very much
appreciated.

   public class MyEditor: EditorPart, INamingContainer
{
       protected override void CreateChildControls()
       {
           Controls.Clear();
           addButton("Add", "Add", new EventHandler(this.addQL_Click),
this.Controls);
           ChildControlsCreated = true;
}
       private void addButton(string buttonID, string buttonText,
EventHandler
myHandler, System.Web.UI.ControlCollection myControls)
       {
           Button _actionButton = new Button();
            _actionButton.ID = buttonID;
           _actionButton.Text = buttonText;
           if (myHandler != null)
               _actionButton.Click += myHandler;
           myControls.Add(_actionButton);
       }

       private void addQL_Click(object sender, EventArgs e)
       {
}
}

Author
9 Jan 2006 3:16 AM
JJ
Hi Richard,

I got this problem too. Any solutions?

Thanks

Show quoteHide quote
"Richard Huang" wrote:

> Following code worked for VS.NET 2005 Beta 2, but not for the final
> release. When clicking the button, it posted back, but the
> "addQL_Click" method is not called. Any suggestion would be very much
> appreciated.
>
>    public class MyEditor: EditorPart, INamingContainer
> {
>        protected override void CreateChildControls()
>        {
>            Controls.Clear();
>            addButton("Add", "Add", new EventHandler(this.addQL_Click),
> this.Controls);
>            ChildControlsCreated = true;
> }
>        private void addButton(string buttonID, string buttonText,
> EventHandler
> myHandler, System.Web.UI.ControlCollection myControls)
>        {
>            Button _actionButton = new Button();
>             _actionButton.ID = buttonID;
>            _actionButton.Text = buttonText;
>            if (myHandler != null)
>                _actionButton.Click += myHandler;
>            myControls.Add(_actionButton);
>        }
>
>        private void addQL_Click(object sender, EventArgs e)
>        {
> }
> }
>
>