The code listed below only works on the line, "string id = ((TextBox)DetailsView1.FindControl("TextBoxAttid")).Text;" regardless of the order I place the lines of code.
When I step through code and get to the other lines of code, I get the error message
"Object is not set to an instance of the object". The only object I think this error is referring to is the detailsview object. However that is not the error.
Thus can you tell me what object the code wants a new instance of?
if (DetailsView1.CurrentMode == DetailsViewMode.ReadOnly)
{
string id = ((TextBox)DetailsView1.FindControl("TextBoxAttid")).Text;
}
else if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
{
string name1 = ((TextBox)DetailsView1.FindControl("TextBoxAttid")).Text;
string name3 = ((TextBox)DetailsView1.FindControl("Invalid_Form")).Text;
string name2 = ((TextBox)DetailsView1.FindControl("Prior_Cutoff_Date")).Text;
}
Loading
NarayanPosted Nov 21, 2011, 10:10 PM
if (DetailsView1.CurrentMode == DetailsViewMode.ReadOnly)
{
TextBox txtAttid=(TextBox)DetailsView1.FindControl("TextBoxAttid");
string id = txtAttid!=null? txtAttid.Text : "";
}
Similarly you can do it for others , try to put a breakpoint and debug you will see one of the values is null, thats why you are getting that error.