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

Problem passing custom object between forms

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");
}
}

Nov 17 '05 #1
6 3230
Scott,

It's much easier just to pass your object in a Session variable.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
From: Scott Zabolotzky <za******@ripco.com>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Problem passing custom object between forms
Date: Thu, 23 Oct 2003 16:07:03 +0000 (UTC)
Organization: Ripco Communications Inc.
Lines: 142
Message-ID: <bn**********@e250.ripco.com>
NNTP-Posting-Host: shell2.ripco.com
X-Trace: e250.ripco.com 1066925223 4061 209.100.225.144 (23 Oct 2003 16:07:03 GMT)X-Complaints-To: us****@ripco.com
NNTP-Posting-Date: Thu, 23 Oct 2003 16:07:03 +0000 (UTC)
User-Agent: nn/6.6.5
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
e.de!newsfeed.icl.net!newsfeed.fjserv.net!newshost ing.com!news-xfer1.atl.new
shosting.com!diablo.voicenet.com!tdsnet-transit!newspeer.tds.net!gail.ripco.
com!zabolotsXref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:186088
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

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");
}
}


Nov 17 '05 #2
ja******@online.microsoft.com (Jim Cheshire [MSFT]) writes:
Scott, It's much easier just to pass your object in a Session variable. Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com This post is provided as-is with no warranties and confers no rights.

Jim,

Thanks for the suggestion. However I have a few ?'s:

1) I thought that passing data in a Session variable was to be
avoided due to memory constraints on the server. Is this not true?

2) Is there anything obvious from my code that is preventing my
custom object from being passed between forms using the Context.Handler
method? It works just fine for passing the string back and forth.

Thanks...Scott
Nov 17 '05 #3
Scott Zabolotzky <za******@ripco.com> writes:
ja******@online.microsoft.com (Jim Cheshire [MSFT]) writes:
Scott, It's much easier just to pass your object in a Session variable. Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com This post is provided as-is with no warranties and confers no rights.


Jim, Thanks for the suggestion. However I have a few ?'s: 1) I thought that passing data in a Session variable was to be
avoided due to memory constraints on the server. Is this not true? 2) Is there anything obvious from my code that is preventing my
custom object from being passed between forms using the Context.Handler
method? It works just fine for passing the string back and forth.

I tried using a session variable and I'm still getting
"undefined value"

Here's what I added:

In WebForm1 send_ButtonClicked:

Session["data"] = (object)obj;

In WebForm2 Page_Load

obj = (MyNamespace.MyObject)Session["data"]

Does the MyNamespace.MyObject type need to derive off of System.Object
for these methods of transferring data between forms to work? Could
that be why I'm getting "undefined value" errors?

Scott

Nov 17 '05 #4
Scott,

Anyone that tells you that you shouldn't store objects in Session variables
is just plain wrong. Remember, in .NET, EVERYTHING is an object.
Therefore, if you are to say "don't store objects in a Session variable",
you are saying "don't use Session variables."

With that as a qualifier, it is true that you should evaluate using
Sessions to store objects based upon the size of the object.

As far as using your method of accessing the object via the Context, that
should work fine. I tried to reproduce your problem, and I am not able to.
It works fine for me. If you want me to test your project, please zip up
ALL project files and e-mail it to me at the e-mail address in my sig line,
but leave off the ONLINE part.

Thanks.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
From: Scott Zabolotzky <za******@ripco.com>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Re: Problem passing custom object between forms
Date: Thu, 23 Oct 2003 18:53:56 +0000 (UTC)
Organization: Ripco Communications Inc.
Lines: 28
Message-ID: <bn**********@e250.ripco.com>
References: <bn**********@e250.ripco.com> <DD**************@cpmsftngxa06.phx.gbl>NNTP-Posting-Host: shell2.ripco.com
X-Trace: e250.ripco.com 1066935236 23329 209.100.225.144 (23 Oct 2003 18:53:56 GMT)X-Complaints-To: us****@ripco.com
NNTP-Posting-Date: Thu, 23 Oct 2003 18:53:56 +0000 (UTC)
User-Agent: nn/6.6.5
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
e.de!diablo.theplanet.net!zen.net.uk!cox.net!news-xfer.cox.net!gail.ripco.co
m!zabolotsXref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:186125
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

ja******@online.microsoft.com (Jim Cheshire [MSFT]) writes:
Scott,

