S
Scott Zabolotzky
I'm trying to pass a custom object back and forth between forms.
This custom object is pulled into the app using an external reference
to an assembly DLL that was given to me by a co-worker. A query-string
flag is used to indicate to the page whether it should instantiate
a new instance of the object or access an existing instance from
the calling page.
On the both pages I have a property of the page which is an
instance of this custom object. I also have a public get accessor
in the page. When a button is clicked I use Server.Transfer to
jump to the other page.
When each page is loaded I look for a query-string to determine
if this page was loaded by the user directly (query-string not
found) or if it was the result of a transfer from the other page
(query-string found). I create an instance of the sending page using
the Context.Handler and assign a local variable of my custom
object type using the get accessor of the sending page.
Unfortunately this isn't working. When I try to access the
custom object I just get "Undefined Value". I can transfer string data
from one form to the next just fine but the custom object does not
work.
Any ideas? Here's my code.
public class WebForm1: System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button send;
protected MyNamespace.MyObject obj;
protected string test;
public MyNamespace.MyObject Object
{
get
{
return obj;
}
}
public string Test
{
get
{
return test;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
{
string sTransfer = Request.QueryString["transfer"];
if (sTransfer == "true")
{
//We were transferred here from WebForm2
//Extract WebForm2's object
WebForm2 wf2;
wf2 = (WebForm2)Context.Handler;
obj = wf2.Object;
//extract WebForm2's string
test = wf2.Test;
}
else
{
//this is the initial page load,
//not a transfer from WebForm2
obj = new MyNamespace.MyObject("data");
//Assign test string a value
test = "test assigned by WebForm1";
}
}
}
private void send_Click(object sender, System.EventArgs e)
{
Server.Transfer ("WebForm2.aspx?transfer=true");
}
}
public class WebForm2: System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button send;
protected MyNamespace.MyObject obj;
protected string test;
public MyNamespace.MyObject Object
{
get
{
return obj;
}
}
public string Test
{
get
{
return test;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
{
string sTransfer = Request.QueryString["transfer"];
if (sTransfer == "true")
{
//We were transferred here from WebForm1
//Extract WebForm1's object
WebForm1 wf1;
wf1 = (WebForm1)Context.Handler;
obj = wf1.Object;
//extract WebForm2's string
test = wf1.Test;
}
else
{
//this is the initial page load,
//not a transfer from WebForm1
obj = new MyNamespace.MyObject("data");
//Assign test string a value
test = "test assigned by WebForm2";
}
}
}
private void send_Click(object sender, System.EventArgs e)
{
Server.Transfer ("WebForm1.aspx?transfer=true");
}
}
This custom object is pulled into the app using an external reference
to an assembly DLL that was given to me by a co-worker. A query-string
flag is used to indicate to the page whether it should instantiate
a new instance of the object or access an existing instance from
the calling page.
On the both pages I have a property of the page which is an
instance of this custom object. I also have a public get accessor
in the page. When a button is clicked I use Server.Transfer to
jump to the other page.
When each page is loaded I look for a query-string to determine
if this page was loaded by the user directly (query-string not
found) or if it was the result of a transfer from the other page
(query-string found). I create an instance of the sending page using
the Context.Handler and assign a local variable of my custom
object type using the get accessor of the sending page.
Unfortunately this isn't working. When I try to access the
custom object I just get "Undefined Value". I can transfer string data
from one form to the next just fine but the custom object does not
work.
Any ideas? Here's my code.
public class WebForm1: System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button send;
protected MyNamespace.MyObject obj;
protected string test;
public MyNamespace.MyObject Object
{
get
{
return obj;
}
}
public string Test
{
get
{
return test;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
{
string sTransfer = Request.QueryString["transfer"];
if (sTransfer == "true")
{
//We were transferred here from WebForm2
//Extract WebForm2's object
WebForm2 wf2;
wf2 = (WebForm2)Context.Handler;
obj = wf2.Object;
//extract WebForm2's string
test = wf2.Test;
}
else
{
//this is the initial page load,
//not a transfer from WebForm2
obj = new MyNamespace.MyObject("data");
//Assign test string a value
test = "test assigned by WebForm1";
}
}
}
private void send_Click(object sender, System.EventArgs e)
{
Server.Transfer ("WebForm2.aspx?transfer=true");
}
}
public class WebForm2: System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button send;
protected MyNamespace.MyObject obj;
protected string test;
public MyNamespace.MyObject Object
{
get
{
return obj;
}
}
public string Test
{
get
{
return test;
}
}
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
{
string sTransfer = Request.QueryString["transfer"];
if (sTransfer == "true")
{
//We were transferred here from WebForm1
//Extract WebForm1's object
WebForm1 wf1;
wf1 = (WebForm1)Context.Handler;
obj = wf1.Object;
//extract WebForm2's string
test = wf1.Test;
}
else
{
//this is the initial page load,
//not a transfer from WebForm1
obj = new MyNamespace.MyObject("data");
//Assign test string a value
test = "test assigned by WebForm2";
}
}
}
private void send_Click(object sender, System.EventArgs e)
{
Server.Transfer ("WebForm1.aspx?transfer=true");
}
}