On the test page..
<%
@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Site.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><%@ MasterType VirtualPath="~/MasterPages/Site.master"/>
<%@ Register src="Controls/CartControl.ascx" tagname="CartControl" tagprefix="uc1" %>
<
asp:Content ID="Content1" ContentPlaceHolderID="PlaceStyleSheetsHere" Runat="Server">asp:Content>
<
asp:Content ID="Content2" ContentPlaceHolderID="PlaceContentHere" Runat="Server"><uc1:CartControl ID="crap" runat="server" />
asp:Content>
WORKS LIKE A CHARM.. BUT
using
System;using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class Default2 :SiteBasePage
{
protected void Page_Load(object sender, EventArgs e)
{
Controls_CartControl ctrl = new Controls_CartControl();
Controls.Add(ctrl);
}
}
DOES NOT WORK AT ALL...
What the heck is wrong with this????
David JohnsonPosted Jul 2, 2008, 12:03 PM
The Code behind looks like this
public
partial class Cart : SiteBasePage{
protected void Page_Load(object sender, EventArgs e)
{
CartControl control = new CartControl();
control.ID = "OrderItem1";
control.Visible = true;
CartControlsDiv.Controls.Add(control);
}
}
the Page Code looks like this
<div id="CartControlsDiv" runat="server"><uc1:CartControl ID="crap" runat="server" />
div>
Crap renders but the OrderItem1 does not Also what is the diff in a user control and a webControl???
Finally the weirdes thing is on unload of the control all the controls on the page are still NULL
I have a test textbox called textbox1 and when I try to set the text the Textbox1 is a property of the control but it is null????
Do I have to manually fire Create Child Controls????
Scott LyslePosted Jul 2, 2008, 4:50 AM
Add it to something like a panel or div with by it's id and with runat="server" set. For example, if you want to add it to a div set up like this:
<
form id="form1" runat="server"> <div id="SomeDiv" runat="server">div> form>You would use this code:
protected void Page_Load(object sender, EventArgs e)
{
TextBox tb = new TextBox();
tb.ID = "txt1";
tb.Text = "Look at that";
SomeDiv.Controls.Add(tb);
}