Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

making an inline C# call in external Javascript file

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?

like image 327
Michael Avatar asked Apr 30 '26 21:04

Michael


1 Answers

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).

like image 159
Eric J. Avatar answered May 03 '26 12:05

Eric J.