Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

Loading Controls dynamically

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tshad - 30 Jul 2007 19:21 GMT
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
Peter Bucher [MVP] - 30 Jul 2007 19:36 GMT
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(v
s.71).aspx


Signature

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 - 30 Jul 2007 19:50 GMT
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

> Hello Tom
>
[quoted text clipped - 4 lines]
> -
> http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.placeholder(v
s.71).aspx

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.