Datagrid on WebPart: After postback Data is disappearing

D

Dan

I am having a problem with losing data from my datagrid after it posts back.

The page runs the populate data sub at the end of CreateChildControls and
fills my DataGrid. After I postback by clicking the cmdUpdate button, I
would expect oTable.Items.Count to have the same # it was before I did the
postback, but instead its zero.

Thanks for any help...

Below is some of the sample code:


Protected WithEvents oTable As New System.Web.UI.WebControls.DataGrid
Protected WithEvents cmdUpdate As New System.Web.UI.WebControls.LinkButton

Protected Overrides Sub CreateChildControls()
oTable.EnableViewState = True
Me.Controls.Add(oTable)
Me.Controls.Add(cmdUpdate)
End Sub

Private Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdUpdate.Click
sDebug = oTable.Items.Count
End Sub

Protected Overrides Sub RenderWebPart(ByVal output As
System.Web.UI.HtmlTextWriter)
Me.EnsureChildControls()
PopulateData()
......
End Sub
 
M

Mark Nelson

Dan,

I suspect that the event cmdUpdate_Click is not getting fired. Please check
whether you have defined the event hanlder in the CreateChildControls method
(where the defniton for the control lives)
Have you enabled postback for this control ?

Could you please post me the code for CreateChildControls, i can have a look
at that/
The problem is definitely with the events not getting fired inside your
custom control.
 
D

Dan

Mark, thanks for the reply, but I know that the event is definately being
fired as I am outputting the sDebug on the RenderControl:

here is more of the code:


Protected WithEvents oTable As New System.Web.UI.WebControls.DataGrid
Protected WithEvents lblPageXofY As New System.Web.UI.WebControls.Label
Protected WithEvents lblCurPage As New System.Web.UI.WebControls.TextBox
Protected WithEvents lblFilter As New System.Web.UI.WebControls.TextBox
Protected WithEvents lblLastProvider As New
System.Web.UI.WebControls.TextBox
Protected WithEvents cmdUpdate As New System.Web.UI.WebControls.LinkButton
Protected WithEvents lblPrev As New System.Web.UI.WebControls.LinkButton
Protected WithEvents lblNext As New System.Web.UI.WebControls.LinkButton
Protected WithEvents dlAlpha As New System.Web.UI.WebControls.DataList


Dim sDebug As String = ""

Protected Overrides Sub RenderWebPart(ByVal output As
System.Web.UI.HtmlTextWriter)
Try
cmdUpdate.RenderControl(output)
output.Write("<BR>")
oTable.RenderControl(output)
If sDebug.Length > 0 Then
output.Write("<BR><span style='color:blue'>" & sDebug &
"</SPAN><BR>")
End If
End Sub

Protected Overrides Sub CreateChildControls()
Try
sDebug = sDebug & "CreateChildControls<BR>"
AlphaList()
lblPrev.Text = "Previous"
lblNext.Text = "Next"
lblPageXofY.Text = "Page X of Y"
lblPrev.Font.Bold = True
lblNext.Font.Bold = True
dlAlpha.RepeatDirection = RepeatDirection.Horizontal
dlAlpha.RepeatLayout = RepeatLayout.Flow
cmdUpdate.Text = "Update"
oTable.AutoGenerateColumns = False
Me.Controls.Add(dlAlpha)
Me.Controls.Add(lblPrev)
Me.Controls.Add(lblNext)
Me.Controls.Add(lblPageXofY)
Me.Controls.Add(oTable)
Me.Controls.Add(lblCurPage)
Me.Controls.Add(lblFilter)
Me.Controls.Add(lblLastProvider)
Me.Controls.Add(cmdUpdate)
Catch ex As Exception
sError = sError & "Child Control:" & ex.Message & "<BR>"
End Try
End Sub

Private Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdUpdate.Click
Try
sDebug = sDebug & "UpdateClick<BR>"
sDebug = sDebug & "# items:" & oTable.Items.Count & "<BR>"
Catch ex As Exception

End Try
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top