I am trying to achieve what is described here under Getting Public Property Values from the Source Page.
After reading these SO questions:
How to Persist Variable on Postback
How to pass values across the pages in ASP.net without using Session
I have come to the conclusion that it seems to be impossible to do this (retrieve a public property from the PreviousPage
variable).
Here is my attempt:
In source page code-behind (SourcePage.aspx.cs):
public MyClass PublicProperty { get; set; }
In target source code (TargetPage.aspx):
<%@ PreviousPageType VirtualPath="~/SourcePage.aspx" %>
In target page code-behind:
TextBox1.Text = PreviousPage.PublicProperty.PoNumber;
From an event handler in SourcePage.aspx.cs
, I am calling (tried with and without 2nd parameter):
Server.Transfer("~/TargetPage.aspx", true);
But of course, before the page is actually transferred to, Page_Load
is called in SourcePage.aspx.cs
, and so PublicProperty
is reset, and once the server reaches TargetPage.aspx.cs
, PreviousPage.PublicProperty
is equal to null
.
My question is, is there any way at all of getting this to work? If not, why is this suggested as a method on MSDN
? Does this work with other versions of ASP, or am I just doing something wrong?
Many thanks for your time and any advice you can give