How to For Each in RadWebControl in master page

4 posts, 0 answers
  1. Mohammed
    Mohammed avatar
    5 posts
    Member since:
    Jun 2013

    Posted 01 Oct 2013 Link to this post


    How to For Each in RadWebControl with page or master page .

    I need  For Each  control in page.RadWebControl. and Add ID and text in RadListBox1

    Example :

    RadListBox1.Items.Add(New RadListBoxItem(control .ID))
    RadListBox1.Items.Add(New RadListBoxItem(control .text))




  2. Mohammed
    Mohammed avatar
    5 posts
    Member since:
    Jun 2013

    Posted 02 Oct 2013 Link to this post

    I am use this code. It works well, but there is a minor problem.

    For Each c In ContentPlaceHolder1.Controls
     
                ' RadListBox1.Items.Add
                If c.ID IsNot Nothing Then
                    RadListBox1.Items.Add(New RadListBoxItem(c.ID.ToString))
                End If
     
                'RadListBox2.Items.Add
                If TypeOf c Is RadAjaxPanel Then
                    For Each childc In c.Controls
                        'If TypeOf childc Is RadTextBox Then
                        '    'allTextBoxValues &= CType(childc, TextBox).Text & ","
                        'End If
                        If childc.ID IsNot Nothing Then
                            RadListBox2.Items.Add(New RadListBoxItem(childc.ID.ToString))
                        End If
     'Here Not work, problem , NO Find Controls
                        If TypeOf childc Is UpdatePanel Then
                            Dim UpPL As UpdatePanel = CType(childc, UpdatePanel)
                            For Each child22 In UpPL.Controls
                                If child22.ID IsNot Nothing Then
                                    RadListBox3.Items.Add(New RadListBoxItem(child22.ID.ToString))
                                End If
     
                                If TypeOf child22 Is Panel Then
                                    Dim PL As Panel = CType(child22, Panel)
                                    For Each child33 In PL.Controls
     
                                        If child33.ID IsNot Nothing Then
                                            RadListBox3.Items.Add(New RadListBoxItem(child33.ID.ToString))
                                        End If
                                    Next
                                End If
                            Next
                        End If
     
                    Next
                End If
    Next
  3. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 02 Oct 2013 Link to this post

    Hi Mohammed,

    You can use the following method to get all the RadControls registered on the page as a list:

    Public Function FindRadControls(parent As Control) As List(Of RadWebControl)
        Dim result As New List(Of RadWebControl)()
        For Each c As Control In parent.Controls
     
            If TypeOf c Is Telerik.Web.UI.RadWebControl Then
                result.Add(TryCast(c, RadWebControl))
            End If
            If c.Controls.Count > 0 Then
                result.AddRange(FindRadControls(c))
            End If
        Next
        Return result
    End Function


    Regards,
    Dobromir
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  4. Mohammed
    Mohammed avatar
    5 posts
    Member since:
    Jun 2013

    Posted 02 Oct 2013 Link to this post

    Thank you, Mr.Dobromir 
    I will inspect the code.
Back to Top