travisowens Posted August 5, 2004 Posted August 5, 2004 I am using the following code example I dug up to learn template based ASP.Net web apps but I don't see how I can add dynamic controls (iow creating a Table control and putting it into the page). Here's the code for the header (testheader.ascx): <div align="center"> <font Size="5"><b>Test Header</b></font> </div> Here's the code for the footer (testfooter.ascx): <div align="center"><hr> <font Size="2"><i>Test Footer</i><br> Copyright 2002, All Rights Reserved</font> </div> Now - here's the main page, where each user control is inserted: <%@ Register TagPrefix="xprs" tagname="footer" src="Testfooter.ascx" %> <%@ Register TagPrefix="xprs" tagname="header" src="testheader.ascx" %> <html> <head> <meta name="GENERATOR" Content="ASP Express 2.0"> <title>Heading of Page Goes here</title> </head> <body> <xprs:header runat="server"/> <i><font Color="#0000FF">As you can see - the Header is on the top of this page. </font></i> <p> Again - two lines accomplish this, also.</font></i> <xprs:footer runat="server"/> </body> </html> Now when I try to do the following in my Page_Load event, no table appears in my page view in runtime, why not? Table menu = new Table(); TableRow row = new TableRow(); TableCell cell = new TableCell(); cell.Text = "TestCell"; row.Cells.Add(cell); menu.Rows.Add(row); Page.Controls.Add(menu); TextBox txtBox = new TextBox(); Page.Controls.Add(txtBox); Quote Experience is something you don't get until just after the moment you needed it
Moderators Robby Posted August 6, 2004 Moderators Posted August 6, 2004 Your code is not really Templating it's a UserControl. To add a userControl at run-time do the following... 'At the top of your page inside your class.... Private myHeader As Control = LoadControl("UserControl/myHeader.ascx") 'Then in your init event .... Me.Controls.Add(myHeader) 'Or you can add it to a Panel or something Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.