tags:

views:

29

answers:

2

Hi there

Is it safe to include a jQuery script by using the asp.net method ClientScriptManager.RegisterStartupScript ?

http://msdn.microsoft.com/en-us/library/z9h4dk8y.aspx

As example within a Page:

this.ClientScript.RegisterStartupScript(typeof(string), "script1", "$('#test').hide();", true);

Could this cause any issues?

Thanks

+1  A: 

Yes it is safe as the script is added at the end of the page so you may assume that you could manipulate the DOM as it is already loaded and you don't need to wrap your calls in a $(document).ready.

Darin Dimitrov
+1  A: 

It should be ok yes, however your script will not work because you have missed the $ from the start of the statement.

this.ClientScript.RegisterStartupScript(typeof(string), "script1", "$('#test').hide();", true);
redsquare