开发者

Inject <script> tag into <head> in code behind

I need to find a global way to inject a <script> tag into my pages directly within the <head> tag from the code behind. I开发者_如何学Pythons there something I can do in the global.asax? If not, all my aspx pages inherit a class I have "BasePage" that implements System.Web.UI.Page.

Basically, I need a way to push jQuery into all of my pages "before" any other scripts (in the HEAD) are referenced.


protected void Application_EndRequest(object sender, EventArgs e)
{
    if (result)
    {
        Page page = HttpContext.Current.CurrentHandler as Page;
        if (page is Page)
        {
            page.ClientScriptManager.RegisterClientScriptBlock(this.GetType(), "HeadScript",
            "<script>alert('error')</script>");
        }
    }
}

Maybe something such as above works for you. Application_EndRequest is defined in Global.asax.


Check this out. It can be adapted to add to a master page too.

http://msdn.microsoft.com/en-us/library/z9h4dk8y.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