我有以下情況:在UserControl中設置母版頁中的值
A MasterPage MyMaster.Master
A內容頁面Content.aspx
用戶控件MyUserControl.ascx
MyUserControl.ascx用於Content.aspx和正在以編程方式添加。內容頁面使用MyMaster.Master
MyMaster.Master有一個變量我可以從Content.aspx訪問,因爲我有@MasterType指令集。我想要做的是以下內容:
1)在MyUserControl.ascx中設置一個值
2)從Content.aspx訪問值
3)在MyMaster.Master中設置值
第2步在contentLo的content.aspx中實現,如下所示:
Control ucControl= LoadControl("/UserControls/MyUserControl.ascx");
UserControls_MyUserControl myUC = ucControl as UserControls_MyUserControl;
//Do some caching stuff here
if (myUC != null)
myUC.PreRender += new EventHandler(myUC_PreRender);
PreRender處理程序只是將MyMaster.Master中的值設置爲true。在MyMaster.Master中,我在PageLoad中檢查該值,並嘗試顯示它是否爲真。這不起作用。
我懷疑它與頁面生命週期有關,但我似乎無法找到哪個部分是錯誤的。
任何幫助非常感謝。
謝謝