Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Event of a dynamically added user control doesn't fire

Reply
Thread Tools

Event of a dynamically added user control doesn't fire

 
 
niberhate
Guest
Posts: n/a
 
      04-24-2010
I have MyUserControlClass.cs as follows. You will see that

(1) LoadMyControl loads MyUserControl1, its CancelButtonEventHandler
is delegated to myControl1_CancelButtonClicked.

(2) In myControl1_CancelButtonClicked, MyUserControl2 is loaded, and
its NewButtonClickEventHandler is delegated to
myControl2_NewButtonClicked.

CancelButtonClicked event fires with no problem and MyUserControl2 is
successfully loaded upon firing.

But, the New button's click event isn't fired, in other words,
myControl2_NewButtonClicked doesn't get executed.

Note that MyEventArgs has been correctly implemented. Any idea to
share? Thanks.

//////////////////////////////
public partial class MyUserControlClass : System.Web.UI.UserControl
{

protected void Page_Load(object sender, EventArgs e)
{
LoadMyControl();
}

protected void LoadMyControl()
{
placeHolder1.Controls.Clear();
var myControl1 = LoadControl("~/UserControls/
MyUserControl1.ascx") as UserControls_MyUserControl1;
myControl1.ID = "myControl1Id";
myControl1.CancelButtonClicked += new
CancelButtonClickEventHandler(myControl1_CancelBut tonClicked);
placeHolder1.Controls.Add(myControl1);
}

// myControl1_CancelButtonClicked gets executed as expected.
protected void myControl1_CancelButtonClicked(object sender,
MyEventArgs e)
{
var myControl2 = LoadControl("~/UserControls/
MyUserControl2.ascx") as UserControls_MyUserControl2;
myControl2.ID = "myControl2Id";
myControl2.NewButtonClicked += new
NewButtonClickEventHandler(myControl2_NewButtonCli cked);
placeHolder2.Controls.Clear();
placeHolder2.Controls.Add(myControl2);
}

// New button click event either doesn't fire or doesn't get
captured, and the following
// method doesn't get executed.
protected void myControl2_NewButtonClicked(object sender,
MyEventArgs e)
{
// Do something here.
}

}
 
Reply With Quote
 
 
 
 
Cubaman
Guest
Posts: n/a
 
      04-26-2010
Take a look here. It solved a similar problem I had some time ago.
http://www.denisbauer.com/ASPNETCont...aceholder.aspx

Best regards


On Apr 24, 6:54*pm, niberhate <(E-Mail Removed)> wrote:
> I have MyUserControlClass.cs as follows. *You will see that
>
> (1) LoadMyControl loads MyUserControl1, its CancelButtonEventHandler
> is delegated to myControl1_CancelButtonClicked.
>
> (2) In myControl1_CancelButtonClicked, MyUserControl2 is loaded, and
> its NewButtonClickEventHandler is delegated to
> myControl2_NewButtonClicked.
>
> CancelButtonClicked event fires with no problem and MyUserControl2 is
> successfully loaded upon firing.
>
> But, the New button's click event isn't fired, in other words,
> myControl2_NewButtonClicked doesn't get executed.
>
> Note that MyEventArgs has been correctly implemented. *Any idea to
> share? Thanks.
>
> //////////////////////////////
> public partial class MyUserControlClass : System.Web.UI.UserControl
> {
>
> * * protected void Page_Load(object sender, EventArgs e)
> * * {
> * * * * LoadMyControl();
> * * }
>
> * * protected void LoadMyControl()
> * * {
> * * * * placeHolder1.Controls.Clear();
> * * * * var myControl1 = LoadControl("~/UserControls/
> MyUserControl1.ascx") as UserControls_MyUserControl1;
> * * * * myControl1.ID = "myControl1Id";
> * * * * myControl1.CancelButtonClicked += new
> CancelButtonClickEventHandler(myControl1_CancelBut tonClicked);
> * * * * placeHolder1.Controls.Add(myControl1);
> * * }
>
> * *// myControl1_CancelButtonClicked gets executed as expected.
> * * protected void myControl1_CancelButtonClicked(object sender,
> MyEventArgs e)
> * * {
> * * * * var myControl2 = LoadControl("~/UserControls/
> MyUserControl2.ascx") as UserControls_MyUserControl2;
> * * * * myControl2.ID = "myControl2Id";
> * * * * myControl2.NewButtonClicked += new
> NewButtonClickEventHandler(myControl2_NewButtonCli cked);
> * * * * placeHolder2.Controls.Clear();
> * * * * placeHolder2.Controls.Add(myControl2);
> * * }
>
> * *// New button click event either doesn't fire or doesn't get
> captured, and the following
> * *// method doesn't get executed.
> * * protected void myControl2_NewButtonClicked(object sender,
> MyEventArgs e)
> * * {
> * * * * // Do something here.
> * * }
>
> }


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically added WebControls requiring TWO clicks to fire event?!? iamurbal@gmail.com ASP .Net Web Controls 0 06-07-2005 03:49 PM
Handle Event of Dynamically Added User Control Jon B ASP .Net 5 04-30-2005 12:33 PM
Handle Event of Dynamically Added User Control Jon B ASP .Net Building Controls 5 04-30-2005 12:33 PM
Event fails to fire first time in dynamically loaded user control( =?Utf-8?B?U3RldmUgQm9vdGg=?= ASP .Net 6 04-06-2005 07:53 PM
Click event doesn't fire o dynamicly added user controls Henke ASP .Net 1 06-29-2004 03:15 PM



Advertisments