Click here to Skip to main content
15,913,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys!

In my first page, I have 2 text boxes and a button. the first one is for username and the other one for the id. What I want to do is that, the text box value will be get from the first page and it will be display inside the text box on the next page after the user clicks the button. How to do that?
Posted

There are three ways:
1) Query string: values after a '?' as part of the page URL.
http://www.codeproject.com/Questions/811654/How-to-get-the-text-box-value-form-one-page-to-ano?arn=4
arn is the variable name, 4 is the value.
http://msdn.microsoft.com/en-us/library/system.web.httprequest.querystring(v=vs.110).aspx[^]
2) Cookies: stored on the client, they can be recovered by the server and used in the new page load event.
http://msdn.microsoft.com/en-us/library/aa287547(v=vs.71).aspx[^]
http://msdn.microsoft.com/en-us/library/aa287533(v=vs.71).aspx[^]
3) Session: stored on the server.
http://msdn.microsoft.com/en-us/library/system.web.httpcontext.session(v=vs.110).aspx[^]
 
Share this answer
 
Comments
DarkDreamer08 26-Aug-14 4:47am    
I am wrong at my explanation above. What I mean is that the user will input their username at first inside the text box in the first page. the the User will select the RESET ID which is a link to the next page. Now, the text box on the second page will display the username of the user. How to do that? I tried to use the session, but I got an error saying,"Object reference not set to an instance of an object"
OriginalGriff 26-Aug-14 5:08am    
How did you try to use the Session?
What code, and where?
DarkDreamer08 26-Aug-14 20:18pm    
on my first page, I included a session on the page load. Here is my code in that part:
//My connection to the database
if (cnt == 1)
{
if (userName == uname.Text && pass == password.Text)
{
if (u_type == "admin")
{
Session["uname"] = uname.Text;
Response.Redirect("admin.aspx");
}
else
{
Session["uname"] = uname.Text;
Response.Redirect("CS.aspx");
}
}
else if (userName == uname.Text && pass != password.Text)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Invalid password');", true);
password.Text = "";
}

and in my second page, I just put this line at the page load event:
username.Text = Session["uname"].ToString();

Please correct me if I did something wrong. Thank you!
Googling "passing data between pages asp.net"

You can try microsoft's approach (First link): http://msdn.microsoft.com/en-us/library/vstudio/6c3yckfw(v=vs.100).aspx[^]

Other approaches (3rd Link): http://www.itorian.com/2012/07/5-ways-to-send-data-between-aspnet-pages.html[^]

I would recommend you to read following links too:
What have you tried?[^]
How to ask a question?[^]

They will help you improve your questions and hence get better answers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900