Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Accessing master page properties from server.transfer page?

Reply
Thread Tools

Accessing master page properties from server.transfer page?

 
 
evantay
Guest
Posts: n/a
 
      05-26-2007
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; }
set { m_AlreadyTested = value; }
}

Then within the Page_Load of the master page I am doing this:

if certainConditions == true then
AlreadyTested = true;
Server.Transfer("/error.aspx");
end if

Then in error.aspx child page (derrived from the master page) I do this from
its Page_Load event:
Response.Write(Master.AlreadyTested.toString());

However the AlreadyTested always displays as FALSE, even though itis hard
coded to True. When I step through in the debugger I can see it is set to
True just prior to the Server.Transfer. But once it gets into the transfered
page everything is nulled out and bools are set to False.

Similarly I have other properties I've set to valid object instances prior
to the .Transfer and afterward those are all Null too.

What is going on here? I thought under ASP.NET 2.0 I could tap into the
master page properties even from exceution of the .Transfer pages?

Thanks!



 
Reply With Quote
 
 
 
 
Mark Fitzpatrick
Guest
Posts: n/a
 
      05-26-2007
Sure you can access MasterPage properties, but what are you expecting to
happen when you move to another page? First, what's going on here is you've
just moved from one page to another with the server.transfer. This means
that absolutely everything that was available before isn't because it's a
completely new page. Your MasterPage isn't static, which could be where your
confusion lies. If it was static than these properties would be acecssible
globally, btu that's not the way things work. Each page that inherits from
your masterpage is completely seperate and instanced. You will only gain
access to the properties of the current instance of a masterpage. So, your
property AlreadyTested will work within that particular page instance. Once
you use Server.Transfer you're essentially doing a server-side redirect to
another page, a new instance which includes a new set of variables and a
blank slate. The variables cannot be maintained since this is a completely
seperate page even though it inherits from a masterpage.

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"evantay" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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; }
> set { m_AlreadyTested = value; }
> }
>
> Then within the Page_Load of the master page I am doing this:
>
> if certainConditions == true then
> AlreadyTested = true;
> Server.Transfer("/error.aspx");
> end if
>
> Then in error.aspx child page (derrived from the master page) I do this
> from
> its Page_Load event:
> Response.Write(Master.AlreadyTested.toString());
>
> However the AlreadyTested always displays as FALSE, even though itis hard
> coded to True. When I step through in the debugger I can see it is set to
> True just prior to the Server.Transfer. But once it gets into the
> transfered
> page everything is nulled out and bools are set to False.
>
> Similarly I have other properties I've set to valid object instances prior
> to the .Transfer and afterward those are all Null too.
>
> What is going on here? I thought under ASP.NET 2.0 I could tap into the
> master page properties even from exceution of the .Transfer pages?
>
> Thanks!
>
>
>



 
Reply With Quote
 
 
 
 
evantay
Guest
Posts: n/a
 
      05-29-2007
Thanks Mark. This makes perfect sense. Perhaps server.transfer then is not
the ideal way to go about what I want...

What I am really looking for is a way that I can "include" a page
dynamically within the master page framework.

For example let's say I have my master page mymaster.master. Inside
mymaster.master I check logic that if it evaluates to True I want the user
to get noservice.aspx instead of the real web page. Currently I can just
make my master page so that it does a server.transfer to noservice.aspx if
those conditions are met, and therefore every web page that derrives (child
pages) from the master automatically enforce this logic. So far all is
good.

However once control is passed to noservice.aspx I want to be able to be
able to access some objects that were created in the master page without
having to recreate them. Its almost like what I want to do is to tell .NET
to merge (i.e. in-line) noservice.aspx directly into the page its processing
if my logic evaluates to true, rather than having it to a service.transfer.

One thing I am doing currently that seems to work ok is that I am able to
store some objects I want to persist across the page request into the
Context of the request. When I access this from the server.transfer page
all is still in tact.

Do any work around or alternatives come to mind?

Thanks!!

"Mark Fitzpatrick" <(E-Mail Removed)> wrote in message
news:O%(E-Mail Removed)...
> Sure you can access MasterPage properties, but what are you expecting to
> happen when you move to another page? First, what's going on here is
> you've just moved from one page to another with the server.transfer. This
> means that absolutely everything that was available before isn't because
> it's a completely new page. Your MasterPage isn't static, which could be
> where your confusion lies. If it was static than these properties would be
> acecssible globally, btu that's not the way things work. Each page that
> inherits from your masterpage is completely seperate and instanced. You
> will only gain access to the properties of the current instance of a
> masterpage. So, your property AlreadyTested will work within that
> particular page instance. Once you use Server.Transfer you're essentially
> doing a server-side redirect to another page, a new instance which
> includes a new set of variables and a blank slate. The variables cannot be
> maintained since this is a completely seperate page even though it
> inherits from a masterpage.
>
> --
> Hope this helps,
> Mark Fitzpatrick
> Former Microsoft FrontPage MVP 199?-2006
>
> "evantay" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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; }
>> set { m_AlreadyTested = value; }
>> }
>>
>> Then within the Page_Load of the master page I am doing this:
>>
>> if certainConditions == true then
>> AlreadyTested = true;
>> Server.Transfer("/error.aspx");
>> end if
>>
>> Then in error.aspx child page (derrived from the master page) I do this
>> from
>> its Page_Load event:
>> Response.Write(Master.AlreadyTested.toString());
>>
>> However the AlreadyTested always displays as FALSE, even though itis hard
>> coded to True. When I step through in the debugger I can see it is set
>> to
>> True just prior to the Server.Transfer. But once it gets into the
>> transfered
>> page everything is nulled out and bools are set to False.
>>
>> Similarly I have other properties I've set to valid object instances
>> prior
>> to the .Transfer and afterward those are all Null too.
>>
>> What is going on here? I thought under ASP.NET 2.0 I could tap into the
>> master page properties even from exceution of the .Transfer pages?
>>
>> Thanks!
>>
>>
>>

>
>



 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      05-30-2007
Hi evantay,

You may find following articles useful:

#Passing Server Control Values Between Pages
http://msdn2.microsoft.com/en-us/lib...fw(vs.71).aspx

#ASP.Net 2.0 - Master Pages: Tips, Tricks, and Traps
http://www.odetocode.com/Articles/450.aspx


Regards,
Walter Wang ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      05-30-2007
Hi evantay,

You may find following articles useful:

#Passing Server Control Values Between Pages
http://msdn2.microsoft.com/en-us/lib...fw(vs.71).aspx

#ASP.Net 2.0 - Master Pages: Tips, Tricks, and Traps
http://www.odetocode.com/Articles/450.aspx


Regards,
Walter Wang ((E-Mail Removed), remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
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
Can a master page be built from another master page Zeba ASP .Net 1 02-22-2007 10:55 AM
Accessing Master Page Custom Properties in Design Mode =?Utf-8?B?U3VyZXNo?= ASP .Net 4 10-21-2006 05:37 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