Thursday, April 10, 2008

Include files (.js, .css) in master pages or base page

We always use master page and basepage implementation for our asp.net projects.

Even after master pages were introduced in VS2005, i continued using basepage.vb file which inherits from system.web.ui.page. I inherit this in all my pages. Its just that I found more flexibility and control by using basepages and master page. basepage contains all the codes that need to fired for each page like authentication, validations etc,. and the masterpage just contains the UI framework ..

anyway, maybe I can explain my reasons for this implementation in some other post .. let me continue with the reason for this post .. Now there was this requirement to inlude some common .js files in all my webpages. I thought I could do this in master page. But it did not work ..

so finally I got it to work using this statement in the load of my basepage.vb class.

MyBase.ClientScript.RegisterClientScriptInclude("CommonJS", "~/Common/Scripts/Common.js")

where Common.js resides in the Root\Scripts directory of the project ..

No comments:

Post a Comment