473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Accessing a Master Page Property from a Module

I have been reading Scott Allen's article on Master Pages (http://
odetocode.com/Articles/450.aspx) but I am having problems
understanding a concept. Specifically, I have created a property
(called "CurFlag") on my master page that can be accessed from content
pages, but not from separate code modules.

I tried doing something like this in my VB code module:

Dim myMaster As MasterPage = CType(ProjectMgmt.Master,
MasterPage)
myMaster.CurFlag = "value"

....but this just gets me an "Reference to a non-shared member requires
an object reference" error on the first line. Forgive my ignorance,
but is my syntax correct, or do I need to add something additional to
the master page so that my module "sees" this master page?

I would appreciate any suggestions.
Thank you.

May 24 '07 #1
13 5281
On May 24, 10:18 pm, Kirk <lok...@hotmail.comwrote:
I have been reading Scott Allen's article on Master Pages (http://
odetocode.com/Articles/450.aspx) but I am having problems
understanding a concept. Specifically, I have created a property
(called "CurFlag") on my master page that can be accessed from content
pages, but not from separate code modules.

I tried doing something like this in my VB code module:

Dim myMaster As MasterPage = CType(ProjectMgmt.Master,
MasterPage)
myMaster.CurFlag = "value"

...but this just gets me an "Reference to a non-shared member requires
an object reference" error on the first line. Forgive my ignorance,
but is my syntax correct, or do I need to add something additional to
the master page so that my module "sees" this master page?

I would appreciate any suggestions.
Thank you.
The instance must first be declared as an object variable and then
referenced by the variable name.

Dim myMaster As MasterPage = new ProjectMgmt.Master

May 24 '07 #2
On May 24, 10:29 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On May 24, 10:18 pm, Kirk <lok...@hotmail.comwrote:


I have been reading Scott Allen's article on Master Pages (http://
odetocode.com/Articles/450.aspx) but I am having problems
understanding a concept. Specifically, I have created a property
(called "CurFlag") on my master page that can be accessed from content
pages, but not from separate code modules.
I tried doing something like this in my VB code module:
Dim myMaster As MasterPage = CType(ProjectMgmt.Master,
MasterPage)
myMaster.CurFlag = "value"
...but this just gets me an "Reference to a non-shared member requires
an object reference" error on the first line. Forgive my ignorance,
but is my syntax correct, or do I need to add something additional to
the master page so that my module "sees" this master page?
I would appreciate any suggestions.
Thank you.

The instance must first be declared as an object variable and then
referenced by the variable name.

Dim myMaster As MasterPage = new ProjectMgmt.Master- Hide quoted text -

- Show quoted text -
Wait... there must be a name of the class

I think, ProjectMgmt.Master is the name of your Master page

May 24 '07 #3
Kirk,

Not sure what are you trying to achieve - why would you need to access
master page (which is generally page specific - as different pages may have
different master pages) from a module? You will only want to access a
particular page's master page instance - in this case you will need a
reference to the page instance (or any control on the page) or to the master
itself.

If you need to change your master for all page - do it inside your Master,
and you will have the reference to it.

If you provide a bit more on what you are trying to achieve, it will be
easier to suggest a better way to accomplish the task.

"Kirk" wrote:
I have been reading Scott Allen's article on Master Pages (http://
odetocode.com/Articles/450.aspx) but I am having problems
understanding a concept. Specifically, I have created a property
(called "CurFlag") on my master page that can be accessed from content
pages, but not from separate code modules.

I tried doing something like this in my VB code module:

Dim myMaster As MasterPage = CType(ProjectMgmt.Master,
MasterPage)
myMaster.CurFlag = "value"

....but this just gets me an "Reference to a non-shared member requires
an object reference" error on the first line. Forgive my ignorance,
but is my syntax correct, or do I need to add something additional to
the master page so that my module "sees" this master page?

I would appreciate any suggestions.
Thank you.

May 24 '07 #4
On May 24, 6:26 pm, Sergey Poberezovskiy
<SergeyPoberezovs...@discussions.microsoft.comwrot e:
Kirk,

Not sure what are you trying to achieve - why would you need to access
master page (which is generally page specific - as different pages may have
different master pages) from a module? You will only want to access a
particular page's master page instance - in this case you will need a
reference to the page instance (or any control on the page) or to the master
itself.

If you need to change your master for all page - do it inside your Master,
and you will have the reference to it.

