473,386 Members | 1,819 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.

Master Page custom property always null :(

I have a Master Page with a property defined in codebehind like this:

private string profile;

public string Profile {
get { return profile; }
}

I can set the property value in the master page fine (normally
page_load or page_preinit), i.e.:

profile = "custom";

In the page that uses the Master page, I can see the property like
this:

string test = Master.Profile;

But, The property is ALWAYS null. It never saves the value I give it
in the Master Page codebehind. Is there any way around this issue? I
would like to pre-initialize some common properties without having to
copy the code into each aspx page. Thanks for the help!

Kyle

Feb 22 '06 #1
4 2360
Consider using AppSettings, they are quite easy to use, and easy to set.
http://msdn2.microsoft.com/en-us/lib...54(VS.80).aspx

web.config:
<appSettings>
<add key="myvar" value="test1234" />
</appSettings>

code:
string myvar = ConfigurationManager.AppSettings["myvar"]
or if it is a per-user setting, the Profile / ProfileManager could be the
answer
http://msdn2.microsoft.com/en-us/lib...le(VS.80).aspx
A ready to use "SqlProfileProvider" is provided with 2.0 out-of-the-box
Just make a database, prep it with the aspnet_regsql.exe, and setup the
connectionstring.


<fi****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I have a Master Page with a property defined in codebehind like this:

private string profile;

public string Profile {
get { return profile; }
}

I can set the property value in the master page fine (normally
page_load or page_preinit), i.e.:

profile = "custom";

In the page that uses the Master page, I can see the property like
this:

string test = Master.Profile;

But, The property is ALWAYS null. It never saves the value I give it
in the Master Page codebehind. Is there any way around this issue? I
would like to pre-initialize some common properties without having to
copy the code into each aspx page. Thanks for the help!

Kyle

Feb 22 '06 #2
Unfortunately, we do not use SQL server and I cannot create new DB
tables at this point.

There were a few things I wanted to do in the Master page that I could
reference in the other pages:
1. Read and store cookie + settings
2. Initialize webservice
3. Save form factor information.

Unfortunately, any properties I create in the Master are always null in
the client page unless I set them explicitly in the client page. I can
access properties of controls on the page, but using controls would be
a pretty bad solution.

Am I right in thinking that custom Master Page properties that have
values set in the Master Page code behind should be accessible in the
client pages? Is there some Asp.net setting I have to set somewhere
for this to work?

Thanks for the help,
Kyle

Feb 22 '06 #3
There were a few things I wanted to do in the Master page that I could
reference in the other pages:
1. Read and store cookie + settings
2. Initialize webservice
3. Save form factor information.
Then I would either make a httpModule, or consider using session ... the
masterpage is not the place to store this stuff

Unfortunately, any properties I create in the Master are always null in
the client page unless I set them explicitly in the client page. I can
access properties of controls on the page, but using controls would be
a pretty bad solution.

Am I right in thinking that custom Master Page properties that have
values set in the Master Page code behind should be accessible in the
client pages? Is there some Asp.net setting I have to set somewhere
for this to work?


Yeah, they should be accessible in the client page, the problem could be
that the page events for the master and the page execute at diffrent times.
- Try overriding the OnInit() event in the master, and assign the properties
there.


Feb 22 '06 #4
You are correct. I just found this document:

http://msdn2.microsoft.com/en-us/library/dct97kc3.aspx

It lists the order of the Init/Load/PreRender events for Master and
Content pages. There is no PreInit, and the Master's OnLoad event
happens AFTER the Content page.

By moving everything into the Page_Init event, I have solved my
problems.

Thanks for the help!

Kyle

Feb 22 '06 #5

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

Similar topics

2
by: Jon Spivey | last post by:
Hi, Using VS 2005/VB.net. I need to add a meta description tag and change a stylesheet link from a page based on a master page. Found this article...
1
by: shapper | last post by:
Hello, I created a property in my master page and I want to expose a panel to the page which uses this master: Private _Center As Panel Public Property Center() As Panel Get Return _Center...
7
by: Just Me | last post by:
Hi I have a master page with a control on it, but I need to set a property of that control from the content. my master page is called Admin.Master and the class is Admin. I have tried this
7
by: =?Utf-8?B?TWFyaw==?= | last post by:
keywords: asp.net master page rubbish I have written a custom control. The control is a simple html Tab menu control. The control inherits from DataBoundControl and implements INamingContainer,...
3
by: William Youngman | last post by:
I am on a team that is developing a proposal generation web application and we are using a custom base page (ProGenBase.cs) located in the app_code directory and all of the app's web pages inherit...
13
by: Kirk | last post by:
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...
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....
4
by: lichaoir | last post by:
I have two questions about the use of Master Page: 1. How to access properties and controls in the master page from content page? (I know I can use the "FindControl()" method of the "Master"...
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" %>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.