关于LoadControl的一个问题
我在text.aspx页面上用LoadControl加载一个用户控件MyControl.ascx,MyControl.ascx上有一个TextBox控件和一个Button。
当我点击Button时,在MyControl.asx的Page_Load事件中TextBox.text的值总是空的,但我在Button_OnClick却能得到TextBox.text
请问:系统在什么时候给TextBox赋的值?
------解决方案--------------------
看看控件的生命周期可能对你有帮助:
http://blog.csdn.net/AppleBBS/archive/2007/04/16/1566592.aspx
------解决方案--------------------PreInit Event : If the request is a postback, the values of the controls have not yet been restored from view state. If you set a control property at this stage, its value might be overwritten in the next event.
Control events
Control events
LoadComplete events
SaveStateComplete events : Before this event occurs, ViewState has been saved for the page and for all controls. Any changes to the page or controls at this point will be ignored.
Use this event perform tasks that require view state to be saved, but that do not make any changes to controls.
------解决方案--------------------
For more information, see : ASP.NET Page Life Cycle Overview
http://msdn2.microsoft.com/en-us/library/ms178472.aspx