If you provide a bit more on what you are trying to achieve, it will be
easier to suggest a better way to accomplish the task.

"Kirk" wrote:
I have been reading Scott Allen's article on Master Pages (http://
odetocode.com/Articles/450.aspx) but I am having problems
understanding a concept. Specifically, I have created a property
(called "CurFlag") on my master page that can be accessed from content
pages, but not from separate code modules.
I tried doing something like this in my VB code module:
Dim myMaster As MasterPage = CType(ProjectMgmt.Master,
MasterPage)
myMaster.CurFlag = "value"
....but this just gets me an "Reference to a non-shared member requires
an object reference" error on the first line. Forgive my ignorance,
but is my syntax correct, or do I need to add something additional to
the master page so that my module "sees" this master page?
I would appreciate any suggestions.
Thank you.- Hide quoted text -

- Show quoted text -
Thanks for all of the replies. My situation is fairly simple: I have
one master page (called "ProjectMgmt.Master,
MasterPage") that has about 10 content pages.

I have a function in a VB module that does some math/validation for
me. This function is called by a button on a content page. When I
arrive at the result, I want to change a label on the master page (so
it is visible on all pages of the site).

Is there a better way to do what I am trying to accomplish? If so, I
would appreciate any code syntax examples you could give me. I don't
know the "proper" names for some objects, so I am unable to follow the
first reply's suggestion (just a newbie, I guess).

Thank you again.

If there is a better way to do this than

May 24 '07 #5
So, you want to only display this label (on all pages) after a certain event
happens on a page - correct? Then store this calculated value (in Session,
for example) and read it on your Master PreRender event (this will ensure
that all button clicks and similar events from other controls have already
been fired and processed).
Something similar to the following:
button click:
Me.Session("MyMasterLabelText") = ModuleName.GetLabelText(...)
Master prerender:
MyLabel.Text = Me.Session("MyMasterLabelText")

"Kirk" wrote:
On May 24, 6:26 pm, Sergey Poberezovskiy
<SergeyPoberezovs...@discussions.microsoft.comwrot e:
Kirk,

Not sure what are you trying to achieve - why would you need to access
master page (which is generally page specific - as different pages may have
different master pages) from a module? You will only want to access a
particular page's master page instance - in this case you will need a
reference to the page instance (or any control on the page) or to the master
itself.

If you need to change your master for all page - do it inside your Master,
and you will have the reference to it.

If you provide a bit more on what you are trying to achieve, it will be
easier to suggest a better way to accomplish the task.

"Kirk" wrote:
I have been reading Scott Allen's article on Master Pages (http://
odetocode.com/Articles/450.aspx) but I am having problems
understanding a concept. Specifically, I have created a property
(called "CurFlag") on my master page that can be accessed from content
pages, but not from separate code modules.
I tried doing something like this in my VB code module:
Dim myMaster As MasterPage = CType(ProjectMgmt.Master,
MasterPage)
myMaster.CurFlag = "value"
....but this just gets me an "Reference to a non-shared member requires
an object reference" error on the first line. Forgive my ignorance,
but is my syntax correct, or do I need to add something additional to
the master page so that my module "sees" this master page?
I would appreciate any suggestions.
Thank you.- Hide quoted text -
- Show quoted text -

Thanks for all of the replies. My situation is fairly simple: I have
one master page (called "ProjectMgmt.Master,
MasterPage") that has about 10 content pages.

I have a function in a VB module that does some math/validation for
me. This function is called by a button on a content page. When I
arrive at the result, I want to change a label on the master page (so
it is visible on all pages of the site).

Is there a better way to do what I am trying to accomplish? If so, I
would appreciate any code syntax examples you could give me. I don't
know the "proper" names for some objects, so I am unable to follow the
first reply's suggestion (just a newbie, I guess).

Thank you again.

If there is a better way to do this than

May 25 '07 #6
On May 25, 1:29 am, Kirk <lok...@hotmail.comwrote:
would appreciate any code syntax examples you could give me. I don't
know the "proper" names for some objects, so I am unable to follow the
first reply's suggestion (just a newbie, I guess).
Open the code-behind *.Master.vb

The name of your class you can find at the top of the file

Public Partial Class {className}

To make a proper "reference to a non-shared member" in you Module do
the following

Dim myMaster As MasterPage = New {className}
myMaster.CurFlag = "value"
.....

Should fix your problem, I hope :-)

