Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my code,


Public Class tempformmanager
Inherits System.Web.UI.Page


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim btn1 As New System.Web.UI.WebControls.Button
btn1.Text = "this is button"
PlaceHolder1.Controls.Add(btn1)


End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
PlaceHolder1.Visible = True

Dim radio1 As New System.Web.UI.WebControls.RadioButton
radio1.Text = " radio button"
PlaceHolder2.Controls.Add(radio1)
End Sub

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
Dim chkbox1 As New System.Web.UI.WebControls.CheckBox
chkbox1.Text = " checkbox "
PlaceHolder3.Controls.Add(chkbox1)
End Sub

Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
Dim txtbox1 As New System.Web.UI.WebControls.TextBox
PlaceHolder4.Controls.Add(txtbox1)
End Sub

Protected Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button5.Click
Dim lbl1 As New System.Web.UI.WebControls.Label
lbl1.Text = "this is label"
PlaceHolder5.Controls.Add(lbl1)
End Sub

Private Sub tempformmanager_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
PlaceHolder1.Visible = True

End Sub
End Class
Posted

1 solution

This is because whenever you create dynamic control, they are lost on the post back...you have to recreate them on preinit event.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900