asp.net - How2: what event to hook in HttpModule for putting js links into head element -


I have to do HTML modules to inject javascript elements, CSS links into head elements, with some simple config data. I'm not sure what event I want to hook up?

I use maliciously - context. Reversionary handler for dynamically changing the masterpiece Examinations - References for SEO optimization

Thanks for any tip, Cheers, X.

Here's what I did without the HTML module. I did not like the httpmodule idea because if I forgot to register it and it was not working then my app would not work and this would not be a clear bug. The page requires a complete JS, so I decided to put it into the base page class of the project.

I had applied earlier this year, and wanted to be able to include more than just scripts, it supports CSS, Meta tags etc. I forgot why I used the page. Control. Just add it instead of the page. Client script. Registry client script included but there was a reason.

 using the  system; Using System.Collections.Generic; Using System.Web; Using System.Web.UI; Namespace Your Namespace {Public category headers included manager {Private list & lt; String & gt; M_IncludedFiles = New list & lt; String & gt; (); Public Zero IncludeScript (strings) {IncludeScript (s, null); } Public Bull isIncluded (string file) {returns (m_IncludedFiles.Find (s = & gt; s.Equals (File, String Communications, Inventory Child Ignore Case)) = Null;} Public Zero IncludeScript (string script, string condition) { Page page = http; current page as current page; if (include! (Script) || page == faucet; return; string script file = string.format ("/ {0} / {1}? V = {2} ", Mac .J.S.DIR, SQL Ripte, M.InfoBilderNumber); if (page header! = Null) {string scriptTag = String.Format ("& lt; script language = \" javascript \ "type = \" text / javascript \ "src = \" { 0} \ "& gt; & lt; / script & gt; \ n", scriptfile); if (! String.IsNullOrEmpty (condition) scriptTag = String.Format ("& lt;! - [[0}] & Gt; Lit Language = \ "javascript \" type = \ "text / javascript \" src = \ "{1} \" & gt; & lt; / script & gt; & lt ;! [AndIf] - & gt; \ N ", condition, scriptfile); page header.add control (new literal control (script tag)); m_IncludedFiles.Add (script); } And if the (include the Client script.is ClientScript Script (GetType (), scriptfile)) {page.ClientScript.RegisterClientScriptInclude (GetType (), scriptfile, scriptfile); M_IncludedFiles.Add (script); }} Public Zero IncludeCss (String CSS) {page of page = html consoles. Present. Current handles as page; If (include! (CSS) || page == faucet) return; String cssfile = string.format ("/ {0} / {1}? V = {2}", MyConfig.CssDir, css, MyConfig.BuildNumber); If (page header! = Null) {(HTTP Consort .content.contentahandler) .Header.Controls.Add (New Literal Control (string.format (" \ n ", cssfile))); M_IncludedFiles.Add (CSS); }} Include Public Zero JQuery () {IncludeScript ("jquery-1.2.3.min.js"); } Include Public Zero JQueryUI () {JQuery (Include); IncludeScript ("jquery.ui.1.0.min.js"); IncludeCss ("jQuery-theme.css"); } Include Public Zero; Flotogon () {JQuery (Include); IncludeScript ("flot / jquery.flot.js"); IncludeScript ("flot / excanvas.pack.js", "if IE"); }} Public class MyPage: Pages {include the header header included in the public header = new headers manager (); } Public class MyControl: UserControl {public new MyPage page {get {return (MyPage) base.Page; }}} Public class SomeControlThatNeedsScripts: MyControl {Secure Override Zero OnLoad (EventArgs e) {Page.HeaderIncludes.IncludeJQueryUI (); Base.OnLoad (E); }}}  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -