when I created a checkBoxList dynamically (in VB code) and put it dynamically in PlaceHolder and render every thing is right but when I thought to create an event (SelectedIndexChanged) for this checkBoxList the debager is not recognise the event and display me the folowing error :
Erreur 1 La clause Handles requiert une variable WithEvents définie dans le type conteneur ou l'un de ses types de base.
so how can I create an events for dynamically created user control ?
this is the code for creation the controle checkBoxList
Protected Sub BtnDelImg_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnDelImg.Click
Dim CheckBoxList As New CheckBoxList
CheckBoxList.ID = "Check1"
CheckBoxList.AutoPostBack = True
AddHandler CheckBoxList.SelectedIndexChanged, AddressOf Check1_SelectedIndexChanged1
Dim files As String()
Dim File As String
files = IO.Directory.GetFiles("C:\DotNetNuke40\DesktopModules\Slider\Images", "*")
For Each File In files
'create img
Dim img As New HtmlGenericControl("img")
img.Attributes("src") = File
CheckBoxList.Items.Add(New ListItem(File.Substring(File.LastIndexOf("\") + 1), File))
CheckBoxList.Controls.Add(img)
Me.imgHolder.Controls.Add(CheckBoxList)
Next
End Sub
and this is the evet handler created for the dynamic checkBoxList the debuger dont recognized the Check1
Protected Sub Check1_SelectedIndexChanged1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Check1.SelectedIndexChanged
Dim Check1 As CheckBoxList = Page.FindControl("Check1")
Dim chklstItem As ListItem
LblListImages.Text = ""
For Each chklstItem In Check1.Items
If chklstItem.Selected = True Then
LblListImages.Text += chklstItem.Text & "<br>"
End If
Next
End Sub