devpro
June 22nd, 2001, 12:39 PM
Hi,
I wrote the message "Grid.DataKeys problem". Well, forget that problem, I discovered something new. In the Update event I have this code:
string sValue1="";
string sValue2="";
TextBox Text1 = (TextBox)e.Item.FindControl("Text1");
TextBox Text2 = (TextBox)e.Item.FindControl("Text2");
sValue1=Text1 .Text;
sValue2=Text2 .Text;
If I run the code, I got an error at line sValue1=Text1 .Text; saying "Unable to dereference a null pointer". But if I debug and put a breakpoint on that line, I can see that the textbox is found and the value is read!! So why I get the exception. I managed to "fix" the problem in this way:
string sValue1="";
string sValue2="";
TextBox Text1 = (TextBox)e.Item.FindControl("Text1");
TextBox Text2 = (TextBox)e.Item.FindControl("Text2");
if (Text1 !=null) sValue1=Text1 .Text;
if (Text2 !=null) sValue2=Text2 .Text;
Of course the are always found, so I can't see why I got the error if I don't test if they are null!! Any solution or explanation? I don't like the way I fixed it...
And an other point: the value I get from the Text property is the old one, the value before editing: why I don't get the current TextBox's value? Are these problems related?
Please help...
Thank you
- devpro
I wrote the message "Grid.DataKeys problem". Well, forget that problem, I discovered something new. In the Update event I have this code:
string sValue1="";
string sValue2="";
TextBox Text1 = (TextBox)e.Item.FindControl("Text1");
TextBox Text2 = (TextBox)e.Item.FindControl("Text2");
sValue1=Text1 .Text;
sValue2=Text2 .Text;
If I run the code, I got an error at line sValue1=Text1 .Text; saying "Unable to dereference a null pointer". But if I debug and put a breakpoint on that line, I can see that the textbox is found and the value is read!! So why I get the exception. I managed to "fix" the problem in this way:
string sValue1="";
string sValue2="";
TextBox Text1 = (TextBox)e.Item.FindControl("Text1");
TextBox Text2 = (TextBox)e.Item.FindControl("Text2");
if (Text1 !=null) sValue1=Text1 .Text;
if (Text2 !=null) sValue2=Text2 .Text;
Of course the are always found, so I can't see why I got the error if I don't test if they are null!! Any solution or explanation? I don't like the way I fixed it...
And an other point: the value I get from the Text property is the old one, the value before editing: why I don't get the current TextBox's value? Are these problems related?
Please help...
Thank you
- devpro