470,620 Members | 1,557 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,620 developers. It's quick & easy.

adding a XML control to a web custom control

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? I am using the web
custom control as a template that I can add to the page, but it depends on
other Web Form controls inside it but I do not know how to add the other web
form controls such as a XML web form control into this programatticly
created control. thanks
Nov 18 '05 #1
2 1389
"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
Nov 18 '05 #2
thanks!

"Derek Harmon" <lo*******@msn.com> wrote in message
news:Oq**************@TK2MSFTNGP15.phx.gbl...
"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

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by James Geurts | last post: by
2 posts views Thread by Stephen Lambie | last post: by
18 posts views Thread by Praveen Ramesh | last post: by
5 posts views Thread by Web Team | last post: by
3 posts views Thread by Fao, Sean | last post: by
3 posts views Thread by Jonathan Wood | last post: by
11 posts views Thread by Pete Kane | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.