How to access values of dynamically created controls on postback for a RadWindow

2 posts, 0 answers
  1. Hunter
    Hunter avatar
    26 posts
    Member since:
    Aug 2012

    Posted 17 Feb 2013 Link to this post

    Maybe I'm not doing this the right way, but I'm trying to use RadWindow as a dialog box.  When I add controls (dropdownlist, textbox, listbox) to the RadWindow dynamically I'm not able to figure out how to get the new values of these dynamic controls on a postback.

    I've tried 2 different approaches to adding the dynamic controls to the Radwindow.  In the first case I added a Panel dynamically to rwinProperties.ContentContainer and I add all my controls to this panel.  I look for the dynamic controls on rwinProperties.ContentContainer.Controls.  But I don't see them there after the postback.  I also tried creating a static Panel inside the ContentTemplate and adding all the dynamic controls to it.  Still no luck.

    The postback is created by a radbutton I added statically in the RadWindow in the ContentTemplate.  I'm suspecting

    So I'm suspecting that I can't these values from a postback, so how do I get them? 

    Thanks
    Sub SetSectionProperties(ByVal SectionID As String, SectionCount As String, ByVal SectionName As String)
         
        Dim SectionString As String = SectionID & "__" & SectionCount
        Dim Properties As New clsDashboardProperties(SectionID)
         
        Dim PropertyName As String
        Dim PropertyNameTitle As String
        Dim PropertyDesc As String
        Dim PropertyID As Integer
        Dim PropertyVisible As Boolean
        Dim ValueSet As String = ""
        Dim DefaultValue As String
        Dim ControlType As String = ""
        Dim lbl As Label
        Dim ddl As DropDownList
        Dim lbx As ListBox
        Dim tb As TextBox
        Dim lc As LiteralControl
        Dim ht As Hashtable = Session("SessionProperties")
        Dim pnl As New System.Web.UI.WebControls.Panel
        Dim pnl2 As New System.Web.UI.WebControls.Panel
        Dim oProp As clsDashboardPropertyMapItem
         
        Dim tbl As Table
        Dim tbl2 As Table 'For invisible properties
        Dim rw As TableRow
        Dim cell As TableCell
     
        pnl.ID = "pnlDialog"
        pnl.Width = New Unit("100%")
        pnl.Height = New Unit("100%")
        pnl.BorderWidth = 1
        pnl.BackColor = Drawing.Color.LightGray
        pnl.Visible = True
         
        rwinProperties.ContentContainer.Controls.Add(pnl)
     
        lbl = New Label
        lbl.Text = "<br/><b>  " & SectionName & " " & "Properties</b>"
        pnl.Controls.Add(lbl)
         
        lbl = New Label()
        lbl.Text = "<br/><br/>"
        pnl.Controls.Add(lbl)
         
        If Properties.Count >= 1 Then
            tbl = New Table
            tbl2 = New Table
            tbl2.Visible = False
             
            For Each prop As clsDashboardProperty In Properties
                PropertyName = prop.PropertyName
                PropertyNameTitle = prop.PropertyNameTitle
                ValueSet = prop.ValueSet
                ControlType = prop.ControlType
                PropertyDesc = prop.PropertyDesc
                PropertyID = prop.PropertyID
                PropertyVisible = prop.PropertyVisible
                DefaultValue = prop.DefaultValue
     
                rw = New TableRow()
                cell = New TableCell()
                cell.Width = 10
                cell.Text = " "
                rw.Controls.Add(cell)
                 
                cell = New TableCell()
                cell.Text = "<b>" & PropertyNameTitle & ":</b>  "
                rw.Controls.Add(cell)
                cell = New TableCell()
                 
                'Add some space
                cell = New TableCell()
                cell.Width = 10
                cell.Text = " "
                rw.Controls.Add(cell)
                 
                Dim Values() As String = ValueSet.Split(",")
                         
                If ControlType = "lb" Then
                    lbl = New Label
                    lbl.Text = Values(0)
                    lbl.ID = "lb_" & SectionString & "_" & PropertyID & "_" & PropertyName
                    lbl.Visible = PropertyVisible
     
                    cell.Controls.Add(lbl)
                             
                ElseIf ControlType = "ddl" Then
                    ddl = New DropDownList
                    ddl.Items.Add("Default")
     
                    For Each Val As String In Values
                        ddl.Items.Add(Val)
                    Next
     
                    ddl.ID = "ddl_" & SectionString & "_" & PropertyID & "_" & PropertyName
                    ddl.Visible = PropertyVisible
     
                    ddlSelect(ddl, DefaultValue) 'Go select an item in the list
     
                    cell.Controls.Add(ddl)
                ElseIf ControlType = "lbx" Then
                    lbx = New ListBox
                    lbx.Items.Add("Default")
                    lbx.SelectionMode = ListSelectionMode.Multiple
                    For Each Val As String In Values
                        lbx.Items.Add(Val)
                     Next
     
                    lbx.ID = "ddl_" & SectionString & "_" & PropertyID & "_" & PropertyName
                    lbx.Visible = PropertyVisible
     
                    lbxSelect(lbx, DefaultValue) 'Go select items in the list
     
                    cell.Controls.Add(lbx)
                ElseIf ControlType = "tb" Then
                    tb = New TextBox
                    tb.ID = "tb_" & SectionString & "_" & PropertyID & "_" & PropertyName
                    tb.Text = Values(0)
                    tb.Visible = PropertyVisible
     
                    cell.Controls.Add(tb)
                ElseIf ControlType = "tbml" Then  'Multiline textbox
                    tb = New TextBox
                    tb.ID = "tb_" & SectionString & "_" & PropertyID & "_" & PropertyName
                    tb.Text = Values(0)
                    tb.Visible = PropertyVisible
     
                    tb.TextMode = TextBoxMode.MultiLine
                    tb.Rows = 4
                    tb.Columns = 35
                    tb.Font.Name = "Arial"
                 
                    cell.Controls.Add(tb)
                End If
     
                rw.Controls.Add(cell)
             
                'Add some space
                cell = New TableCell()
                cell.Width = 10
                cell.Text = " "
                rw.Controls.Add(cell)
                 
                'Add the description of the property
                cell = New TableCell()
                cell.Text = "<i>" & PropertyDesc & "</i>  "
                rw.Controls.Add(cell)
     
                If PropertyVisible Then
                    tbl.Controls.Add(rw)
                Else
                    tbl2.Controls.Add(rw)
                End If
            Next
     
            pnl.Controls.Add(tbl)
                 
            If tbl2.Rows.Count > 0 Then
                pnl.Controls.Add(tbl2)
            End If
             
            lc = New LiteralControl()
            lc.Text = "<br/>"
     
            pnl.Controls.Add(lc)
        Else
     
            lbl = New Label
            lbl.Text = "    No Properties available for this section.<br/><br/>"
            pnl.Controls.Add(lbl)
        End If
         
        lc = New LiteralControl()
        lc.Text = "  "
        pnl.Controls.Add(lc)      
     
    End Sub
     
    Sub rbtnUpdateProperties_Click(ByVal sender As Object, ByVal e As System.EventArgs)
         
        Dim pnl As Panel = rwinProperties.ContentContainer.FindControl("pnlDialog")
        For Each Ctl As Control In pnl.Controls
            If Ctl.ID.StartsWith("ddl") Then
                Dim ddl As DropDownList = CType(Ctl, DropDownList)
                Dim name As String = ddl.ID
                Dim value As String = ddl.SelectedValue
                Dim fields() As String = name.Split("_")
         
                AddToProperties(fields(1), fields(3), fields(5), name, value)
            ElseIf Ctl.ID.StartsWith("lbx") Then
                Dim lbx As ListBox = CType(Ctl, ListBox)
                Dim name As String = lbx.ID
                Dim value As String = GetListBoxSelectedValues(lbx)
                Dim fields() As String = name.Split("_")
         
                AddToProperties(fields(1), fields(3), fields(5), name, value)
                         
            ElseIf Ctl.ID.StartsWith("tb") Then
                Dim tb As TextBox = CType(Ctl, TextBox)
                Dim name As String = tb.ID
                Dim value As String = tb.Text
                Dim fields() As String = name.Split("_")
         
                AddToProperties(fields(1), fields(3), fields(5), name, value)
            ElseIf Ctl.ID.StartsWith("tbml") Then
                Dim tb As TextBox = CType(sender, TextBox)
                Dim name As String = tb.ID
                Dim value As String = tb.Text
                Dim fields() As String = name.Split("_")
         
                AddToProperties(fields(1), fields(3), fields(5), name, value)
            End If
        Next
         
        UpdateZone()
    End Sub

    <telerik:RadWindow runat="server" ID="rwinProperties" Modal="true" Height="450" Width="550" Title="Panel Properties"  CssClass="RadWindow"  >
        <ContentTemplate>
     
                <telerik:RadButton id="rbtnUpdateProperty" runat="server" Text="Update" EnableEmbeddedSkins="false" Skin="SOD_SKIN" AutoPostBack="true" OnClick="rbtnUpdateProperties_Click" />
                           
                <telerik:RadButton id="rbtnClosePropertyWindow" runat="server" Text="Cancel" EnableEmbeddedSkins="false" Skin="SOD_SKIN"    />
     
        </ContentTemplate>
    </telerik:RadWindow>
  2. Hunter
    Hunter avatar
    26 posts
    Member since:
    Aug 2012

    Posted 17 Feb 2013 Link to this post

    Hmmm.  After more research I think I need to create a new .aspx page and create that controls there and display them via the RadWindow.

    So I'm off to do that and hopefully that will be more successful.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top