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" <ma******@fitzme.comwrote in message
news:O%****************@TK2MSFTNGP03.phx.gbl...
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" <ev*****@nospam.nospamwrote in message
news:Ob**************@TK2MSFTNGP05.phx.gbl...
>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!