Geeks With Blogs
Pankaj Tahiliani
Author : Pankaj Tahiliani
Technology : ASP.NET
Error : The 'MasterPageFile' property can only be set in or before the 'Page_PreInit' event.
Solution : At this point, the logical step is to move the line of code into Page_PreInit. Doing this in a real ASPX page avoids the above error (but doesn’t quite actually work). You need to OVERRIDE the PreInit event.

Protected Overrides Sub OnPreInit(ByVal e As System.EventArgs)
'++++++++++++++++++++++++++++++++++++++++++++++
' Check for login
' if logged in then change the master page template
'++++++++++++++++++++++++++++++++++++++++++++++
If IsNothing(Session("loginclass")) = False Then
If Session("loginclass").ToString() = "Customer" Then
Me.MasterPageFile = ("~/userMaster.master")
End If
End If
End Sub

Posted on Saturday, November 29, 2008 1:27 AM | Back to top


Comments on this post: The 'MasterPageFile' property can only be set in or before the 'Page_PreInit' event.

# re: The 'MasterPageFile' property can only be set in or before the 'Page_PreInit' event.
Requesting Gravatar...
your quote is working..thanks a lot
Left by ram on Jan 24, 2011 6:01 AM

# re: The 'MasterPageFile' property can only be set in or before the 'Page_PreInit' event.
Requesting Gravatar...
Works for me - Thanks !!
Left by SP2010 Developer on May 02, 2011 7:10 AM

# re: The 'MasterPageFile' property can only be set in or before the 'Page_PreInit' event.
Requesting Gravatar...
Thanks a lot for sharing this script with us but can you tell me how can we use it properly and where we have to paste this code? I'm a writer and provide research paper writing help online, therefore, I'm unable to understand about scripts and languages, it would be nice if you share pictures showing step by step process and it would be great for users like me.
Left by HenryFabian on Mar 11, 2018 2:33 PM

Your comment:
 (will show your gravatar)


Copyright © Pankaj Tahiliani | Powered by: GeeksWithBlogs.net