One thing I have been doing lately is injecting custom crafted html and javascript into pages. I have found that a great way to do this is to use string.concat() because not only can you indent lines easily to get good code formatting, but you can also easily comment out lines. I wish there was a better way, but so far this is the best I’ve found. If anyone knows of a better way please let me know.
private string GetWidgetScript()
{
return string.Concat(
"<script type=\"text/javascript\">",
"$(document).ready(function() {",
"$('#",ClientID,"_WidgetHeader').click(function () {",
"$('#",ClientID,"_Widget').slideToggle('normal');",
"});",
"});",
"</script>"
);
}
private void BeforeInitControls()
{
Controls.Add(new LiteralControl(
string.Concat(
//GetWidgetScript(),
"<div id=\"",ClientID,"_WidgetHeader\" class=\"widgetHeader\">",Header,"</div>",
"<div id=\"",ClientID,"_Widget\" class=\"widget\">"
)));
}