473,406 Members | 2,369 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,406 software developers and data experts.

Master page property is found but no longer set

I have a public property defined in my master page

public partial class MainMaster : System.Web.UI.MasterPage
{
string UserName;

public string userName
{
get
{
return UserName;
}
set
{
UserName = value;
}
}

protected void Page_Load(object sender, EventArgs e)
{
userName = "MyUser";
}
}

I have set up the MasterType directive on a child page and can locate the
userName property using intellisense - but when the child page loads the
property is no longer set;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = Master.userName; // this does not appear
TextBox1.Text += "\nhowdy"; //this does appear
}
}

What am I doing wrong?

Cheers,
n

Jul 7 '08 #1
4 1258
"Neil Chambers" <no****@nospam.comwrote in message
news:uz**************@TK2MSFTNGP03.phx.gbl...
>I have a public property defined in my master page

public partial class MainMaster : System.Web.UI.MasterPage
{
string UserName;

public string userName
{
get
{
return UserName;
}
set
{
UserName = value;
}
}

protected void Page_Load(object sender, EventArgs e)
{
userName = "MyUser";
}
}

I have set up the MasterType directive on a child page and can locate the
userName property using intellisense - but when the child page loads the
property is no longer set;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = Master.userName; // this does not appear
TextBox1.Text += "\nhowdy"; //this does appear
}
}

What am I doing wrong?

Cheers,
n


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 7 '08 #2
"Neil Chambers" <no****@nospam.comwrote in message
news:uz**************@TK2MSFTNGP03.phx.gbl...
What am I doing wrong?
Populating the property too late in the Page load cycle - the Page_Load
event of a content page fires before the Page_Load event of its MasterPage:
http://forums.asp.net/p/1247678/2297924.aspx

Try moving the MasterPage code from Page_Load to Page_Init...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jul 7 '08 #3
Have you tried setting the property value in the masterpage earlier? The
problem here is, which occurs first, the Page_Load in the Master, or in the
inherited Page. It may end up surprising you. Try doing it during the OnInit
event of the Master. When you set the data, set it to the UserName local
variable and not the property as every property activity has a small bit of
overhead and it's best to avoid it whenever possible.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression

"Neil Chambers" <no****@nospam.comwrote in message
news:uz**************@TK2MSFTNGP03.phx.gbl...
I have a public property defined in my master page

public partial class MainMaster : System.Web.UI.MasterPage
{
string UserName;

public string userName
{
get
{
return UserName;
}
set
{
UserName = value;
}
}

protected void Page_Load(object sender, EventArgs e)
{
userName = "MyUser";
}
}

I have set up the MasterType directive on a child page and can locate the
userName property using intellisense - but when the child page loads the
property is no longer set;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = Master.userName; // this does not appear
TextBox1.Text += "\nhowdy"; //this does appear
}
}

What am I doing wrong?

Cheers,
n
Jul 7 '08 #4
Thank you Mark & Mark!

: n)

"Neil Chambers" <no****@nospam.comwrote in message
news:uz**************@TK2MSFTNGP03.phx.gbl...
>I have a public property defined in my master page

public partial class MainMaster : System.Web.UI.MasterPage
{
string UserName;

public string userName
{
get
{
return UserName;
}
set
{
UserName = value;
}
}

protected void Page_Load(object sender, EventArgs e)
{
userName = "MyUser";
}
}

I have set up the MasterType directive on a child page and can locate the
userName property using intellisense - but when the child page loads the
property is no longer set;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = Master.userName; // this does not appear
TextBox1.Text += "\nhowdy"; //this does appear
}
}

What am I doing wrong?

Cheers,
n
Jul 7 '08 #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...
4
by: Bob | last post by:
In ASP.NET 1.1, I have a base page for all my pages in an application. The base page contains some common properties that every page needs, the code behind file of every page looks like this: ...
1
by: Rob R. Ainscough | last post by:
I'm running into a problem with Master Pages. I have some "absolute" controls (labels, textboxes) that I position on the page using: ControlObject.Style.Add("Top", "250") or ...
4
by: Boris Yeltsin | last post by:
OK, on my Master Page I have a control: <a id="hypTabAccount" href="#" runat="server">Account</a> Now, in the code-behind (Root.master.vb) I can refer to it simply thus: ...
0
by: Matt | last post by:
I am trying to access a property that I have created inside a Master Page. However all instruction that I have found shows them accessing the property from a .aspx page not a .aspx.vb page. My...
7
by: TheLongshot | last post by:
I just recently converted a few pages of my application to using master pages. Problem is, in all of my content pages, the contents are centered. I can't figure out why. The markup in the...
6
by: Just Me | last post by:
When using master pages, how can I get an external style sheet applied to the specific page and still see the effects at design time. I want to have a generic style sheet and specific ones for each...
0
by: John Kotuby | last post by:
Hi all, Has anyone experienced any problems after applying the SP1 service pack to Visual Studio 2005? I am running into a problem that I can't otherwise explain. My project contains a 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.