Pass values from the asp.net controls in one webpage to asp.net controls in another webpage
I have a webpage 'WPwp1.aspx' and another webpage 'FLcourt.aspx'
In WPwp1.aspx
i have DropDownList2,DropDownList3,TextBox1,TextBox2,TextBox3 and a LinkButton1
- On click of a link button i want to
redirect to
FLcourt.aspx
. FLcourt.aspx
also has the controls that are there inWPwp1.aspx
(DropDownList2,DropDownList3,Text开发者_Go百科Box1,TextBox2,TextBox3)
When user input value in the controls present in WPwp1.aspx
and clicks on LinkButton1, the user should be able to see all the values that were being given as input in 'WPwp1.aspx' into the asp.net controls in 'FLcourt.aspx'.
How is it possible to pass values being input in some controls in a webpage to similar controls in another webpage?
Yes, you have several options:
- Use Session variables. This is the less scalable way. Just before
Response.Redirect
, store your values inSession
and get them in thePage_Load
of the target page. Using
QueryString
. Pass the values in a query string:Response.Redirect( string.Format("FLcourt.aspx?value1={0}&value2={1}", HttpUtility.UrlEncode(value1), HttpUtility.UrlEncode(value2)));
And in the second page:
var value1 = Request.QueryString["value1"];
UPDATE
Using cookies (the client's browser must have them enabled). Set cookies before Redirect:
Response.Cookies["MyValues"]["Value1"] = value1;
In the target page:
if(Request.Cookies["MyValues"] != null) { var value1 = Request.Cookies["MyValues"]["Value1"]; //... }
(but you have to check that Request.Cookies["MyValues"]
is not null before)
You can try this out.
In your source page ("WPwp1.aspx") create properties for each control i.e. DropDownList2,DropDownList3,TextBox1,TextBox2,TextBox3.
Give "PostBackUrl" property of the linkbutton to the page you want to redirect, in your case it will be "FLcourt.aspx".
In the destination page ("FLcourt.aspx") access the previous page with the help of "PreviousPage" class. This class will give you the properties which you have written in point1.
Hope this helps!
Regards,
Samar
See: http://msdn.microsoft.com/en-us/library/6c3yckfw.aspx
To summarize and answer your question directly, you can:
- Use a query string.
- Get HTTP POST information from the source page.
And since both pages appear to be in the same Web Application, you can also:
- Use session state.
- Create public properties in the source page and access the property values in the target page.
- Get control information in the target page from controls in the source page using the
PreviousPage
object. This option has a particular performance disadvantage as a call toPreviousPage
results in the instantiation of the object and the processing of its life-cycle up to, but not includingPreRender
.
Sometimes, though, it is simpler to avoid cross-page postbacks and simulate the multiple pages/stages with Panel
or MultiView
controls.
- Use sessions
- Use cookies
- Use Applications (global)
- Post Back URL
- Query String
- Server.Transfer
- Static Variables (global)
http://www.herongyang.com/VBScript/IIS-ASP-Object-Example-Pass-Value-between-Pages.html
its shown how you do it between two pages.
精彩评论