Avatar of gianitoo
gianitoo

asked on 

loading my masterpage dynamically

gettin this error?

Compiler Error Message: BC30451: Name 'legal2' is not declared.

Source Error:

 

Line 7:      Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs)
Line 8:          If Session("zona") = 1 Then
Line 9:              MasterPageFile = legal2.Master
Line 10:         Else
Line 11:            
 
ASP.NET

Avatar of undefined
Last Comment
gianitoo
Avatar of abel
abel
Flag of Netherlands image

You need to have legal2 defined. Maybe it is not in scope, maybe it doesn't exist. What do you expect it to be?
Avatar of gianitoo
gianitoo

ASKER

legal2.master is my other masterpage.  i need it to load depending on the session id.  
it does exist in the server.  
Avatar of gianitoo
gianitoo

ASKER

do i have to add something in the webconfig?

right now the page has this on top
<%@ Page Language="VB" MasterPageFile="legalother.master"  %>

so if session =1 then i want legal2.master to load instead
Avatar of abel
abel
Flag of Netherlands image

Ah, I think I see what you are getting at.

Use the directive MasterType to make a reference to the masterfile, like so and in your codebehind you can use Master to point to your masterpage.

But since you are setting the masterpage progammatically, I think you will have to use another way. It is not all too trivial, but not too hard either. I think the explanation given here does a much better job then I could by just repeating him: http://odetocode.com/Articles/450.aspx (see under PreInit, there's also a VB version of the code)
<%@ MasterType VirtualPath="~/Masterpages/Default.master" %>

Open in new window

Avatar of gianitoo
gianitoo

ASKER

dont understand much.  do u have a sample code?
Avatar of gianitoo
gianitoo

ASKER

this is my code right now.  all i need is to load  legal2.master instead ofthe current master page if session =1  else  stay the same.  how would you do it?

<%@ Page Language="VB" MasterPageFile="legalother.master"  %>


<%@ Register TagPrefix="custom" Namespace="myControls" %>
<script runat="server">

   

    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs)
        'If Session("zona") = 1 Then
        '    MasterPageFile = legal2.Master
        'Else

        'End If
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Session("compania") = Request.QueryString("ID")
       
    End Sub
</script>
Avatar of gianitoo
gianitoo

ASKER

any hope?
Avatar of abel
abel
Flag of Netherlands image

My apologies. I was looking too far off. Your request is way simpler then to create a complete handler for dealing with masterpages.

If the name of the masterpage is "legal2.master" all you need in the PreInit even is the following line of code:

MasterPageFile = "~/legal2.master"

I.e.: you need the string, not the literal name.

HTH,
Cheers,
-- Abel --
ASKER CERTIFIED SOLUTION
Avatar of abel
abel
Flag of Netherlands image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of abel
abel
Flag of Netherlands image

So you got it working? Great! & tx for the points ;)
Avatar of gianitoo
gianitoo

ASKER

si amigo!!!
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo