Dynamically created controls problem

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top