I'm working on an ASP.net 3.5 project that has evolved out of a Classic ASP project. We have two old Javascript files that are included in a few pages and have never been updated properly. The Javascript contains ASP.Net server tags and the files are saved with a .js.aspx extension.
The embedded VB.net refers to shared (static) properties in a class and also the ASP.net Session variable. The class in question isn't imported in the Javascript files, so Visual Studio fails to compile the page. However, when you load a page that includes these files, it works fine.
What is the correct way to update these files to .Net standards? Should we avoid having server tags in Javascript files or is there a .Net way to mingle Javascript and server-side code in an includable file?
Thanks.
Edit to answer question:
The file is being included with <!-- #include virtual="myFile.js.aspx" --> inside a script tag. The compiler error is: "Name 'MyClass' is not declared", where MyClass is the class being referenced.
Fully qualify your class , for example if your class is in the namespace
YourCompany.YourApp
then in your .js.aspx file you do YourCompany.YourApp.MyClass
And make sure you have added reference to the DLL where this resides.
Also note that ASP style includes do not work in ASP.Net.