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.0problem with adding controls dynamically into loop problem with adding controls dynamically into loop
Previous
 
Next
New Post
4/1/2009 11:05 PM
 

 when I  try to create controls dynamiccally into a While loop I surprised that the statment "Panel.Contols.Add(control)" take just the last value (control) and view it on page please help me if there is a solution to resolve this big problem 

 

this is the portion of vb code loop (note : the problem on the red lines)

 

 

While dr.Read()

 

            'menu hover

 

            tab(i) = dr(0)

            'Response.Write(tab(i))

 

 

            'Dim menu As New AjaxControlToolkit.HoverMenuExtender

            menu.ID = "HoverMenuExtender" & dr(1).ToString

            menu.TargetControlID = "btn" & dr(1).ToString

            menu.PopupControlID = "PanelPopUp" & dr(1).ToString

            menu.PopupPosition = AjaxControlToolkit.HoverMenuPopupPosition.Bottom

            menu.OffsetX = 6

            menu.PopDelay = 25

            menu.HoverCssClass = "popupHover"

 

            Panel3.Controls.Add(menu)

 

            'linkBtn

            'Dim linkBtn As LinkButton

            linkBtn = New LinkButton

            linkBtn.ID = "btn" & dr(1).ToString

            linkBtn.Text = dr(1).ToString

 

            Panel2.Controls.Add(linkBtn)

 

            'panel child

            'Dim PopUpPanel As New Panel

            PopUpPanel.ID = "PanelPopUp" & dr(1).ToString

            'Response.Write(PopUpPanel.ID.ToString)

            tabPopUpName(j) = "PanelPopUp" & dr(1).ToString

            'Response.Write(tabPopUpName(j))

            j = j + 1

            PopUpPanel.CssClass = "popupMenu"

            PopUpPanel.Width = 373

            PopUpPanel.Height = 22

 

            Panel1.Controls.Add(PopUpPanel)

 

 

        End While

        dr.Close()

        myConnection.Close()

 

 

 

 

 

 
New Post
4/2/2009 6:29 AM
 

Your adding Menu,LinkButton,Popup Manuaaly .

Before adding these controls to panel create new instance every time with new key word

while...

 .............................

menu =new AjaxControlToolkit.HoverMenuPopupPosition.Bottom()

Panel3.Controls.Add(menu)

 

--...................

End While

similarly  for the remaining controsls inside loop

may be this may help you

 
New Post
4/2/2009 10:24 AM
 

thanks for intersting , about all the controls added dynamically exept (panel1,panel2,panel3) and this is all the code

 

vb code

 

Imports DotNetNuke

Imports System.Web.UI

Imports System.Web.UI.WebControls

Imports System.Collections.Generic

Imports System.Reflection

Imports System.Text

Imports DotNetNuke.Security.PortalSecurity

 

