views:

792

answers:

3

Using RegisterClientScriptBlock I reduce server requests. But with RegisterClientScriptInclude I can separate HTML and javascript.

Which method should I prefer?

EDIT: Additional question - where do you store your js blocks. I get used to place them into resources files.

A: 

Use which method most serves your needs at the time. I don't think there's a rule that says you must choose one or the other for every single possibility.

TheTXI
+2  A: 

The RegisterClientScriptBlock method is handy if you want to modify the script somehow.

If you can have the script as a static file to include I would recommend that, as the browser would cache the file so that it would only be requested the first time that it's used. Given that the script is more than just a few lines, of course.

Guffa
A: 

Both functions should be used as last resort for JS. Best way to store and attach your JavaScript to the site is to use static linking.

Migol