This is probably a simple solution, but i can't figure it out......
I dynamically create a control on the page, but it disappears when a button on the page is clicked. Here's an example of what i have:
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'If Me.IsPostBack = True Then Exit Sub End Sub Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOne.Click Dim chkSample As New CheckBox With chkSample .Text = "I was added in the code" .ID = "chkSample" .EnableViewState = True End With pnlSample.Controls.Clear() pnlSample.Controls.Add(chkSample) pnlSample.EnableViewState = True lblTalk.Text = "button ONE was clicked" End Sub Private Sub btnTwo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTwo.Click lblTalk.Text = "button TWO was clicked" End Sub
I thought that the controls and their state were supposed to remain, but they don't. Run the page and click the first button - the code runs and creates the checkbox. Then click the second button - the checkbox vanishes.
What am i doing wrong?![]()




Reply With Quote