Tuesday, December 15, 2009

JQuery and Master Pages

How to register jquery scripts with a master page? After much agonizing, I came upon this (which is learned from http://geekswithblogs.net/rachit/archive/2007/01/14/103608.aspx)...

HtmlGenericControl jqueryScriptTag = new HtmlGenericControl();
jqueryScriptTag.TagName = "script";
jqueryScriptTag.Attributes.Add("type", "text/javascript");
jqueryScriptTag.Attributes.Add("language", "javascript"); //don't need it usually but for cross browser.
jqueryScriptTag.Attributes.Add("src", "http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.js");
this.Page.Header.Controls.Add(jqueryScriptTag);

HtmlGenericControl jqueryDimensionsScriptTag = new HtmlGenericControl();
jqueryDimensionsScriptTag.TagName = "script";
jqueryDimensionsScriptTag.Attributes.Add("type", "text/javascript");
jqueryDimensionsScriptTag.Attributes.Add("language", "javascript"); //don't need it usually but for cross browser.
jqueryDimensionsScriptTag.Attributes.Add("src", ResolveUrl("~/Scripts/jquery.dimensions.js"));
this.Page.Header.Controls.Add(jqueryDimensionsScriptTag);

No comments:

Post a Comment