When a user control is dynamically loaded, some attributes and methods of some controls are called, causing confusion in the control naming.
Because when you add a user control or loadcontrol
If the control ID and clientid are not specified, the initial ID is: "_ ctl0"
If you call textbox1.clientid --> in the user control before adding the user control to the page, the user control is named.
At this time, the user control has not been added to the page, so the clientid generated at this time certainly does not have the name of the parent control.
In addition, the initial ID of the sub-control is: "_ ctl0", and then go down, as long as it is not named _ ctl1, _ ctl2 ......
In this way, when the user control is truly added to the page, the user control does not specify the Control ID, then the user control ID will be
Initial ID: "_ ctl0"
We should see the problem.
The child control and the parent control have the same ID. As a result, the viewstate of textbox1 in the user control cannot be restored, and the button event cannot be triggered.
If you first add the user control to the page and then perform the operation, the control name in the user control will be changed:
User Control
ID type
_ Ctl0 ASP. webusercontrolpolicascx
_ Ctl0: _ ctl0 system. Web. UI. literalcontrol
_ Ctl0: button2 system. Web. UI. webcontrols. Button
_ Ctl0: _ ctl1 system. Web. UI. literalcontrol
............................
This will not cause duplicate names.