Datagrid inline editing problem: textbox does not hold new value

I had a problem with DataGrid inline editing last Friday: I click the “Update” LinkButton in the DataGrid, but the DataGrid still shows the old value. After stepping into the source code, I found that the TextBox in the DataGrid under the editing mode still holds the old value, and the value that I typed in seems to be lost somehow. Well, I thought it might be the ViewState issue, so I checked the ViewState of the DataGrid, but it is enabled. Actually the ViewState of all server controls on that page has been enabled. So it is not the ViewState issue, then what causes the loss of TextBox’s value? Finally, after hours of debugging and head scratching, I found out what caused the problem. It is actually a foolish mistake: the Page_Load function should be like this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

‘Put user code to initialize the page here
If Not IsPostBack() Then
Me.BindSoftwareVendorDG()
End If

End Sub

But what I have is this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

‘Put user code to initialize the page here
Me.BindSoftwareVendorDG()

End Sub

So I forgot to check if it is a postback, so the page re-binds the DataGrid and overwrites the value of the TextBox before executing the Update Event Handler, that is why the TextBox loses the entered value upon postbacks.

Leave a Reply

avatar
  Subscribe  
Notify of