質問

I have a question...if I have an asp:Button on my page, and I want that button, when clicked, to switch the masterpage, that would be impossible right?

Impossible because switching the masterpage needs to happen in Page_PreInit...but the button click event doesn't happen until after code in Page_PreInit is executed.

So if I had this in my Page_PreInit block:

If buttonWasPressed Then
      Me.MasterPageFile = "newMaster.master"
end If

It would never get executed.

So how can one change the master page file with the click of a button?

Thanks!

役に立ちましたか?

解決

In the click event:

Session("Master") = "newMaster.master"
Server.Transfer(Request.Url)

In the Page_PreInit:

Me.MasterPageFile = Session("Master") 
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top