views:

209

answers:

2

How do you inject HTML to a server control?

I'm creating a calendar control and have some javascript/css that go with it.

In addition, I have some html code that gets generated with the proper ClientIDs that work with the JS/CSS and I would like to inject this to where the "server" control is used.

For example:

<MyUC:UC1 ID="someUC" runat="server" />

Using LiteralControls/RegisterClientScriptBlock for including the CSS/JS but was wondering about HTML injection to the body.

This would render as the control I've built PLUS the CSS/JSS/HTML that would go with it.

I guess I can generate the dom elements within the javascript include, but I was wondering how I could do it from the server side.

+1  A: 

LB:

Have a look at this CodeProject article:

Simplify the construction of HTML inside ASP.NET server controls using ControlInjector
http://www.codeproject.com/KB/aspnet/ControlInjector.aspx

Robert Harvey
A: 

If you need to just add some extra markup, you could use the LiteralControl to add some HTML to your server control.

myServerControl.Controls.Add(new LiteralControl("<br />"));

Alternatively, you can use the System.Web.UI.HtmlControls library to generate specific server controls on the back-end, and programmatically create the HTML structure you'd like within your server control.

Jay S