Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to create events for dynamically created user control ?How to create events for dynamically created user control ?
Previous
 
Next
New Post
4/12/2009 10:06 PM
 

 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
 
 
 
 

 
New Post
4/13/2009 6:03 AM
 

You need to make sure that your control is created before the view_state gets loaded after a postback. Usually that means that you need to create your control during page init.


Erik van Ballegoij, Former DNN Corp. Employee and DNN Expert

DNN Blog | Twitter: @erikvb | LinkedIn: Erik van Ballegoij on LinkedIn

 
New Post
4/13/2009 1:48 PM
 

 you are the man,  resolved thank you I put all the code in the BtnDelImg_Click sub into init sub

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to create events for dynamically created user control ?How to create events for dynamically created user control ?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out