solution to PostBack? [modified]
-
There was an error message System.NullReferenceException was unhandled by user code Message="Object reference not set to an instance of an object.". Here is my code. Is there anything wrong? I have already set the PostBackUrl button from the previous page.
if (!Page.IsPostBack) { TextBox t = (TextBox)PreviousPage.FindControl("txtStartDate"); lblStartDate.Text = t.Text; }
-- modified at 0:06 Monday 7th August, 2006thanks in advance. Much appreciated.
-
There was an error message System.NullReferenceException was unhandled by user code Message="Object reference not set to an instance of an object.". Here is my code. Is there anything wrong? I have already set the PostBackUrl button from the previous page.
if (!Page.IsPostBack) { TextBox t = (TextBox)PreviousPage.FindControl("txtStartDate"); lblStartDate.Text = t.Text; }
-- modified at 0:06 Monday 7th August, 2006thanks in advance. Much appreciated.
-
There was an error message System.NullReferenceException was unhandled by user code Message="Object reference not set to an instance of an object.". Here is my code. Is there anything wrong? I have already set the PostBackUrl button from the previous page.
if (!Page.IsPostBack) { TextBox t = (TextBox)PreviousPage.FindControl("txtStartDate"); lblStartDate.Text = t.Text; }
-- modified at 0:06 Monday 7th August, 2006thanks in advance. Much appreciated.
hi, i think you are not giving the currect textbox name or textbox is not present check the textbox name. thanks
-
There was an error message System.NullReferenceException was unhandled by user code Message="Object reference not set to an instance of an object.". Here is my code. Is there anything wrong? I have already set the PostBackUrl button from the previous page.
if (!Page.IsPostBack) { TextBox t = (TextBox)PreviousPage.FindControl("txtStartDate"); lblStartDate.Text = t.Text; }
-- modified at 0:06 Monday 7th August, 2006thanks in advance. Much appreciated.
Hi, The problem could be, the reference to the page were the textbox(txtStartDate)is available might not be referred. If the textbox has to be referred from the current page were you want the reference you can do so by. if (!Page.IsPostBack) { TextBox t = (TextBox)this.Page.FindControl("txtStartDate"); lblStartDate.Text = t.Text; } Hope this should work Regards:-O
Mohan
-
I suppose you don't have txtStartDate textbox on your page, thats why this exception is raised. Pilo
i have that textbox obviously. :(
thanks in advance. Much appreciated.
-
hi, i think you are not giving the currect textbox name or textbox is not present check the textbox name. thanks
thanks. i checked many times, but it seems i type correctly, or rather copy paste correctly.:->
thanks in advance. Much appreciated.
-
Hi, The problem could be, the reference to the page were the textbox(txtStartDate)is available might not be referred. If the textbox has to be referred from the current page were you want the reference you can do so by. if (!Page.IsPostBack) { TextBox t = (TextBox)this.Page.FindControl("txtStartDate"); lblStartDate.Text = t.Text; } Hope this should work Regards:-O
Mohan
I tried and I faced same error. I should be clearer with the error. It says:
if (!Page.IsPostBack) { TextBox t = (TextBox)this.Page.FindControl("txtStartDate"); lblStartDate.Text = t.Text; }
lblStartDate.Text = t.Text;
The error stops at this line saying "Object reference not set to an instance of an object." The troubleshooting tips were: Use the "new" keyword to create an object instance. Check to determine if the object is null before calling the method.thanks in advance. Much appreciated.
-
I tried and I faced same error. I should be clearer with the error. It says:
if (!Page.IsPostBack) { TextBox t = (TextBox)this.Page.FindControl("txtStartDate"); lblStartDate.Text = t.Text; }
lblStartDate.Text = t.Text;
The error stops at this line saying "Object reference not set to an instance of an object." The troubleshooting tips were: Use the "new" keyword to create an object instance. Check to determine if the object is null before calling the method.thanks in advance. Much appreciated.
I hope my MS visual is not haunted. X|
thanks in advance. Much appreciated.
-
I hope my MS visual is not haunted. X|
thanks in advance. Much appreciated.
Is that TextBox is inside any other controls like DataGrid,DataList or Panel. The reason for the Problem could be: 1) If the TextBox(txtxStartDate) is not available in the respective page. 2) If the page reference is not set when calling this.Page.FindControl 3) If the TextBox is inside some other controls like DataGrid,DataList or Panel. Please do check and come around.:-O
P. Mohan
-
i have that textbox obviously. :(
thanks in advance. Much appreciated.
In this case, if you really want people to help you to solve this problem, you should copy - paste your code. if you declare this TextBox in aspx file, then paste it here (at least relevant part), if you create it dynamicaly, paste here code where you do so. There is a possibility, that problem is with lblStartDate. Try to debug your application and check each value, you will see if FindControls returns your desired textBox and if lblStartDate is not null. Pilo
-
Is that TextBox is inside any other controls like DataGrid,DataList or Panel. The reason for the Problem could be: 1) If the TextBox(txtxStartDate) is not available in the respective page. 2) If the page reference is not set when calling this.Page.FindControl 3) If the TextBox is inside some other controls like DataGrid,DataList or Panel. Please do check and come around.:-O
P. Mohan
I am using MaterPages + .NET 2.0 Login Control. I observed that if my webform had not used the MasterPages or the webform was not autheticated by the Login Control, the postback will work fine. Is there a diferent code?
thanks in advance. Much appreciated.