May 25 '07 #7
I think you are on the right track, but I still have a problem.

The name of the class is shown like this in my master page
(ProjectMgmt.Master.vb):

Partial Public Class ProjectMgmt

And the property I added is called out like this (within the above
file):

Public Property CurFlag() As String

Therefore, I followed your example (thank you!) and came up with this:

Dim myMaster As MasterPage = New ProjectMgmt
myMaster.CurFlag = "value"

The first line has no errors, but the second once has this error:

"'CurFlag' is not not a member of 'System.Web.UI.MasterPage'."

I really don't know why I am seeing this error, as once the variable
myMaster is defined, it should be able to find the public property
CurFlag (right?).

Thank you again for following up with my problem. I would appreciate
any further suggestions you might have.

May 25 '07 #8
On May 25, 2:16 pm, Kirk <lok...@hotmail.comwrote:
"'CurFlag' is not not a member of 'System.Web.UI.MasterPage'."
Ah, sorry! it says about 'System.Web.UI.MasterPage' because it should
be

Dim myMaster As ProjectMgmt = New ProjectMgmt

or simply

Dim myMaster As New ProjectMgmt

hope it works now

May 25 '07 #9
Alexey, I think we are making progress, but I have yet another bug.

The code compiles correctly but I get an error as the property
attempts to assign the value. This is the property in the master
page:

Public Property CurFlag() As String
Get
Return lblFlag.Text
End Get
Set(ByVal value As String)
lblFlag.Text = value '<==Error here
End Set
End Property

When it gets to the marked line above, I get this error:

"Object reference not set to an instance of an object."

Actually, I can see this as a warning if I check this line

myMaster.CurFlag = "value"

If I hover my mouse over myMaster.CurFlag it gives this same error.
Do you have any suggestions?

Thank you again for sticking with me on this one.

May 25 '07 #10
On May 25, 3:55 pm, Kirk <lok...@hotmail.comwrote:
Alexey, I think we are making progress, but I have yet another bug.
That's great! it's not over yet :-)

The code compiles correctly but I get an error as the property
attempts to assign the value. This is the property in the master
page:

Public Property CurFlag() As String
Get
Return lblFlag.Text
End Get
Set(ByVal value As String)
lblFlag.Text = value '<==Error here
End Set
End Property

When it gets to the marked line above, I get this error:

"Object reference not set to an instance of an object."

Actually, I can see this as a warning if I check this line

myMaster.CurFlag = "value"

If I hover my mouse over myMaster.CurFlag it gives this same error.
Do you have any suggestions?
Okay, let me think here. You have a Master page, a module referenced
to the master, and a content page, right? Where do you call
myMaster.CurFlag = "value"? In the content page?

If true, I would suggest to make your life easier, as following:

module:

Public Class Class1

Public Shared Sub ChangeCurFlag(ByVal myMaster As ProjectMgmt)

myMaster.CurFlag = "value"

End Sub

aspx content page:

Class1.ChangeCurFlag(Me.Master)
May 25 '07 #11
On May 25, 2:52 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On May 25, 3:55 pm, Kirk <lok...@hotmail.comwrote:
Alexey, I think we are making progress, but I have yet another bug.

That's great! it's not over yet :-)


The code compiles correctly but I get an error as the property
attempts to assign the value. This is the property in the master
page:
Public Property CurFlag() As String
Get
Return lblFlag.Text
End Get
Set(ByVal value As String)
lblFlag.Text = value '<==Error here
End Set
End Property
When it gets to the marked line above, I get this error:
"Object reference not set to an instance of an object."
Actually, I can see this as a warning if I check this line
myMaster.CurFlag = "value"
If I hover my mouse over myMaster.CurFlag it gives this same error.
Do you have any suggestions?

Okay, let me think here. You have a Master page, a module referenced
to the master, and a content page, right? Where do you call
myMaster.CurFlag = "value"? In the content page?

If true, I would suggest to make your life easier, as following:

module:

Public Class Class1

Public Shared Sub ChangeCurFlag(ByVal myMaster As ProjectMgmt)

myMaster.CurFlag = "value"

End Sub

aspx content page:

Class1.ChangeCurFlag(Me.Master)- Hide quoted text -

- Show quoted text -
Alexey - Again, I greatly appreciate you persistence in trying to
resolve my problem.

