Masterpage class problem

Demon Cleaner
02-06-2007, 07:36 AM
Hi guys.

I'm trying to create a class which will allow me to have access to a masterpage's objects. Here is the code I'm using

(notes: my project's name is myPro and my masterpage's name is MasterPage)


Imports myPro.MasterPage
Imports System.Web.UI.Page

Public Class authorization_layer

Public a As New myPro.MasterPage
Public x As New System.Web.UI.Page

Public Function Retrive_User_Privilages(ByVal x As Integer)

CType(x.Master, a).TheMainInfoLabel = "blabla"

End Function

End Class


In the MasterPage.Master.vb i put some code to make a label's text property public


Public Property TheMainInfoLabel() As String
Get
Return Label6.Text
End Get
Set(ByVal value As String)
Label6.Text = value
End Set
End Property


I call my function as following

Dim auth As New authorization_layer()
auth.Retrive_User_Privilages(1)


Well, the above code doesn't work. I'm getting an error (VS Studio 2005) in this line


CType(x.Master, a).TheMainInfoLabel = "blabla"


saying that :
Type "a" is not defined

Can someone give a hint here cause I'm little confused. :-\

Thanks in advance.

wayneph
02-06-2007, 07:42 AM
a is a variable. not a type. you don't actually even need the variable.

This will work directly on a form:
CType(Me.Master, myPro.MasterPage).TheMainInfoLabel = "blabla"

To get it to work in a class, I would suggest passing in the form. You have another issue because you Dim x as a Page, and then turn around and pass x in as an integer. In your function x.Master has problems becauase x is an integer and doesn't have a Master property. I'd suggest something like this.

Public Function Retrive_User_Privilages(ByVal myForm As System.Web.Ui.Page)
CType(myForm.Master, myPro.MasterPage).TheMainInfoLabel = "blabla"
End Function

Demon Cleaner
02-06-2007, 07:52 AM
Thanks for your answer wayneph

I'm not on a VS machine right now but I'll test it tonight and I'll post the results.

Demon Cleaner
02-06-2007, 09:42 AM
Your suggestion worked perfectly :)

I really appreciate your help.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum