Click here to Skip to main content
13,086,120 members (85,012 online)
Rate this:
Please Sign up or sign in to vote.
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 28-Apr-13 20:08pm
Updated 29-Apr-13 1:51am
Mohi Uddin Sumon 29-Apr-13 2:31am
Can't I get a proper answer??

1 solution

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

Solution 1

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 29 Apr 2013
Copyright © CodeProject, 1999-2017
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