Loading Controls dynamically

Discussion in 'ASP .Net' started by tshad, Jul 30, 2007.

  1. tshad

    tshad Guest

    I am using asp.net 1.1 and am creating my pages with different looks where
    the middle right is where my actual changing content will go.

    It seems to work pretty well except for some strange behavior and this seems
    to be caused from the placement of the my Panel objects. I am using Panels
    as placeholders for my controls. I can't just put controls on the page as
    registered objects as the objects will be different based on the companies
    that are using them. So I load the control and add them to the panel. I
    have been told this is the best way to do this.

    The problem is that the Panels are changed to <Div ID="x">. Since my
    controls are basically html code for the look, I end up with the </div> tag
    inside a <td> statement. This is not legal and causes some issues.

    What it looks like is something like:

    <div "test">
    <table>
    <tr>
    <td>
    ....
    </div>
    </td>
    </tr>
    </table>

    The problem is that the opening <div> tag is outside the table and the
    closing </div> tag is inside the table. If I wasn't using a placeholder
    that changed to <div> there wouldn't be a problem.

    Is there a way to have the Panel not create a <div> tag? Or a better way to
    load the objects?

    As you can see from the following, there is the basically the following
    objects and html code:
    1) Top of the page
    2) Navigation menus
    3) Form tag
    4) Object that as all the textboxes, labels asp.net code etc.
    5) Closing Form tag
    6) Bottom of the page

    I had also thought about just using one Panel and adding the controls into
    that panel. Not sure how to do the Form part, however, unless I just create
    2 controls 1 that has only the Form tag and one that has only the closing
    form tag.

    *****************************************
    <%@ Page Language="VB" trace="false" debug="true" ContentType="text/html"
    ResponseEncoding="iso-8859-1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <script runat="server">
    Sub Page_Load(sender as Object, e as EventArgs)
    Dim pageTop as String
    Dim navigateTop as String
    Dim pageBottom as String
    Dim pageTopControl as Control
    Dim navigateTopControl as Control
    Dim pageBottomControl as Control
    Dim LogonControl as Control
    Dim skinArray as ArrayList = Application("SkinArray")
    for i as integer = 0 to skinArray.Count - 1 step 3
    if skinArray(i) = request("MID") then
    session("CompanyInitials") = skinArray(i+1)
    end if
    Next
    if session("CompanyInitials") = "sdhc" orElse session("CompanyInitials") =
    "fts" orElse session("CompanyInitials") = "mazda" then
    pageTop = "/skins/" & session("CompanyInitials") & "/" &
    session("CompanyInitials") & "PageTop" & ".ascx"
    navigateTop = "/skins/" & session("CompanyInitials") & "/" &
    session("CompanyInitials") & "NavigateTop" + ".ascx"
    pageBottom = "/skins/" & session("CompanyInitials") & "/" &
    session("CompanyInitials") & "PageBottom" + ".ascx"
    end if

    pageTopControl = LoadControl(pageTop)
    PageTopPanel.Controls.Add(pageTopControl)
    navigateTopControl = LoadControl(navigateTop)
    NavigateTopPanel.Controls.Add(navigateTopControl)
    LogonControl = LoadControl("/applicant/DisplayCompanyJobs.ascx")
    LogonPanel.Controls.Add(LogonControl)
    pageBottomControl = LoadControl(pageBottom)
    PageBottomPanel.Controls.Add(pageBottomControl)
    end Sub
    </script>

    <html>
    <head>
    <title>:: Staffing Workshop ::</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <body id="myBody" leftmargin="0" topmargin="0" marginwidth="0"
    marginheight="0" runat="server">
    <asp:panel ID="PageTopPanel" runat="server"/>
    <asp:panel ID="NavigateTopPanel" runat="server"/>
    <form id="addForm" runat="server">
    <asp:panel ID="LogonPanel" runat="server"/>
    </form>
    <asp:panel ID="PageBottomPanel" runat="server"/>
    <asp:label CSSClass="UserHeaderLabel" visible=false id="UserLoggedOnLabel"
    text="Hello: " runat="server"/>
    <asp:label CSSClass="UserHeader" visible=false id="UserLoggedOn"
    runat="server"/></body>
    </html>
    ******************************************

    Thanks,

    Tom
     
    tshad, Jul 30, 2007
    #1
    1. Advertising

  2. Hello Tom

    > Is there a way to have the Panel not create a <div> tag? Or a better way
    > to load the objects?

    Use a System.Web.UI.WebControls.PlaceHolder Control instead of a Panel, that
    Control would not generate any Code, as the name sounds ;-)
    -
    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.placeholder(vs.71).aspx

    --
    Gruss, Peter Bucher
    Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
    http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
     
    Peter Bucher [MVP], Jul 30, 2007
    #2
    1. Advertising

  3. tshad

    tshad Guest

    That's exactly what I was looking for. I didn't know there was a
    Placeholder object in asp.net.

    I'll try that.

    Thanks,

    Tom

    "Peter Bucher [MVP]" <> wrote in message
    news:%...
    > Hello Tom
    >
    >> Is there a way to have the Panel not create a <div> tag? Or a better way
    >> to load the objects?

    > Use a System.Web.UI.WebControls.PlaceHolder Control instead of a Panel,
    > that Control would not generate any Code, as the name sounds ;-)
    > -
    > http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.placeholder(vs.71).aspx
    >
    > --
    > Gruss, Peter Bucher
    > Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
    > http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
    > http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
     
    tshad, Jul 30, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]
    Replies:
    0
    Views:
    610
    Ben Miller [msft]
    Aug 5, 2003
  2. sonic_soul
    Replies:
    0
    Views:
    524
    sonic_soul
    Aug 14, 2003
  3. Jill Graham
    Replies:
    1
    Views:
    362
    Jim Corey
    May 3, 2004
  4. =?Utf-8?B?V291dGVy?=

    Dynamically Loaded controls loading other controls

    =?Utf-8?B?V291dGVy?=, Feb 27, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    513
    =?Utf-8?B?V291dGVy?=
    Feb 27, 2006
  5. Bob Rock
    Replies:
    1
    Views:
    671
    Cowboy \(Gregory A. Beamer\)
    Sep 17, 2006
Loading...

Share This Page