It's much easier just to pass your object in a Session variable.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

Jim,

Thanks for the suggestion. However I have a few ?'s:

1) I thought that passing data in a Session variable was to be
avoided due to memory constraints on the server. Is this not true?

2) Is there anything obvious from my code that is preventing my
custom object from being passed between forms using the Context.Handler
method? It works just fine for passing the string back and forth.

Thanks...Scott


Nov 17 '05 #5
Anyone who tells you not to store objects in session variables has done a
little more coding than a simple Hello World in VB.Net. Sessions break down
too easily to store objects in them (try opening two browser windows after
you create the session and alternate requests between those windows). The
exception is read only objects, such as user preferences.

Jerry

"Jim Cheshire [MSFT]" <ja******@online.microsoft.com> wrote in message
news:sR**************@cpmsftngxa06.phx.gbl...
Scott,

Anyone that tells you that you shouldn't store objects in Session variables is just plain wrong. Remember, in .NET, EVERYTHING is an object.
Therefore, if you are to say "don't store objects in a Session variable",
you are saying "don't use Session variables."

With that as a qualifier, it is true that you should evaluate using
Sessions to store objects based upon the size of the object.

As far as using your method of accessing the object via the Context, that
should work fine. I tried to reproduce your problem, and I am not able to. It works fine for me. If you want me to test your project, please zip up
ALL project files and e-mail it to me at the e-mail address in my sig line, but leave off the ONLINE part.

Thanks.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
From: Scott Zabolotzky <za******@ripco.com>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Re: Problem passing custom object between forms
Date: Thu, 23 Oct 2003 18:53:56 +0000 (UTC)
Organization: Ripco Communications Inc.
Lines: 28
Message-ID: <bn**********@e250.ripco.com>
References: <bn**********@e250.ripco.com> <DD**************@cpmsftngxa06.phx.gbl>
NNTP-Posting-Host: shell2.ripco.com
X-Trace: e250.ripco.com 1066935236 23329 209.100.225.144 (23 Oct 2003

18:53:56 GMT)
X-Complaints-To: us****@ripco.com
NNTP-Posting-Date: Thu, 23 Oct 2003 18:53:56 +0000 (UTC)
User-Agent: nn/6.6.5
Path:

cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin e.de!diablo.theplanet.net!zen.net.uk!cox.net!news-xfer.cox.net!gail.ripco.co m!zabolots
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:186125X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

ja******@online.microsoft.com (Jim Cheshire [MSFT]) writes:
Scott,

It's much easier just to pass your object in a Session variable.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

Jim,

Thanks for the suggestion. However I have a few ?'s:

1) I thought that passing data in a Session variable was to be
avoided due to memory constraints on the server. Is this not true?

2) Is there anything obvious from my code that is preventing my
custom object from being passed between forms using the Context.Handler
method? It works just fine for passing the string back and forth.

Thanks...Scott

Nov 17 '05 #6
Jerry,

In .NET development, everything is an object. If you store a String in a
session variable, you are storing an object in a Session. Therefore, to
say "you should not store objects in Session variables" is wrong on its
face. The .NET Framework was designed to store objects in Session state.
In fact, the developers explicitly designed it with the ability to pass
simple objects and their properties in Session variables.

When you are writing code, nothing is absolute. If you have certain
architectures that make using Session variables problematic, it is your
responsibilty as the developer to identify those and make the necessary
accommodations.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "Jerry III" <je******@hotmail.com>
References: <bn**********@e250.ripco.com> <DD**************@cpmsftngxa06.phx.gbl> <bn**********@e250.ripco.com>
<sR**************@cpmsftngxa06.phx.gbl>Subject: Re: Problem passing custom object between forms
Date: Thu, 23 Oct 2003 21:49:24 -0700
Lines: 96
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <eP**************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: h-68-164-57-117.lsanca54.dynamic.covad.net 68.164.57.117
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:186243
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Anyone who tells you not to store objects in session variables has done a
little more coding than a simple Hello World in VB.Net. Sessions break down
too easily to store objects in them (try opening two browser windows after
you create the session and alternate requests between those windows). The
exception is read only objects, such as user preferences.

Jerry

"Jim Cheshire [MSFT]" <ja******@online.microsoft.com> wrote in message
news:sR**************@cpmsftngxa06.phx.gbl...
Scott,

Anyone that tells you that you shouldn't store objects in Session

