Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > adding a XML control to a web custom control

Reply
Thread Tools

adding a XML control to a web custom control

 
 
Brian Henry
Guest
Posts: n/a
 
      11-14-2004
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


 
Reply With Quote
 
 
 
 
Derek Harmon
Guest
Posts: n/a
 
      11-14-2004
"Brian Henry" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
Brian Henry
Guest
Posts: n/a
 
      11-14-2004
thanks!

"Derek Harmon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Brian Henry" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem dynamically adding Custom Web Control. Gibble ASP .Net 0 05-17-2007 04:18 PM
Problem dynamically adding Custom Web Control. Gibble ASP .Net 0 05-17-2007 03:50 PM
Adding a control to a custom web control Web Team @ Borough of Poole ASP .Net 5 09-14-2005 01:02 AM
Adding a control to a custom web control Web Team @ Borough of Poole ASP .Net 0 09-10-2005 10:10 AM
ControlDesigner not invoked on custom control when control is rendered within another custom control Matt Sokol ASP .Net Building Controls 2 08-07-2003 07:13 AM



Advertisments