With my javascript getting bigger and bigger, I want to clean up my ASPX File.
The problem is alot of my javascript involves a lot of inline C# calls. ie:
'<%=C# method call)%>'
But this doesn't seem to work when its tucked away in a .js file.
Is there a workaround so I can seperate my javascript into js files?
Certainly you cannot call C# from a .js file. C# code is executed on the server, not on the client. Your .js file is not parsed on the server.
Nothing should prevent you from putting actual JavaScript into a .js file, as opposed to, say, JavaScript that is dynamically emitted by server-side C# code.
If you have a lot of C# code that is generating JavaScript, you can still organize your code by using partial views (that's MVC terminology, but I'm sure there's something similar for standard ASP.Net).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With