Partial Class DesktopModules_test_Test

    Inherits Entities.Modules.PortalModuleBase

 

 

    'Dim panel As New Panel

    'Dim panelString As StringBuilder

    Dim PopUpPanel As New Panel

    Dim linkBtnChild As New LinkButton

 

 

 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

 

        'for DB

        Dim myConnection As SqlConnection = New SqlConnection("server=ISITC-A31266378;uid=dnnuser40;pwd=1311984;database=DotNetNuke40")

        Dim myCommand As SqlCommand

        Dim dr As SqlDataReader

 

 

        Try

            If DotNetNuke.Framework.AJAX.IsInstalled Then

                DotNetNuke.Framework.AJAX.RegisterScriptManager()

            End If

        Catch exc As Exception        'Module failed to load

            ProcessModuleLoadException(Me, exc)

        End Try

 

 

        'establishing connection. you need to provide password for sql server

        myConnection.Open()

        'opening the connection

        myCommand = New SqlCommand("SELECT TabID, TabName FROM Tabs WHERE ParentID = 63", myConnection)

        'executing the command and assigning it to connection 

        dr = myCommand.ExecuteReader()

 

        Dim i As Integer = 0

        Dim j As Integer = 0

        Dim tab() As Integer = {0, 0, 0}

        Dim tabPopUpName As String() = New String(3) {"1", "2", "3", "4"}

 

 

        While dr.Read()

            'menu hover

 

            tab(i) = dr(0)

            'Response.Write(tab(i))

            i = i + 1

 

            Dim menu As New AjaxControlToolkit.HoverMenuExtender

            menu.ID = "HoverMenuExtender" & dr(1).ToString

            menu.TargetControlID = "btn" & dr(1).ToString

            menu.PopupControlID = "PanelPopUp" & dr(1).ToString

            'menu.PopupPosition = AjaxControlToolkit.HoverMenuPopupPosition.Bottom

            menu.OffsetX = 6

            menu.PopDelay = 25

            menu.HoverCssClass = "popupHover"

            Panel3.Controls.Add(menu)

 

 

            'linkBtn

            Dim linkBtn As LinkButton

            linkBtn = New LinkButton

            linkBtn.ID = "btn" & dr(1).ToString

            linkBtn.Text = dr(1).ToString

 

            Panel2.Controls.Add(linkBtn)

 

            'panel child

            'Dim PopUpPanel As New Panel

            PopUpPanel.ID = "PanelPopUp" & dr(1).ToString

            'Response.Write(PopUpPanel.ID.ToString)

            tabPopUpName(j) = "PanelPopUp" & dr(1).ToString

            'Response.Write(tabPopUpName(j))

            j = j + 1

            PopUpPanel.CssClass = "popupMenu"

            PopUpPanel.Width = 373

            PopUpPanel.Height = 22

 

            Panel1.Controls.Add(PopUpPanel)

 

        End While

        dr.Close()

        myConnection.Close()

 

        '#############################################################################################################################

 

        ' For Each panelTab As String In tabPopUpName

        'panel.ID = panelTab

        'panel.CssClass = "popupMenu"

        'panel.Width = 373

        'panel.Height = 22

        'panel.BackColor = Color.Chocolate

        'Panel1.Controls.Add(panel)

 

        'Response.Write(Parent)

        For Each Parent As Integer In tab    ''''''

            'establishing connection. you need to provide password for sql server

            myConnection.Open()

            'opening the connection

            myCommand = New SqlCommand("SELECT TabName FROM Tabs WHERE ParentID = " & Parent, myConnection)

            'executing the command and assigning it to connection 

            dr = myCommand.ExecuteReader()

            While dr.Read()

                'Response.Write(dr(0))

                'linkBtnChild

                linkBtnChild.ID = "Btn" & dr(0)

                linkBtnChild.CausesValidation = "true"

                linkBtnChild.CommandName = dr(0).ToString

                linkBtnChild.Text = dr(0).ToString

                'adding buttun to panel

                PopUpPanel.Controls.Add(linkBtnChild)

 

 

 

            End While

            dr.Close()

            myConnection.Close()

 

        Next

 

 

        'Next

 

    End Sub

 

 

 

 

 

    Protected Sub DropDownListAddMenu_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim DropDownListAddMenu As DropDownList = formView1.FindControl("DropDownListAddMenu")

        Dim LblAddMenuChoiced As Label = formView1.FindControl("LblAddMenuChoiced")

        LblAddMenuChoiced.Text = DropDownListAddMenu.SelectedValue

 

    End Sub

 

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim DropDownListAddParent As DropDownList = formView1.FindControl("DropDownListAddParent")

        Dim LblAddParentChoiced As Label = formView1.FindControl("LblAddParentChoiced")

        LblAddParentChoiced.Text = DropDownListAddParent.SelectedValue

    End Sub

 

    Protected Sub InsertItemButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)

 

    End Sub

 

    Protected Sub InsertCancelButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)

 

    End Sub

 

    Protected Sub LinkButtonAddMenu_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButtonAddMenu.Click

        Me.formView1.Visible = True

    End Sub

End Class

 

this is the ascx

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Test.ascx.vb" Inherits="DesktopModules_test_Test" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

 

<style type="text/css">

.popupMenu {

position:absolute;

visibility:hidden;

background-color:#AAFFFF;

opacity:.9;

filter: alpha(opacity=90);

}

 

.popupHover {

background-image:url(images/header-opened.png);

background-repeat:repeat-x;

background-position:left top;

background-color:#F5F7F8;

}

</style>

 

 

<asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px">

</asp:Panel>

 

 

<asp:Panel ID="Panel2" runat="server" Height="36px" Width="648px" BackColor="silver">

</asp:Panel>

 

<asp:Panel ID="Panel3" runat="server" Height="50px" Width="125px">

</asp:Panel>

 

 

 

 

 

<br />

 

 

<asp:formView ID="formView1" runat="server" 

DataKeyNames="MenuID" 

DataSourceID="SqlDataSource1"

    DefaultMode="Insert" Visible="False" CellPadding="4" ForeColor="#333333">

    <EditItemTemplate>

    </EditItemTemplate>

    <InsertItemTemplate>

    

    

    

<table>

    <tr>

        <td style="width: 100px">

            <asp:Label ID="LblAddMenu" runat="server" Text="add menu" Width="102px"></asp:Label></td>

        <td style="width: 24px">

        </td>

        <td style="width: 100px">

            <asp:DropDownList ID="DropDownListAddMenu" runat="server" DataSourceID="SqlDataSource2"

                DataTextField="TabName" DataValueField="TabID" OnSelectedIndexChanged="DropDownListAddMenu_SelectedIndexChanged">

            </asp:DropDownList></td>

        <td style="width: 158px">

            <asp:Label ID="LblAddMenuChoiced" runat="server" Width="115px" text='<%# Bind("TabID") %>'></asp:Label></td>

    </tr>

    <tr>

        <td style="width: 100px">

            <asp:Label ID="LblAddParent" runat="server" Text="add Parent" Width="99px"></asp:Label></td>

        <td style="width: 24px">

        </td>

        <td style="width: 100px">

            <asp:DropDownList ID="DropDownListAddParent" runat="server" DataSourceID="SqlDataSource2"

                DataTextField="TabName" DataValueField="TabID" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">

            </asp:DropDownList></td>

        <td style="width: 158px">

            <asp:Label ID="LblAddParentChoiced" runat="server" Width="142px" text='<%# Bind("ParentID") %>'></asp:Label></td>

    </tr>

    <tr>

        <td style="width: 100px; height: 21px;">

        </td>

        <td style="width: 24px; height: 21px;">

        </td>

        <td style="width: 100px; height: 21px;">

         <asp:LinkButton ID="InsertItemButton" runat="server" 

                 CausesValidation="True" CommandName="Insert"

                 Text="Insert" OnClick="InsertItemButton_Click">

             </asp:LinkButton>

             <asp:LinkButton ID="InsertCancelButton" runat="server" 

                 CausesValidation="False" CommandName="Cancel"

                 Text="Cancel" OnClick="InsertCancelButton_Click">

             </asp:LinkButton>

        </td>

        <td style="width: 158px; height: 21px">

        </td>

    </tr>

