0

I wanted to know the difference between:

ClientScript.RegisterStartupScript, and ClientScript.RegisterClientScriptBlock

I checked few posts on StackOverflow and came to know about the difference.

I want to know when to use RegisterStartupScript and when to use RegisterClientScriptBlock.

Community
  • 1
  • 1
RKh
  • 13,818
  • 46
  • 152
  • 265

1 Answers1

1

Simple answer: don't use RegisterClientScriptBlock as it's been deprecated.

Ref. MSDN: http://msdn.microsoft.com/en-us/library/system.web.ui.page.registerclientscriptblock(v=vs.110).aspx

As you're probably aware, RegisterClientScriptBlock will be inserted right after the opening tag on your page. Whereas, RegisterStartupScript will be inserted right before the closing tag.

In most cases RegisterClientScriptBlock will work just fine, but if your script relies on any elements on your page you will need to use RegisterStartupScript instead so that the elements exist and can be referenced.

Scotty
  • 1,127
  • 1
  • 7
  • 17