|
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
namespace JavascriptWriters
{
public class JsWriter : System.Web.UI.HtmlControls.HtmlGenericControl
{
public JsWriter(string tagName)
{
//Nothing needs to happen here.
}
#region Methods & Event Handlers
protected override void OnPreRender(EventArgs e)
{
Page.ClientScript.RegisterClientScriptInclude("jsWritersScript", Page.ClientScript.GetWebResourceUrl(this.GetType(), "JavascriptWriters.javascriptWriters.js"));
base.OnPreRender(e);
}
protected override void Render(HtmlTextWriter output)
{
string[] htmlLines = (this.InnerHtml.Trim()).Split('\n');
string outString = "";
for (int i = 0; i < htmlLines.Length; i++)
{
string currentLine = htmlLines[i].Replace("'", "\\'").Replace("\r", "");
if (i > 0)
outString += "+";
if (i == htmlLines.Length - 1)
outString += "'" + currentLine + "';\n";
else
outString += "'" + currentLine + "'\n";
}
string varName = "objStr_" + this.UniqueID;
output.Write("<script language=\"javascript\">");
output.Write(Environment.NewLine);
output.Write("var " + varName + " = " + outString);
output.Write(Environment.NewLine);
output.Write("InsertObjectToDocument(document," + varName + ");");
output.Write(Environment.NewLine);
output.Write("</script>");
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Seth Berger is a Technology Director at WHITTMANHART Interactive. At WHITTMANHART he develops and manages large .NET projects for some of the world's most successful companies. He is skilled in a large number of languages and development environments but his primary focus is on ASP.NET development, and has worked on it since it was in beta. He previously co-founded Estco Medical, a web development and software company focused on the life-science industry.