I am using Master Page. Which has table in the form and table row:
And in the content page Page1.aspx which uses this Master Page has a text box between:
I want to access this text box value that is there in Page1.aspx in another page Page2.aspx.
Can anyone help me how to achieve this?
I have tried all most all ways that I have found in google search, but nothing working for me as I am always getting the error:
*******************************************
Object reference not set to an instance of an object.
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.
*******************************************
Thanks,
Moksha.
Nilanka DharmadasaPosted Dec 23, 2009, 5:55 AM
If my previous answer helped you, please tick 'Do you like this answer' check box near that answer.
The reason for your issue is one of those methods return a null value and you try to execute a method on that.
Try to run the coode given below instead of the code you gave. it will tell you what happens exactly.
if (Page.PreviousPage == null)
{
MessageBox.Show("Cannot access PreviousPage");
}
if ((Page.PreviousPage.FindControl("ContentPlaceHolder1")) == null)
{
MessageBox.Show("cannot find ContentPlaceHolder1");
}
else if (((ContentPlaceHolder)Page.PreviousPage.FindControl("ContentPlaceHolder1")).FindControl("TxtUserName") == null)
{
MessageBox.Show("cannot find TxtUserName");
}
else
{
TextBox1.Text = ((TextBox)((ContentPlaceHolder)Page.PreviousPage.FindControl("ContentPlaceHolder1")).FindControl("TxtUserName")).Text;
}
MokshasriPosted Dec 23, 2009, 4:37 AM
If you have any hint on why TextBox1.Text = ((TextBox)((ContentPlaceHolder)Page.PreviousPage.FindControl("ContentPlaceHolder1")).FindControl("TxtUserName")).Text; or any other method of FindControl did not work and it is throwing System.NullReferenceException: Object reference not set to an instance of an object. exception, please share.
At present, I am using the solution of session variables.
Thanks once again.
Regards,
Moksha.
Nilanka DharmadasaPosted Dec 22, 2009, 6:52 AM
Did you try to set the value to a session variable in Page1.aspx and access the session from Page2.aspx?