</table>

 

<br />

<br />

<br />

 </InsertItemTemplate>

     <ItemTemplate>

     </ItemTemplate>

    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />

    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <EditRowStyle BackColor="#999999" />

</asp:formView>

<br />

<asp:LinkButton ID="LinkButtonAddMenu" runat="server">add menu</asp:LinkButton><br />

&nbsp;<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"

    CellPadding="4" DataKeyNames="MenuID" DataSourceID="SqlDataSource1" EmptyDataText="Il n'y a aucun enregistrement de données à afficher."

    ForeColor="#333333" GridLines="None">

    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

    <Columns>

        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />

        <asp:BoundField DataField="MenuID" HeaderText="MenuID" ReadOnly="True" SortExpression="MenuID" />

        <asp:BoundField DataField="TabID" HeaderText="TabID" SortExpression="TabID" />

        <asp:BoundField DataField="ParentID" HeaderText="ParentID" SortExpression="ParentID" />

    </Columns>

    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />

    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <EditRowStyle BackColor="#999999" />

    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DotNetNuke40ConnectionString1 %>"

    DeleteCommand="DELETE FROM [Menu] WHERE [MenuID] = @MenuID" InsertCommand="INSERT INTO [Menu] ([TabID], [ParentID]) VALUES (@TabID, @ParentID)"

    ProviderName="<%$ ConnectionStrings:DotNetNuke40ConnectionString1.ProviderName %>"

    SelectCommand="SELECT [MenuID], [TabID], [ParentID] FROM [Menu]" UpdateCommand="UPDATE [Menu] SET [TabID] = @TabID, [ParentID] = @ParentID WHERE [MenuID] = @MenuID">

    <DeleteParameters>

        <asp:Parameter Name="MenuID" Type="Int32" />

    </DeleteParameters>

    <InsertParameters>

        <asp:Parameter Name="TabID" Type="Int32" />

        <asp:Parameter Name="ParentID" Type="Int32" />

    </InsertParameters>

    <UpdateParameters>

        <asp:Parameter Name="TabID" Type="Int32" />

        <asp:Parameter Name="ParentID" Type="Int32" />

        <asp:Parameter Name="MenuID" Type="Int32" />

    </UpdateParameters>

</asp:SqlDataSource>

<br />

<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AutoGenerateColumns="False"

    CellPadding="4" DataKeyNames="TabID" DataSourceID="SqlDataSource2" EmptyDataText="Il n'y a aucun enregistrement de données à afficher."

    ForeColor="#333333" GridLines="None">

    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

    <Columns>

        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />

        <asp:BoundField DataField="TabID" HeaderText="TabID" ReadOnly="True" SortExpression="TabID" />

        <asp:BoundField DataField="TabName" HeaderText="TabName" SortExpression="TabName" />

        <asp:BoundField DataField="ParentId" HeaderText="ParentId" SortExpression="ParentId" />

    </Columns>

    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />

    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

    <EditRowStyle BackColor="#999999" />

    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DotNetNuke40ConnectionString1 %>"

    ProviderName="<%$ ConnectionStrings:DotNetNuke40ConnectionString1.ProviderName %>"

    SelectCommand="SELECT * FROM [Tabs]"></asp:SqlDataSource>

&nbsp;<br />

 

 

 

 

 
New Post
4/3/2009 1:00 AM
 

Declare all Dynamoc controls Outside While Loop and create Instance Inside while loop

Dim menu As AjaxControlToolkit.HoverMenuExtender
Dim linkBtn As LinkButton
Dim PopUpPanel As PopUpPanel

While Loop
  ....
  menu= new AjaxControlToolkit.HoverMenuExtender()
  Panel3.controls.add(menu)
  ...
  linkBtn = new  LinkButton  
  Panel2.controls.add(linkBtn)
  ...
  PopUpPanel =new PopUpPanel
  Panel1.controls.add(PopUpPanel)
  ..
end While
 

 
New Post
4/4/2009 9:46 PM
 

I try to do with your tips but i got the same problem i thank that the problem is refer to the varables names of every instance should be different to each others 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0problem with adding controls dynamically into loop problem with adding controls dynamically into loop


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