views:

54

answers:

1

I would like to know what are the best practices in using Javascript in ASP.NET in a pre-AJAX and pre-jQuery era. What I meant by pre-era is not the time before AJAX/jQuery was created, but rather the time before it is popularized and widely adopted (by a significantly large number of programmers).

i.e. Is it good thing to store the script in a string variable and register it on demand (RegisterClientScriptBlock) or on startup (RegisterStartUpScript)?

Although I would be happy to see answers in using Javascript in ASP.NET, its usage in PHP and JSP are also welcome.

Thanks in advance for your time and expertise.

A: 

I have always been an opponent of the RegisterClientScriptBlock methods and object structure. When you use these methods, your JavaScript is injected into the page at the behest of the page controls. This means it could end up being output in very specific positions and not necessarily in the order desired.

My JavaScript methods are always external to the page, typically in a separate file. When needed I use a literal control to output JavaScript assignment objects (to let the scripts know what any pertinent ClientIDs might be for accessing fields.

Joel Etherton