开发者

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 in

    WPwp1.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 in Session and get them in the Page_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.

  1. In your source page ("WPwp1.aspx") create properties for each control i.e. DropDownList2,DropDownList3,TextBox1,TextBox2,TextBox3.

  2. Give "PostBackUrl" property of the linkbutton to the page you want to redirect, in your case it will be "FLcourt.aspx".

  3. 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 to PreviousPage results in the instantiation of the object and the processing of its life-cycle up to, but not including PreRender.

Sometimes, though, it is simpler to avoid cross-page postbacks and simulate the multiple pages/stages with Panel or MultiView controls.


  1. Use sessions
  2. Use cookies
  3. Use Applications (global)
  4. Post Back URL
  5. Query String
  6. Server.Transfer
  7. 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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