First off - the example code you gave me works! ;-)

Unfortunately, in my effort to simplify my situation for a newsgroup
post, I have run into another issue. For my testing, I created a
button on a content page that called this function. In the final
solution, I want to call this function from a custom membership
provider module function. As membership functions are called
differently than a button, our example is not working (they reside in
the App_Code folder and are called automatically from any page). This
was my mistake in explaining - sorry! I assumed that a function or
class could be created in a separate module that could then be called
from anywhere (including my membership provider class).

Anyway, look at this line we put in the content page:

Class1.ChangeCurFlag(Me.Master)

The reason this works (as I understand it) is because of this section
in the content page's designer.vb file:

Public Shadows ReadOnly Property Master() As
Project_Management.ProjectMgmt
Get
Return CType(MyBase.Master,
Project_Management.ProjectMgmt)
End Get
End Property

Obviously, I don't have this in my membership provider module/class.
I tried adding it, but I can't "wire it up" so that the module knows
which master page to use.

Is there anyway to modify what you have come up with to make the
function "stupid"? That is, to make it so that the function always
uses my one-and-only Master page reference irregardless of where it
was called from? I guess this would involve removing the "ByVal
myMaster As ProjectMgmt" part of it, but I don't know what to put in
it's place.

Again, thank you for your continued support & sorry about my
misleading comments.

May 25 '07 #12
On May 25, 9:57 pm, Kirk <lok...@hotmail.comwrote:
On May 25, 2:52 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:


On May 25, 3:55 pm, Kirk <lok...@hotmail.comwrote:
Alexey, I think we are making progress, but I have yet another bug.
That's great! it's not over yet :-)
The code compiles correctly but I get an error as the property
attempts to assign the value. This is the property in the master
page:
Public Property CurFlag() As String
Get
Return lblFlag.Text
End Get
Set(ByVal value As String)
lblFlag.Text = value '<==Error here
End Set
End Property
When it gets to the marked line above, I get this error:
"Object reference not set to an instance of an object."
Actually, I can see this as a warning if I check this line
myMaster.CurFlag = "value"
If I hover my mouse over myMaster.CurFlag it gives this same error.
Do you have any suggestions?
Okay, let me think here. You have a Master page, a module referenced
to the master, and a content page, right? Where do you call
myMaster.CurFlag = "value"? In the content page?
If true, I would suggest to make your life easier, as following:
module:
Public Class Class1
Public Shared Sub ChangeCurFlag(ByVal myMaster As ProjectMgmt)
myMaster.CurFlag = "value"
End Sub
aspx content page:
Class1.ChangeCurFlag(Me.Master)- Hide quoted text -
- Show quoted text -

Alexey - Again, I greatly appreciate you persistence in trying to
resolve my problem.

First off - the example code you gave me works! ;-)

Unfortunately, in my effort to simplify my situation for a newsgroup
post, I have run into another issue. For my testing, I created a
button on a content page that called this function. In the final
solution, I want to call this function from a custom membership
provider module function. As membership functions are called
differently than a button, our example is not working (they reside in
the App_Code folder and are called automatically from any page). This
was my mistake in explaining - sorry! I assumed that a function or
class could be created in a separate module that could then be called
from anywhere (including my membership provider class).

Anyway, look at this line we put in the content page:

Class1.ChangeCurFlag(Me.Master)

The reason this works (as I understand it) is because of this section
in the content page's designer.vb file:

Public Shadows ReadOnly Property Master() As
Project_Management.ProjectMgmt
Get
Return CType(MyBase.Master,
Project_Management.ProjectMgmt)
End Get
End Property

Obviously, I don't have this in my membership provider module/class.
I tried adding it, but I can't "wire it up" so that the module knows
which master page to use.

Is there anyway to modify what you have come up with to make the
function "stupid"? That is, to make it so that the function always
uses my one-and-only Master page reference irregardless of where it
was called from? I guess this would involve removing the "ByVal
myMaster As ProjectMgmt" part of it, but I don't know what to put in
it's place.

Again, thank you for your continued support & sorry about my
misleading comments.- Hide quoted text -
If I were you I would create a public function in the membership
provider module to return a value and call that function in the master
page.

What do you think?

May 25 '07 #13
On May 25, 4:18 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On May 25, 9:57 pm, Kirk <lok...@hotmail.comwrote:


