"Brian Henry" <br**********@newsgroups.nospam> wrote in message news:O3**************@TK2MSFTNGP09.phx.gbl...
I want to create a web custom control (not a user web control) that I can
add a XML translation control into, how would I do this?
So you've created this WebCustomControl1 type from the default web
custom control project, right? Now you want to add an Xml web control
into it (or perhaps several Xml web controls into it). OK, two steps.
In your control's OnInit override (or this can also be done externally
from the Page_Init event handler) you need to create an instance of
the Xml web control and add it to the child Controls collection of the
WebCustomControl1 class.
e.g.,
protected override void OnInit( EventArgs e)
{
// Always call base class's OnInit( ) in case it does anything.
base.OnInit( e);
// Create an Xml control.
System.Web.UI.WebControls.Xml xmlControl1 = new Xml( );
// Set some properties on it; in this case my XML is really xHTML so
// it'll show up in the browser w/o too much hassle.
xmlControl1.ID = "XmlControl1";
xmlControl1.DocumentContent = "<span style='color:red;'>text</span>";
xmlControl1.TransformSource = "./IdentityTransform.xsl";
// Add the Xml control as one of this control's children.
this.Controls.Add( xmlControl1);
}
Next step is that when the ASP.NET Framework tells WebCustomControl1
to render itself, WebCustomControl1 needs to tell any child controls that they
should render themselves.
protected override void Render(HtmlTextWriter output)
{
// This line is generated automatically by the Code Wiz.
output.Write( Text);
// Render all child controls to this HtmlTextWriter.
this.RenderChildren( output);
}
Now you should be set to go. The technique is known as "composite controls,"
if you have further questions about them.
Derek Harmon