event from dynamically loaded usercontrol gets fired once for 2 clicks

D

Dan

hi,
i have a page with two usercontrols:
1. a static menu control.
2. a dynamically loaded control as user interface

the main page receives events from the menu and sets the apropriate
ui control in the OnBubbleEvent method.
but now, the ui control doesnt't fire any events any more. i first have
to do another postback, and now the ui fires again.
what's wrong there?
it seems to me that only if the actual usercontrol has been added in the
pageload method, the control somehow is asigned to the page.
if the uc gets added later (OnBubbleEvent), the conection seems to get lost.

here some code:

main page:
private void Page_Load(object sender, System.EventArgs e)
{
control=this.LoadControl("x");
this.FindControl("Form1").Controls.Add(control);
}

override protected bool OnBubbleEvent(object sender, System.EventArgs e)

{
int index=this.FindControl("Form1").Controls.IndexOf(control);
//if menu button has been clicked, load the apropriate uc:
control=this.LoadControl("x");
this.FindControl("Form1").Controls.RemoveAt(index);
this.FindControl("Form1").Controls.Add(control);
}

as soon as the control stems from the OnBubbleEvent, nothing gets fired.
when the button of the control gets clicked another time (postback)
and the pageload sets the actual control, everything is fine again.
so, the event fires only 50% of the click.
i don't understand that.

thanks very much for any help.
dan
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top