On May 25, 2:52 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On May 25, 3:55 pm, Kirk <lok...@hotmail.comwrote:
Alexey, I think we are making progress, but I have yet another bug.
That's great! it's not over yet :-)
The code compiles correctly but I get an error as the property
attempts to assign the value. This is the property in the master
page:
Public Property CurFlag() As String
Get
Return lblFlag.Text
End Get
Set(ByVal value As String)
lblFlag.Text = value '<==Error here
End Set
End Property
When it gets to the marked line above, I get this error:
"Object reference not set to an instance of an object."
Actually, I can see this as a warning if I check this line
myMaster.CurFlag = "value"
If I hover my mouse over myMaster.CurFlag it gives this same error.
Do you have any suggestions?
Okay, let me think here. You have a Master page, a module referenced
to the master, and a content page, right? Where do you call
myMaster.CurFlag = "value"? In the content page?
If true, I would suggest to make your life easier, as following:
module:
Public Class Class1
Public Shared Sub ChangeCurFlag(ByVal myMaster As ProjectMgmt)
myMaster.CurFlag = "value"
End Sub
aspx content page:
Class1.ChangeCurFlag(Me.Master)- Hide quoted text -
- Show quoted text -
Alexey - Again, I greatly appreciate you persistence in trying to
resolve my problem.
First off - the example code you gave me works! ;-)
Unfortunately, in my effort to simplify my situation for a newsgroup
post, I have run into another issue. For my testing, I created a
button on a content page that called this function. In the final
solution, I want to call this function from a custom membership
provider module function. As membership functions are called
differently than a button, our example is not working (they reside in
the App_Code folder and are called automatically from any page). This
was my mistake in explaining - sorry! I assumed that a function or
class could be created in a separate module that could then be called
from anywhere (including my membership provider class).
Anyway, look at this line we put in the content page:
Class1.ChangeCurFlag(Me.Master)
The reason this works (as I understand it) is because of this section
in the content page's designer.vb file:
Public Shadows ReadOnly Property Master() As
Project_Management.ProjectMgmt
Get
Return CType(MyBase.Master,
Project_Management.ProjectMgmt)
End Get
End Property
Obviously, I don't have this in my membership provider module/class.
I tried adding it, but I can't "wire it up" so that the module knows
which master page to use.
Is there anyway to modify what you have come up with to make the
function "stupid"? That is, to make it so that the function always
uses my one-and-only Master page reference irregardless of where it
was called from? I guess this would involve removing the "ByVal
myMaster As ProjectMgmt" part of it, but I don't know what to put in
it's place.
Again, thank you for your continued support & sorry about my
misleading comments.- Hide quoted text -

If I were you I would create a public function in the membership
provider module to return a value and call that function in the master
page.

What do you think?- Hide quoted text -

- Show quoted text -
Sounds like a good concept. I will experiment with what you have
given me and post back if I get stuck.
Thanx again.

May 25 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Steve Franks | last post by:
I have this cool nested master page scenario working great. However what is the correct way to be able to access a strongly typed property at the top level master from a content page that has a...
4
by: Rik Brooks | last post by:
OK, now I'm getting excited. I actually created a master page and added two content place holders to it. I also added a label which will serve as a sort of one line help and a little image button...
5
by: Siva | last post by:
Hello I have a dropdownlist inside the gridview as a template column defined as follows: <asp:TemplateField HeaderText="Choose Location"> <ItemTemplate> <asp:DropDownList ID="ddlChooseLoc"...
9
by: J055 | last post by:
Hi I have a standard asp page which uses a MasterPage. The MasterPage contains a User control. How can I access a public method in the User control from my WebForm page? I can't move the method...
4
by: evantay | last post by:
I'm using ASP.NET 2.0 with VS.NET 2005. I'm trying to access properties from my master pages within a page that inherits from that master page (a child page). However the values are always null....
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
3
by: Nathan Sokalski | last post by:
I have a validator that I wrote by inheriting from BaseValidator. At certain points in the code, I need to access other controls on the page containing the validator. I have the IDs of these...
1
by: Ned White | last post by:
Hi, How can I access the Master Page's public methods from a web user control ? Inside the user control, i can see the Page.Master using the this.Page.Master. However it does not seem to be...
5
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi guys I'm trying to make my code as streamlined as possible, and add CSS file references dynamically when they are required, for example, if a page contains a webcontrol, then the related CSS...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.