Sometimes we want to get value of any control of First page to another page. Here is an Article To do the same without using Session or Querysting.
If we are using some data which we dont want to show in addressbar (URL) at that time we are facing problem using Querystring, sometimes we are encrypting the URL and descrypting at another (next) page so anyone don't get exact meaning of passed querystring values, but here is best way to come out from those problems.
And using Session having some another problem because sessions are always stored at Server side. So server memory occupies.
Now here is good idea to overcome from above both the problems.
Using the code
In your application add 2 webpages.
First page ID = Page1.aspx
and Second Page ID = Page2.aspx
Now in Page1.aspx add below controls with defined properties.
TextBox : ID = txtFirstPage
Button : ID = btnSend
On button btnSend's Click event write below code :
protected void btnSend_Click(object sender, EventArgs e)
Now on the Page2.aspx write below code in Page Load Event.
protected void Page_Load(object sender, EventArgs e)
if(Page.PreviousPage != null)
TextBox txt =(TextBox) Page.PreviousPage.FindControl("txtFirstPage");
if(txt != null)
Response.Write("<font color='Blue' size='15'> <b>" + txt.Text + "</b></font>");
Now Set Page1.aspx as startup page, run your application.
Enter any text in TextBox and then Submit the button.
Here it will Transfer Page1.aspx to Page2.aspx and on Page you will see your entered text of TextBox with Blue color !!
You can access any control of Page1.aspx to Page2.aspx.
Enjoy the coding.
Points of Interest
Always use Server.Transfer , if you are trying to use Response.Redirect then Page.PreviousPage will null always.
Keep coding and get the best code to achieve your goal.
Try Try and Try. There are always lots of way to do.