A
Alain DIART
I try to create a class derivating System.Web.UI.Page which would add
dynamicaly created controls just before any html code in the body. I'm using
beta 2 for this project.
My code works partially :
- I can create the controls
but
- the automatic post back on some control (dropdownlist) doesn't work, even
with setting AutoPostBack property to true.
- If I add to my code ddl1.Attributes.Add("onChange",
"this.form.submit();"), I get something that looks like an AutoPostBack,
but, I don't go trough the server side event handler code
- Then I have no persistency on values entered by the user in the
dynamically components...
Please, help !
Here's my code :
Public Class MyPage
Inherits System.Web.UI.Page
Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Init
' If Not Page.IsPostBack Then
If Request("mode") = "edit" Then
InsertDynamicZone()
End If
' End If
End Sub
Protected Sub InsertDynamicZone()
' no problem here, I got what I want
Dim div1 As New HtmlGenericControl("div")
div1.ID = "dynamicZone"
Dim uwc As aWebControl
uwc = New aWebControl()
div1.Controls.Add(uwc)
Me.Form.Controls.AddAt(0, div1)
End Sub
End Class
Public Class aWebControl
Inherits System.Web.UI.WebControls.WebControl
Protected ddl1 As DropDownList
Protected Overrides Sub CreateChildControls()
ddl1 = New DropDownList
ddl1.ID = "ddlDisplayMode"
ddl1.AutoPostBack = True
' ddl1.Attributes.Add("onChange", "this.form.submit();")
AddHandler ddl1.SelectedIndexChanged, AddressOf
dlDisplayMode_SelectedIndexChanged
End Sub
Protected Sub WP_PreRender(ByVal sender As Object, ByVal e As EventArgs)
Handles MyBase.PreRender
' here comes the databinding of ddl1 - works perfectly
End Sub
Protected Sub ddlDisplayMode_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
' here comes some code - I never go trough this code.
End Sub
End Class
dynamicaly created controls just before any html code in the body. I'm using
beta 2 for this project.
My code works partially :
- I can create the controls
but
- the automatic post back on some control (dropdownlist) doesn't work, even
with setting AutoPostBack property to true.
- If I add to my code ddl1.Attributes.Add("onChange",
"this.form.submit();"), I get something that looks like an AutoPostBack,
but, I don't go trough the server side event handler code
- Then I have no persistency on values entered by the user in the
dynamically components...
Please, help !
Here's my code :
Public Class MyPage
Inherits System.Web.UI.Page
Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Init
' If Not Page.IsPostBack Then
If Request("mode") = "edit" Then
InsertDynamicZone()
End If
' End If
End Sub
Protected Sub InsertDynamicZone()
' no problem here, I got what I want
Dim div1 As New HtmlGenericControl("div")
div1.ID = "dynamicZone"
Dim uwc As aWebControl
uwc = New aWebControl()
div1.Controls.Add(uwc)
Me.Form.Controls.AddAt(0, div1)
End Sub
End Class
Public Class aWebControl
Inherits System.Web.UI.WebControls.WebControl
Protected ddl1 As DropDownList
Protected Overrides Sub CreateChildControls()
ddl1 = New DropDownList
ddl1.ID = "ddlDisplayMode"
ddl1.AutoPostBack = True
' ddl1.Attributes.Add("onChange", "this.form.submit();")
AddHandler ddl1.SelectedIndexChanged, AddressOf
dlDisplayMode_SelectedIndexChanged
End Sub
Protected Sub WP_PreRender(ByVal sender As Object, ByVal e As EventArgs)
Handles MyBase.PreRender
' here comes the databinding of ddl1 - works perfectly
End Sub
Protected Sub ddlDisplayMode_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs)
' here comes some code - I never go trough this code.
End Sub
End Class