Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net Page_PreInit和事件_Asp.net_.net_Master Pages_Page Lifecycle - Fatal编程技术网

Asp.net Page_PreInit和事件

Asp.net Page_PreInit和事件,asp.net,.net,master-pages,page-lifecycle,Asp.net,.net,Master Pages,Page Lifecycle,我有一个问题…如果我的页面上有一个asp:按钮,我想在单击该按钮时切换母版页,那是不可能的,对吗 不可能,因为切换母版页需要在Page_PreInit中进行…但是按钮单击事件只有在执行Page_PreInit中的代码后才会发生 因此,如果我的Page_PreInit块中有这个: If buttonWasPressed Then Me.MasterPageFile = "newMaster.master" end If 它永远不会被执行 那么,如何通过单击按钮来更改母版页文件呢 谢谢

我有一个问题…如果我的页面上有一个asp:按钮,我想在单击该按钮时切换母版页,那是不可能的,对吗

不可能,因为切换母版页需要在Page_PreInit中进行…但是按钮单击事件只有在执行Page_PreInit中的代码后才会发生

因此,如果我的Page_PreInit块中有这个:

If buttonWasPressed Then
      Me.MasterPageFile = "newMaster.master"
end If
它永远不会被执行

那么,如何通过单击按钮来更改母版页文件呢

谢谢

在单击事件中:

Session("Master") = "newMaster.master"
Server.Transfer(Request.Url)
在页面_PreInit中:

Me.MasterPageFile = Session("Master") 

我想你需要重新加载页面才能做到这一点。你可以将母版页指针存储在会话变量或cookie中,然后检查并根据需要进行设置。是的,我当时想的正是steve写的,在会话内存中存储触发器,并在单击按钮时重新加载页面