|
-
Dec 3rd, 2002, 04:04 PM
#1
Thread Starter
C# Aficionado
Persisting RunTime created controls
I am using a DataGrid. In it, I add a cell and then attempt to add an evenhandler.
In any case, whenever anything is clicked on the page, the added cells drop from the datagrid -- EVEN IF I do not do anything with the datagrid.
In the past, usually datagrids don't change unless you change them.
Anyone run in to this? How can I make the DataGrid persist the added cells?
My Code:
Code:
Public Sub QueueDataGrid_Bound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles QueueDataGrid.ItemDataBound
Dim tempVal As String
Dim DItem As Object 'System.Web.UI.WebControls.DataGridItem
Dim intI As Integer
Dim TTCell As New System.Web.UI.WebControls.TableCell()
Static CellsList() As Boolean
If e.Item.ItemType = System.Web.UI.WebControls.ListItemType.Header Then
ReDim CellsList(e.Item.Cells.Count)
For intI = 0 To e.Item.Cells.Count - 1
If Not IsDBNull(e.Item.Cells(0).ToString) Then
If UCase(Left((e.Item.Cells(intI).Text.ToString()), 3)) = "HDN" Then
CellsList(intI) = False
e.Item.Cells(intI).Visible = False
Else
CellsList(intI) = True
e.Item.Cells(intI).Visible = True
End If
End If
' Response.Write(e.Item.DataItem.item(0).ToString())
Next
TTCell.Text = ""
e.Item.Cells.AddAt(e.Item.Cells.Count, TTCell)
End If
If e.Item.ItemType = System.Web.UI.WebControls.ListItemType.Item Or e.Item.ItemType = System.Web.UI.WebControls.ListItemType.AlternatingItem Or e.Item.ItemType = System.Web.UI.WebControls.ListItemType.Footer Then
For intI = 0 To e.Item.Cells.Count - 1
e.Item.Cells(intI).Visible = CellsList(intI)
Next
Dim ViewCell As New System.Web.UI.HtmlControls.HtmlButton()
If Not IsDBNull(e.Item.Cells(0).ToString()) Then
ViewCell.InnerText = "View"
ViewCell.Attributes.Add("onClick", "javascript:window.open('default.aspx?vwRec=" & e.Item.Cells(0).Text.ToString() & "');void[];")
ViewCell.Attributes.Add("Class", "QueueButton")
TTCell.Controls.Add(ViewCell)
TTCell.Controls.Add(New LiteralControl("|"))
Dim TakeCell As New System.Web.UI.WebControls.Button()
TakeCell.Text = "Take"
'TakeCell.Attributes.Add("Class", "QueueButton")
TakeCell.ID = e.Item.Cells(0).Text.ToString()
AddHandler TakeCell.Click, AddressOf TakeCellClick
e.Item.Cells.AddAt(e.Item.Cells.Count, TTCell)
e.Item.Cells(e.Item.Cells.Count - 1).Controls.Add(TakeCell)
End If
End If
End Sub
Public Sub TakeCellClick(ByVal sender As Object, ByVal e As System.EventArgs) 'ByVal e As ImageClickEventArgs) Handles bn.Click
LoginApp.Visible = True
Response.Write("I was clicked")
End Sub
I never get "I was clicked" outputted to the page and the extra table cell column drops from the table
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Dec 4th, 2002, 09:44 PM
#2
Lively Member
you need to check for postback in page_load function
-
Dec 4th, 2002, 10:30 PM
#3
You can also try declaring the runtime variables in a module instead of the page. I don't know for sure about eventhandlers but with delegates you have to reset them at every postback.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|