variables
is just plain wrong. Remember, in .NET, EVERYTHING is an object.
Therefore, if you are to say "don't store objects in a Session variable",
you are saying "don't use Session variables."

With that as a qualifier, it is true that you should evaluate using
Sessions to store objects based upon the size of the object.

As far as using your method of accessing the object via the Context, that
should work fine. I tried to reproduce your problem, and I am not able

to.
It works fine for me. If you want me to test your project, please zip up
ALL project files and e-mail it to me at the e-mail address in my sig

line,
but leave off the ONLINE part.

Thanks.

Jim Cheshire [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
>From: Scott Zabolotzky <za******@ripco.com>
>Newsgroups: microsoft.public.dotnet.framework.aspnet
>Subject: Re: Problem passing custom object between forms
>Date: Thu, 23 Oct 2003 18:53:56 +0000 (UTC)
>Organization: Ripco Communications Inc.
>Lines: 28
>Message-ID: <bn**********@e250.ripco.com>
>References: <bn**********@e250.ripco.com>

<DD**************@cpmsftngxa06.phx.gbl>
>NNTP-Posting-Host: shell2.ripco.com
>X-Trace: e250.ripco.com 1066935236 23329 209.100.225.144 (23 Oct 2003

18:53:56 GMT)
>X-Complaints-To: us****@ripco.com
>NNTP-Posting-Date: Thu, 23 Oct 2003 18:53:56 +0000 (UTC)
>User-Agent: nn/6.6.5
>Path:

cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfee d00.sul.t-online.de!t-onli

n

e.de!diablo.theplanet.net!zen.net.uk!cox.net!ne ws-xfer.cox.net!gail.ripco.c

o
m!zabolots
>Xref: cpmsftngxa06.phx.gbl

microsoft.public.dotnet.framework.aspnet:186125 >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
>
>ja******@online.microsoft.com (Jim Cheshire [MSFT]) writes:
>
>>Scott,
>
>>It's much easier just to pass your object in a Session variable.
>
>>Jim Cheshire [MSFT]
>>Developer Support
>>ASP.NET
>>ja******@online.microsoft.com
>
>>This post is provided as-is with no warranties and confers no rights.
>
>
>Jim,
>
>Thanks for the suggestion. However I have a few ?'s:
>
>1) I thought that passing data in a Session variable was to be
>avoided due to memory constraints on the server. Is this not true?
>
>2) Is there anything obvious from my code that is preventing my
>custom object from being passed between forms using the Context.Handler
>method? It works just fine for passing the string back and forth.
>
>Thanks...Scott
>
>
>



Nov 17 '05 #7

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

Similar topics

11
by: milkyway | last post by:
Hello, I have an HTML page that I am trying to import 2 .js file (I created) into. These files are: row_functions.js and data_check_functions.js. Whenever I bring the contents of the files into...
3
by: James Spibey | last post by:
Hi, I have an MDI application which has aboout 10 child windows. The way the app needs to work is that only one window should be visible at a time and it should be maximized within the parent...
4
by: waltborders | last post by:
Hi, Because the blind are unable to use a mouse, keyboard navigation is key. A major difficulty is that not all windows forms controls are keyboard 'tab-able' or 'arrow-able' or have "tab...
3
by: Kris van der Mast | last post by:
Hi, I've created a little site for my sports club. In the root folder there are pages that are viewable by every anonymous user but at a certain subfolder my administration pages should be...
0
by: Chris Ericoli | last post by:
Hi, I am working with an 'in session' ado dataset with an asp.net application. My dataset is comprised of two tables, one of which maintains a few calculated datacolumns. For some reason these...
4
by: marek.rocki | last post by:
First of all, please don't flame me immediately. I did browse archives and didn't see any solution to my problem. Assume I want to add a method to an object at runtime. Yes, to an object, not a...
0
by: mjsterz | last post by:
I've been working with VB .NET for less than a year and this is the first time I've posted on one of these groups, so let me apologize beforehand if I'm being unclear, not posting my issue...
7
by: AMP | last post by:
Hello, I have this in form1: namespace Pass { public partial class Form1 : Form { public Form2 form2; public Form1() {
2
by: Carl Heller | last post by:
Working in VS2003, .Net 1.1 I'm working on a project where I compare data between two databases. This is a lengthy process, and very data intensive, so I decided to create a class, and thread...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.