Click here to Skip to main content
15,891,409 members
Articles / Web Development

Managing Your JavaScript Library in ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.88/5 (99 votes)
10 Nov 2011CPOL12 min read 414.6K   4.9K   209  
Learn how to embed JavaScript into a DLL, manage dependencies, and avoid page bloat.
Public Class _Default
    Inherits System.Web.UI.Page

    ' Page load occurs before pre-render (the ideal place to exclude JavaScript).
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' We have some third-party control that includes jQuery in a weird way, so we will avoid including it again.
        JavaScriptLibrary.JavaScriptHelper.Exclude_jQuery(Page.ClientScript)
    End Sub

    ' We include our JavaScript during pre-render.
    Protected Overrides Sub OnPreRender(e As System.EventArgs)
        MyBase.OnPreRender(e)
        ' See above comment about excluding jQuery.
        'JavaScriptLibrary.JavaScriptHelper.Include_jQuery(Page)
        JavaScriptLibrary.JavaScriptHelper.Include_GreetUser(Page.ClientScript)
    End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States

  • Managing Your JavaScript Library in ASP.NET (if you work with ASP.net and you don't read that, you are dead to me).
  • Graduated summa cum laude with a BS in Computer Science.
  • Wrote some articles and some tips.
  • DDR ("New high score? What does that mean? Did I break it?"), ping pong, and volleyball enthusiast.
  • Software I have donated to (you should too):

Comments and Discussions