Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Building Controls (http://www.velocityreviews.com/forums/f59-asp-net-building-controls.html)
-   -   Problems Adding Dynamic Controls to Custom Web control (http://www.velocityreviews.com/forums/t758961-problems-adding-dynamic-controls-to-custom-web-control.html)

Tipo70 02-27-2008 04:04 PM

Problems Adding Dynamic Controls to Custom Web control
 
I am having problems after adding dynamic controls in a custom web control.
I have no problem adding the controls. However in the example below, when
someone clicks on the button, the data in the previous textbox is gone. Is
there any way I can get this data to persist?

<ToolboxData("<{0}:TestWebControl runat=server></{0}:TestWebControl>")> _
Public Class TestWebControl
Inherits WebControl
Implements INamingContainer
Private btnAdd As New Button

Public Sub New()
AddHandler btnAdd.Click, AddressOf btnSubmit_Click
End Sub

Protected Overrides Sub CreateChildControls()
Controls.Clear()
btnAdd.ID = "btnAdd"
btnAdd.Text = "Add Box"
If numBoxes = 0 Then numBoxes = 1
For i As Integer = 1 To numBoxes
Dim myTextBox As New TextBox()
myTextBox.ID = "myTextBox" & i
myTextBox.Width = 200
Controls.Add(myTextBox)
Controls.Add(New LiteralControl("<br>"))
Next
Controls.Add(New LiteralControl("<br>"))
Controls.Add(btnAdd)
End Sub
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
EventArgs)
numBoxes = numBoxes + 1
Me.ChildControlsCreated = False
End Sub
Public Property numBoxes() As Integer
Get
Me.EnsureChildControls()
Return ViewState("numBoxes")
End Get
Set(ByVal value As Integer)
Me.EnsureChildControls()
ViewState("numBoxes") = value
End Set
End Property
End Class


Thanks in advance



All times are GMT. The time now is 08:35 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.