Tip & Trick: MasterPage Problems with JavaScript files

 When we Develop web application in all times almost we use sub folders fro different section or modules depends on our architecture and in other hand we use master page to make consistence feel and look for our web site but in this situation we not facing any problem but the problem became when  we want to include JavaScript file in regular way ex:

 

 <script src=”js/Main.js” type=”text/javascript” language=”javascript”></script>

 

we well see that this script works fine in  root folder pages but when we move to pages that contained in sub folder it will run JavaScript exception because file not exist so called scripts not found.  so to solve this problem we just need to simple tweek in out master page code either in Init event or or Load event with following code:

 

Page.ClientScript.RegisterClientScriptInclude(”MyScript”, Request.ApplicationPath + “/js/Main.js”);

 

 Request.ApplicationPath: return web application virtual root  path on the server

 

Thanks Hope this Tip useful and helpful.

 

 

 

تعليقات

ASP NET USer Control #1

When I start work in web application development I Face lot of problems with user controls that can save my time especially when I can’t pay lot of money for commercial one so I decide to develop my own package and put some of as free component on my web blog starting with this ASP .NET Date Picker user control, which I hope you like it.

 

Download:date-picker-uc.zip

تعليقات