You need to ensure that you UserControl exists so the button click event is triggered when viewstate is rebuilt.
Loading your UserControl in the Page_Load will work the first time. When you click the button and the post_back occurs, Page_Load has not occurred yet. This means the UserControl will not exist, which mean the button does not exist for the event to be wired back up. So the UserControl with the button in it cannot be connected to the click event and the click event wont fire.
Recommend that your user control is loaded in this event.
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
//-- Create your controls here
}
Try a sandbox test. In page_load, dynamically create a button with a click event in the Page_Load. You will see that the click event does not fire. Now move the button to the OnLoad event. The click event will fire. Also note, the click event will occur before the Page_Load event. Further proof that the button does not exist at the right time.
Another idea...
You are reloading the usercontrol on the page before the button event occurs. Ensure your LoadControl method is inside the If block
if (!IsPostBack)
{
//load usercontrol
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…