Click here to Skip to main content
15,909,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i pass a textbox text of first.aspx page to second.aspx page?
Posted

C#
// on first page
response.redirect("second.aspx?string="textbox1.text);

//and on second page

 string value= request.querystring["string"].tostring();
 
Share this answer
 
Comments
Member 8214635 7-Sep-11 5:58am    
i got this error - "Object reference not set to an instance of an object."
Member 11615396 6-May-15 9:56am    
how can pass two textbox text
Might be helpful,

ASP.NET State Management Overview[^]

:)
 
Share this answer
 
There are many ways to pass information between pages.
1) Use session variables
2) Use QueryString
3) Use objects

For detailed description on implementing these ways, go Here[^]
 
Share this answer
 
Comments
RaviRanjanKr 7-Sep-11 5:57am    
Nice Answer, My 5+
nagendrathecoder 7-Sep-11 5:59am    
Thanks Ravi
There are many ways. Select which suits you.
http://msdn.microsoft.com/en-us/library/6c3yckfw.aspx[^]

C#
if (PreviousPage != null)
{
    TextBox SourceTextBox =
        (TextBox) PreviousPage.FindControl("TextBox1");
    if (SourceTextBox != null)
    {
        Label1.Text = SourceTextBox.Text;
    }
}

Use PreviousPage as shown, or QueryString.
 
Share this answer
 
v2
Comments
nagendrathecoder 7-Sep-11 5:57am    
Best answer among all given, my 5. :)
Prerak Patel 7-Sep-11 5:58am    
Thanks.
You can use querystring or Session or Context object if you are using server.transfer. Refer the below link

Transferring page values to another page[^]
 
Share this answer
 
v2
Comments
RaviRanjanKr 7-Sep-11 5:57am    
Always Convert URL to hyperlink. it gives better readability to user.
The basic way is:

C#
Response.Redirect( "second.aspx?query=" + textbox.Text );


Other ones would be:
1:
C#
Session[ "query" ] = textbox.Text;
//Page load of second.aspx
String query = ( Session[ "query" ] != null ) ? Session[ "query" ].ToString() : String.Empty /*or do something else*/;
 
Share this answer
 
1. Use querystring

C#
// on first page
response.redirect("secondpage.aspx?tempValue="textbox1.text);


C#
//and on second page
string value= request.querystring["tempValue"].tostring();


2. use Session

C#
// on first page set Session
Session[ "tempValue" ] = textbox1.Text;


C#
//on second page get value from Session
  String query = ( Session[ "tempValue" ] != null ) ? Session[ "tempValue" ].ToString() : String.Empty 



3. use previos page concept

C#
// on first page set textbox value
TextBox1.text="something";
//on second page 
if (PreviousPage != null)
{
    TextBox tmpTextBox =
        (TextBox) PreviousPage.FindControl("TextBox1");
    if (tmpTextBox != null)
    {
        string value = tmpTextBox.Text.tostring();
    }
}


Edit: Code has been formatted.
 
Share this answer
 
v2
 
Share this answer
 
Hi,

You could use the
Response.Redirect from your first ASPX and fulled out the value
using Request.QueryString


From your first aspx code behind code example:
string qryStr = "The Value of text in First ASPX";
Response.Redirect("EditItem.aspx?emp=" + qryStr);


then in your second aspx code behind in Page_Load:
string qryStr = Request.QueryString["emp"];


You may use Session if you want.

Regards,

Algem
 
Share this answer
 
you can use session or query stirng

query string example:

write code in button click event in .aspx page 1

C#
string value=textbox1.text;
Response.Redirect("Page2.aspx?item="+value);



write code in Page2. aspx Page_Load Event

C#
string value=Request.QueryString["item"].ToString();
Respose.Write(value);


try your self. best of luck

Mahabub
 
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