Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Sharepoint publishing page inject javascript through custom Httpmodule

$
0
0

Hi,

I have written one custome Httpmodule to inject few javascript files in to all the pages. This will be used by both Sharepoint and ASP.NET applications.  Below are the events handlers I am using to do this job

public void Init(HttpApplication application)
        {
            application.PostMapRequestHandler += Application_PostMapRequestHandler;
        }

 private void Application_PostMapRequestHandler(object sender, EventArgs e)
        {            
                HttpContext context = ((HttpApplication)sender).Context;
                Page _currentPage = HttpContext.Current.CurrentHandler as Page;
                if (_currentPage != null)
                {
                    _currentPage.PreRenderComplete += OnPreRenderComplete;
                }
        }

void OnPreRenderComplete(object sender, EventArgs e)
        {
                Page _currentPage = (Page)sender;
                ClientScriptManager _clientScriptmanager = _currentPage.ClientScript;

                string _script = "http://cdn/sample.js";
                    _clientScriptmanager.RegisterClientScriptInclude(_currentPage.GetType(), _script, _script);

        }

This working fine everywhere except Publishing pages. "OnPreRenderComplete" event handler is not executed for Sharepoint Publishing Pages.

Please let me know if anyone has any solution for this.

Thanks in advance

Siva


Siva Sankar


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>