Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
First Page as follows

User Name textbox1
Password textbox2

Second Page as follows

User textbox3


i want user enters the User Name in textbox1 (in First Page) that value to be shown in textbox3 (in Second Page).

for that how can i do in asp.net using c#.

Regards,
narasiman )
Posted

 
Share this answer
 
Comments
thatraja 24-Feb-14 2:30am    
5!
Tom Marvolo Riddle 24-Feb-14 2:36am    
Thank you
You can use Asp.Net Session to do this. Check out the following code snippet:

In the code behind of the first page, add this code to your button click event:

C#
protected void Button1_Click(object sender, EventArgs e)
        {
            Session["UserName"] = textbox1.Text;
        }


In the code behind of the second page add this code:

C#
protected void Page_Load(object sender, EventArgs e)
        {
            textbox3.Text = Session["UserName"] as String;
        }


Hope it helps :)
 
Share this answer
 
Comments
Member 12506675 9-May-16 2:52am    
by applying this code i dint get the solution.. please help me...
Nitij 9-May-16 3:20am    
Download the code from this link and see how its done.

https://drive.google.com/open?id=0BwAdilPqy-wDaHVXNG9nV3RNYVU
Member 12506675 9-May-16 6:38am    
thank eu :)
Hi,

If you are redirecting from first page to second page you can use QuesryString to maintain the state.

Response.
Redirect("SecondPage.aspx?UserName="+txtUserName.text);


Get values in second page as below

textbox3.Text = Request.QueryString["UserName"];


OR

If you want to maintain or access the username more than one page use session state as below

Session["UserName"] = txtUsername.Text;


Get session value

textbox3.Text = Session["UserName"].toString();
 
Share this answer
 
To get textbox1 text from page1 to page2 assuming for example that textbox1 holds the username:

In Page1.aspx.cs:
C#
Response.Redirect("Page2.aspx?username=" + txtbox1.Text); 


In Page2.aspx.cs:
C#
string uName = Request.QueryString["username"]; 


Then you can use the new string "uName" in Page2.aspx.
 
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