Problem in Grid_Update

boss700

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