Faizal
Faizal

Reputation: 1833

Response.Redirect, Access source page data from target page

I have two ASP.NET Web Pages (Page1.aspx and Page2.aspx), Page1.aspx contains few TextBox controls and a Button Control.

On Click Event of Button Control i redirect user to Page2.aspx using Response.Redirect method.

How do i access source page data (TextBox values in Page1.aspx) from target page (Page2.aspx).

I don't want to use Cross-Page Postback or Server.Transfer method

Thank You.

Upvotes: 1

Views: 1035

Answers (2)

Kamal
Kamal

Reputation: 2522

Try using session variables

in page 1

Session["field1"] = textbox1.Text;

in page 2

string page1text = Session["field1"];

Upvotes: 1

David
David

Reputation: 218847

You'll need to persist that data somewhere. The way Response.Redirect works is by telling the client (the web browser) to make a new request for the specified resource. This essentially means that the old resource is abandoned. Think of each request made by the client as unique and stand-alone.

An easy way to persist the values is to store them in Session state on Page1 just before calling Response.Redirect. Then, in Page2 you can retrieve those values from Session state.

Something like:

Page1

//...
Session["SomeValue"] = TextBox1.Text;
Session["SomeOtherValue"] = DropDownList1.SelectedIndex;
//...
Response.Redirect("Page2.aspx");

Page2

//...
// Note: The following can have some additional type checking and input/value checking added
var someValue = Session["SomeValue"];
var someOtherValue = Session["SomeOtherValue"];
//...

Upvotes: 2

Related Questions