开发者

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.


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"];
//...


Try using session variables

in page 1

Session["field1"] = textbox1.Text;

in page 2

string page1text = Session["field1"];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