Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Master page property is found but no longer set

Reply
Thread Tools

Master page property is found but no longer set

 
 
Neil Chambers
Guest
Posts: n/a
 
      07-07-2008
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

 
Reply With Quote
 
 
 
 
Mark Fitzpatrick
Guest
Posts: n/a
 
      07-07-2008
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
Neil Chambers
Guest
Posts: n/a
 
      07-07-2008
Thank you Mark & Mark!

: n)

"Neil Chambers" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Access Master Page Controls from page.aspx doesn't inherit from master SerpentKiss2010 ASP .Net 0 04-06-2011 02:46 PM
Setting the value of a Master page's control's property using a property of the Master page Nathan Sokalski ASP .Net 25 03-04-2010 03:42 AM
How To: Set Label Text Property In Master Page (From Subscribing Page)? Joey ASP .Net 2 05-23-2007 04:46 PM
Can a master page be built from another master page Zeba ASP .Net 1 02-22-2007 10:55 AM
seeking servlet "Master" keep getting "Master/servlet/Master" not found. Tomcat 5.0.25 Doug McCann Java 1 08-05-2004 09:16 PM



Advertisments