Cross Page Posting!

If you want to pass for example a textbox value from one webform to another, we usually do that using either the query string or the Session variable. ASP.NET 2.0 introduced Cross Page Posting which allow us to retrieve the value of the textbox in the second webform.

Now let's jump to the code.

For this purpose, Create two pages (Page1.aspx, and Page2.aspx)

Page1.aspx will have two controls
 1- A textbox (TextBox1).
 2- A Button (Button1)
 
Set the PostBackUrl property of the Button1 to Page2.aspx.

Now in Page2.aspx page_load event, Write the below code

 TextBox txtFirstPage = (TextBox)(PreviousPage.FindControl("TextBox1"));
 Response.Write(String.Format("You wrote {0} in Page1",txtFirstPage.Text));

When Page2.aspx is loaded, you will see that you were able to retrieve the value you entered on Page1.

Hope this helps,

Published 20 November 2007 09:57 AM by haissam

Comments

No Comments

This site

Search

Go

This Blog

Syndication

Sponsors

  • MaximumASP
  • Breaking News
  • Find a Job
  • Social Bookmarking
    Tidebuy Reviews
    Online Shopping
    asp.net hosting
    UK online local dating