Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Datagrid on WebPart: After postback Data is disappearing

Reply
Thread Tools

Datagrid on WebPart: After postback Data is disappearing

 
 
Dan
Guest
Posts: n/a
 
      02-21-2007
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

 
Reply With Quote
 
 
 
 
Mark Nelson
Guest
Posts: n/a
 
      02-22-2007
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.
--
Thanks & Regards,
Mark Nelson


"Dan" wrote:

> 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
>

 
Reply With Quote
 
 
 
 
Dan
Guest
Posts: n/a
 
      02-22-2007
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

"Mark Nelson" wrote:

> 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.
> --
> Thanks & Regards,
> Mark Nelson
>
>
> "Dan" wrote:
>
> > 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
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data disappearing on postback in GridView with Dynamic columns =?Utf-8?B?dmFuZGls?= ASP .Net 2 01-25-2007 08:20 AM
Custom Datagrid disappearing on Postback GJH ASP .Net Building Controls 5 12-04-2006 09:57 PM
Custom Datagrid disappearing on Postback GJH ASP .Net Web Controls 0 12-04-2006 04:38 PM
DataGrid contains no data after postback of edit button click... Andrew Connell ASP .Net 1 11-10-2003 07:56 AM
DataGrid contains no data after postback of edit button click... Andrew Connell ASP .Net Datagrid Control 0 11-06-2003 10:14 PM



Advertisments