Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There is a textbox (id="TextBox1") in Default.aspx page. I want to get the value of the textbox1 from Default2.aspx page

protected void Button1_Click(object sender, EventArgs e)
{

TextBox tb = (TextBox)PreviousPage.FindControl("TextBox1");
if (tb != null)
{
Label1.Text = tb.Text;
}
}
When I click the button it arises an error :


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 30: //page_load();
Line 31: //Label1.Text = PreviousPage.Name;
Line 32: TextBox tb = (TextBox)PreviousPage.FindControl("TextBox1"); if (tb != null)
Line 33: {
Line 34: Label1.Text = tb.Text;
Posted
Updated 29-Apr-13 1:51am
v2
Comments
Sumon562 29-Apr-13 2:31am    
Can't I get a proper answer??

1 solution

Hi.
Firstly I suggest you to add a tag ASP .NET.
Secondly if you want to exchange data between pages you should consider to fill GET or POST insformation with your request or/and to add session.
The following links might be helpful
http://msdn.microsoft.com/en-us/library/6c3yckfw(v=vs.100).aspx[^]
http://code.msdn.microsoft.com/How-to-Pass-Data-Between-935838e4[^]
http://aspdotnetfaq.com/Faq/How-to-make-Cross-Page-Postback-in-ASP-Net.aspx[^]
http://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/5-ways-to-send-data-between-Asp-Net-pages/[^]
 
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