473,748 Members | 9,931 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ProjectMg mt.Master,
MasterPage)
myMaster.CurFla g = "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 5312
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(ProjectMg mt.Master,
MasterPage)
myMaster.CurFla g = "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.Mas ter

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(ProjectMg mt.Master,
MasterPage)
myMaster.CurFla g = "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.Mas ter- Hide quoted text -

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

I think, ProjectMgmt.Mas ter 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(ProjectMg mt.Master,
MasterPage)
myMaster.CurFla g = "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
<SergeyPoberezo vs...@discussio ns.microsoft.co mwrote:
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(ProjectMg mt.Master,
MasterPage)
myMaster.CurFla g = "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.Ma ster,
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("MyM asterLabelText" ) = ModuleName.GetL abelText(...)
Master prerender:
MyLabel.Text = Me.Session("MyM asterLabelText" )

"Kirk" wrote:
On May 24, 6:26 pm, Sergey Poberezovskiy
<SergeyPoberezo vs...@discussio ns.microsoft.co mwrote:
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(ProjectMg mt.Master,
MasterPage)
myMaster.CurFla g = "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.Ma ster,
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.CurFla g = "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.Ma ster.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.CurFla g = "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.CurFla g = "value"

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

Thank you again for sticking with me on this one.

May 25 '07 #10

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

Similar topics

4
2469
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 nested master page between the content page and the top level master? For example, assume the very top level master is called CompanyWide.master. And the nested master page is called DepartmentA.master, which inherits from CompanyWide master. ...
4
1957
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 beside it to turn off the help. I wrote a public method in the master page that looks like this: public void tattle(string as_msg) { microhelp.Text = as_msg; }
5
2762
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" runat="server"> </asp:DropDownList> </ItemTemplate> </asp:TemplateField> I have the gridview inside of a master page- content hierarchy.
9
2651
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 to another location because it populates a Textbox in the user control page. Thanks Andrew
4
4015
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. In my masterpage I have this: private bool m_AlreadyTested; public bool AlreadyTested { get { return m_AlreadyTested; }
6
9159
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" %> On the Master Page I have a public property exposed: Public Property ErrorMessage() As String Get Return txtError.InnerText End Get
3
1572
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 controls, so I use the following statement to access them: Me.Page.FindControl(ControlID) However, this is returning Nothing, even though the control can be accessed in the Load event of the Page containing the control and the validator. I also...
1
1135
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 able to identify the Master page class and cannot access the master page's public methods.... Thanks...
5
2714
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 file is added by the webcontrol. This prevents me having to remember to add the CSS file to the page if I use a certain webcontrol. I have a MasterPage with an array of StyleSheets, and a public function for
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9548
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.