Javascript and Css are usually referenced in the
Write a class that references Javascript and Css in the background
/// <Summary>
/// Add the JS script Link
/// </Summary>
/// <Param name = "page"> page </param>
/// <Param name = "url"> path </param>
Public static void AddJS (System. Web. UI. Page page, string url)
{
HtmlGenericControl jsControl = new HtmlGenericControl ("script ");
JsControl. Attributes. Add ("type", "text/javascript ");
JsControl. Attributes. Add ("src", url );
Page. Header. Controls. Add (jsControl );
}
/// <Summary>
/// Add JS script content
/// </Summary>
/// <Param name = "page"> page </param>
/// <Param name = "content"> script content </param>
Public static void AddScript (System. Web. UI. Page page, string content)
{
HtmlGenericControl scriptControl = new HtmlGenericControl ("script ");
ScriptControl. Attributes. Add ("type", "text/javascript ");
ScriptControl. InnerHtml = content;
Page. Header. Controls. Add (scriptControl );
}
/// <Summary>
/// Add a CSS style Link
/// </Summary>
/// <Param name = "page"> page </param>
/// <Param name = "url"> path </param>
Public static void AddCss (System. Web. UI. Page page, string url)
{
HtmlLink link = new HtmlLink ();
Link. Href = url;
Link. Attributes. Add ("rel", "stylesheet ");
Link. Attributes. Add ("type", "text/css ");
Page. Header. Controls. Add (link );
}
/// <Summary>
/// Add CSS style content
/// </Summary>
/// <Param name = "page"> page </param>
/// <Param name = "content"> style content </param>
Public static void AddStyle (System. Web. UI. Page page, string content)
{
HtmlGenericControl styleControl = new HtmlGenericControl ("style ");
StyleControl. Attributes. Add ("type", "text/css ");
StyleControl. InnerHtml = content;
Page. Header. Controls. Add (styleControl );
}
/// <Summary>
/// Add a Meta tag
/// </Summary>
/// <Param name = "page"> page </param>
/// <Param name = "name"> HttpEquiv </param>
/// <Param name = "content"> Meta content </param>
Public static void AddMeta (System. Web. UI. Page page, string name, string content)
{
HtmlMeta = new HtmlMeta ();
Meta. HttpEquiv = name;
Meta. Content = content;
Page. Header. Controls. Add (meta );
}
From Ai Zhi Chen