Click here to Skip to main content
13,197,796 members (43,434 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked
Posted 21 Nov 2007

Get value from one page to another

, 21 Nov 2007
Rate this:
Please Sign up or sign in to vote.
Getting value from one page to another page


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 :

// Any source code blocks look like this
protected void btnSend_Click(object sender, EventArgs e)
// Transfer first page to Second Page
// Always use Server.Transfer. Then and then you will get desire OuptPut

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.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Sun Rays
Team Leader
India India
Working as a Team Lead in MNC located at India.
In IT world, I have worked with Microsoft Technologies and always ready for R&D.
Worked with Website Development and Windows based applications as well.

New errors are really good and being happy to resolve those.....

You may also be interested in...


Comments and Discussions

Questionclarification Pin
sivacool23-Jan-10 23:14
membersivacool23-Jan-10 23:14 
AnswerRe: clarification Pin
Sun Rays27-Jan-10 21:23
memberSun Rays27-Jan-10 21:23 
GeneralBad Article Pin
Ankit Rajpoot28-Jan-09 21:48
memberAnkit Rajpoot28-Jan-09 21:48 
GeneralGreat Artical Pin
~V~28-Dec-07 23:46
member~V~28-Dec-07 23:46 
GeneralArticle Pin
norm .net21-Nov-07 3:08
membernorm .net21-Nov-07 3:08 
GeneralRe: Article Pin
Sun Rays21-Nov-07 18:13
memberSun Rays21-Nov-07 18:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171020.1 | Last Updated 21 Nov 2007
Article Copyright 2007 by Sun Rays
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid