Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
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 28-Apr-13 21:08pm
Edited 29-Apr-13 2:51am
vinayakJJ3.4K
v2
Comments
Mohi Uddin Sumon at 29-Apr-13 2:31am
   
Can't I get a proper answer??

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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/[^]
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 29 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100