473,223 Members | 1,685 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,223 software developers and data experts.

Accessing master page properties from server.transfer page?

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!

May 26 '07 #1
4 3971
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!

May 26 '07 #2
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!


May 29 '07 #3
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 (wa****@online.microsoft.com, 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.

May 30 '07 #4
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 (wa****@online.microsoft.com, 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.

May 30 '07 #5

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

Similar topics

3
by: yma | last post by:
Hi, I put a .aspx page inside Server.Transfer() within a button. The page was created for testing so it only has button and I did not add code. When I click the button, it gave me an error...
4
by: Bob H | last post by:
Hi, I'm aware of the different ways to pass variables between ASP.Net pages. For pages that need to pass a variable, we're using the server.transfer method. For others, we're using...
2
by: dee | last post by:
Hi I'm posting back to a second page using Server.Transfer(). There are buttons on this second page that use Respose.Redirect() since some of the pages are html's and the Transfer function cant...
4
by: Stan | last post by:
This code has been working for a long time: try { Server.Transfer ("Order.aspx"); } catch (Exception ex) { /// }
3
by: Adrian Parker | last post by:
Anyone come across anything like this before.. If I do a server transfer to a new page, at the top of the page, the contents of the <TITLE> in the <HEAD> section is displayed above the contents...
3
by: Jeff | last post by:
Hi! I was wondering if it is possible to access page properties in the page's @Page directive. For example, if I had a property: Public Property MyProperty ... Can I set it using...
2
by: archana | last post by:
Hi all, I am new to asp.net. I am trying to use server.transfer and respnse.redirect. When i nagivate to page using server.transfer on navigated page if i click on refresh i am getting...
0
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....
3
by: Waazzzii | last post by:
Here's an interesting one... received the {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.} exception when attempting a...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.