Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing values from Page 1 to Page2

Status
Not open for further replies.

sheykc

Programmer
Sep 28, 2001
79
US
I've been searching the forums here and everywhere I can possibly locate, to figure out how to pass 2 values on webform1 to webform2. Once I have the data on webform2, I will be calling an XML object to retrieve more data.

I don't want the information viewable (querystring), because it contains a controlID that would compromise security.

On webform1, I have code like this:

Session("Product") = "Bankruptcy";

On webform2, I have this code:

lblProductType.Text = Session.("Product");

When I recompile the project, I get an error in the task list:

c:\inetpub\ 'System.Web.UI.Page.Session' denotes a 'property' where a 'method' was expected

What am I doing wrong?
 
Oops--ignore the period. I was trying to use intellisense right before I pasted the code into the forum. But, I was getting the error before the period appeared.

By the way, I get the same error on both the webform1 page and the webform2 page.

If there is another way I should be doing this, I'd appreciate suggestions.

I have also tried Context.Item and got errors with that.
Webform1:
Context.Items.Add("Product", "Bankruptcy");
Server.Transfer("brdetail.aspx");

Webform2: lblCaseValue.Text=Context.Items["Product"].ToString();

Error:
System.NullReferenceException: Object reference not set to an instance of an object.


Then I had tried creating a Get property in the webform1 class, and trying to retrieve it via the context.handler.
Webform1:
public string strProduct
{
get
{
return "Bankruptcy";
}
}
Webform2:
//create instance of source web form
dolan_main wf1;
//get reference to current handler instance
wf1=(dolan_main)Context.Handler;
lblCaseValue.Text = wf1.strProduct;

Error:
System.InvalidCastException: Specified cast is not valid.
 
See this.


The example passes single values. I changed it so that Page 1 creates an object containing ALL the data that I needed to pass just before the Server.Transfer in Page 1, created a Property on page 1 that returns the object and called that Property from Page 2 after the Server Transfer.

I am using VB though, not C#.



Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Thanks, but that's where I started at yesterday :) (That's how I learned to use the Get Property and Context.Handler).

Good article and I thought it would have my answer.

It just seems like I'm getting errors noone else gets. Maybe I have something setup incorrectly in a config file.
 
I thought I'd add this about my problem. I am displaying a datagrid on page1. When the user clicks on a hyperlink column, they need to be redirected to page2. Since my values are being updated in the dgSummary_SelectedIndexChanged method, I'm assuming they are never getting updated. It appears that the hyperlink redirects before this code is ever executed.
 
Right, but that is not techically a redirect. A Redirect comes from the Server to the browser. You are taking a direct link, that is, a GET Request out of your displayed page to another URL. You need a POST to Page 1. So what I gave you, or you discovered yesterday is of no use. If you want Postback then you will have to find a way to POST to page 1 and Server.Transfer to Page 2.

Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
i have encountered the same problem. i have found out that there are several ways of accomplishing this feat.

hopefully one of them will be of use to you...

1.
dim a as string=4291
dim b as string= "Testing"
Dim sJavaScript As String
sJavaScript = &quot;<script language=javascript>&quot;
sJavaScript &= &quot;SiteWindow=open('Page2.aspx?RoomNo= &quot; + a + &quot; &RoomName= &quot; + b + &quot;', 'Rooms','toolbar=no,location=no,menubar=no,resizable=yes,scrollbars=yes');&quot;
sJavaScript &= &quot;</script>&quot;
Response.Write(sJavaScript)

on page2 make sure you have
a request.querystring(&quot;RoomNo&quot;)
and a request.querystring(&quot;RoomName&quot;)

2.
Source Page:

context.Items(&quot;FacilityNo&quot;) = lstFacility.SelectedItem.Value
context.Items(&quot;FacilityName&quot;) = lstFacility.SelectedItem.Text
Server.Transfer(&quot;WhlFacilityList.aspx&quot;, True)

Destination Page:

txtFacilityNo.Text = CType(context.Items(&quot;FacilityNo&quot;), String)
lblName.Text = CType(context.Items(&quot;FacilityName&quot;), String)

in the HTML:
enableViewStateMac=&quot;False&quot;

3.

Hope this helps

Sam
 
If you are using C# then you need to access the session variable using square brackets...

On webform1...
Session(&quot;Product&quot;) = &quot;Bankruptcy&quot;;

On webform2...
lblProductType.Text = Session[&quot;Product&quot;];
 
That didn't post correctly ... on webform 2 &quot;Product&quot; should exist inside square brackets - if that makes sense.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top