Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Hi,
I was trying to learn client side scripting from
http://msdn.microsoft.com/en-us/library/aa479302.aspx[^]

what i don't understand is why we are writing these java script functions on a class file rather than a .js file.

i was thinking its easy to add the .js file into src attribute of your page or directly incorporate into your project so that we can access the functions from the code behind.

How does the JavaScript gets added in real life project(both in normal web-application and AJAX enable ones)?

Please advise ..there is too much information in web for a beginner to get confused where to start practicing.
Posted
Updated 26-May-11 8:32am
v3

You can certainly write Javascript statically in a *.JS file or write it embedded in HTML file.

Javascript is a part of HTML page generated by APS.NET on the fly exactly as anything else. You parametrize part of your HTML output by inserting the values generated by the code behind. Exactly in the same way you can parametrize the part of your Javascript code: this is the way to insert the result of code behind in the Javascript code. If you don't need it, write a static *.JS file, why not?

—SA
 
Share this answer
 
Comments
AspDotNetDev 26-May-11 13:42pm    
It just so happens that I recently wrote an article on just this topic. See my answer.
thatraja 26-May-11 14:20pm    
Fine 5!
Sergey Alexandrovich Kryukov 26-May-11 14:33pm    
Thank you, Raja.
--SA
Manfred Rudolf Bihy 26-May-11 15:49pm    
So it is! 5+
Sergey Alexandrovich Kryukov 26-May-11 15:51pm    
Thank you, Manfred.
How do you like the new article by AspDotNetDev (I voted for, see his answer)?
--SA
Read Managing Your JavaScript Library in ASP.NET. That will give you some solid pointers on how you should be including JavaScript in your ASP.NET applications. Basically, you should normally not include JavaScript as strings in your code behind. Instead, you can embed a .JS file into a DLL and insert a script reference (src="....") into your page that loads that JavaScript from the DLL.
 
Share this answer
 
Comments
thatraja 26-May-11 14:20pm    
Spot on. 5!
Sergey Alexandrovich Kryukov 26-May-11 14:35pm    
I'll check you article later. At first glance it looks like a mature approach and techniques. Thank you for notifying me. My 5 for the answer.
--SA
Manfred Rudolf Bihy 26-May-11 15:47pm    
I'll chime in and add my 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900