Calling the procedure below in your DotNetNuke module will make sure that your client script will be inserted in the proper place. Which is inside the Head tag.
The Code:
Sample:
Inserting a script file;
Result:
Inserting a plain script;
Result:
The Code:
01.Public Sub InjectClientScript(ByVal page As System.Web.UI.Page, ByVal scriptKey As String, ByVal scriptSrc As String, Optional ByVal scriptValue As String = "") 02. Dim objHead As Control = page.FindControl("Head") 03. If objHead IsNot Nothing Then04. If objHead.FindControl(scriptKey) Is Nothing Then05. Dim jQueryControl As New HtmlGenericControl("script") 06. jQueryControl.ID = scriptKey 07. jQueryControl.Attributes.Add("type", "text/javascript") 08. If scriptValue = "" Then09. jQueryControl.Attributes.Add("src", scriptSrc) 10. Else11. jQueryControl.InnerHtml = scriptValue 12. End If13. objHead.Controls.Add(jQueryControl) 14. End If15. End If16.End SubSample:
Inserting a script file;
1.InjectClientScript(page, "jquery.1.3.2.min.js", "/js/jquery.1.3.2.min.js") Result:
1.<script id="jquery.1.3.2.min.js" type="text/javascript" src="/js/jquery.1.3.2.min.js"></script>Inserting a plain script;
1.InjectClientScript(page, "jQueryNoConflict", "", "jQuery.noConflict();") Result:
1.<script id="jQueryNoConflict" type="text/javascript">jQuery.noConflict();</script>
Comments
Post a Comment