A
Adrian Parker
v1.1 and v2.0
We have a problem with viewstate not being stored.
What's happening is that we create controls in CreateChildControls and add them to a container on the page (whether it be a panel or
a table etc). We only set the data values for the controls if not page.ispostback. But, if either of the textboxes change,
the page posts back and the changed event fires twice.
Protected Overrides Sub CreateChildControls()
Dim txtbox1 As New TextBox
txtbox1.ID = "txt1"
AddHandler txtbox1.TextChanged, AddressOf Text_Changed
txtbox1.AutoPostBack = True
If Not Page.IsPostBack Then txtbox1.Text = "text box 1"
Panel1.Controls.Add(txtbox1)
Dim txtbox2 As New TextBox
txtbox2.ID = "txt2"
AddHandler txtbox2.TextChanged, AddressOf Text_Changed
txtbox2.AutoPostBack = True
If Not Page.IsPostBack Then txtbox2.Text = "text box 2"
Panel2.Controls.Add(txtbox2)
End Sub
Private Sub Text_Changed(ByVal sender As System.Object, ByVal e As System.EventArgs)
Response.Write("text changed: " + sender.ID + "<br>")
End Sub
If instead of creating controls dynaically, I create them by dragging them onto the form then it works fine.
How do I force the page to store the created controls' viewstate ?
We have a problem with viewstate not being stored.
What's happening is that we create controls in CreateChildControls and add them to a container on the page (whether it be a panel or
a table etc). We only set the data values for the controls if not page.ispostback. But, if either of the textboxes change,
the page posts back and the changed event fires twice.
Protected Overrides Sub CreateChildControls()
Dim txtbox1 As New TextBox
txtbox1.ID = "txt1"
AddHandler txtbox1.TextChanged, AddressOf Text_Changed
txtbox1.AutoPostBack = True
If Not Page.IsPostBack Then txtbox1.Text = "text box 1"
Panel1.Controls.Add(txtbox1)
Dim txtbox2 As New TextBox
txtbox2.ID = "txt2"
AddHandler txtbox2.TextChanged, AddressOf Text_Changed
txtbox2.AutoPostBack = True
If Not Page.IsPostBack Then txtbox2.Text = "text box 2"
Panel2.Controls.Add(txtbox2)
End Sub
Private Sub Text_Changed(ByVal sender As System.Object, ByVal e As System.EventArgs)
Response.Write("text changed: " + sender.ID + "<br>")
End Sub
If instead of creating controls dynaically, I create them by dragging them onto the form then it works fine.
How do I force the page to store the created controls' viewstate ?