Home » How to load client-side scripts in a SharePoint web part

How to load client-side scripts in a SharePoint web part

Here are two approaches to adding client-side scripts to a SharePoint web part.

  1. Load the script immediately after the <form> tag (i.e., at the beginning of the form)
  2. Load the script immediately before the </form> tag (i.e., at the end of the form)

This page has a good description of the difference.

RegisterClientScriptBlockPlaces something like this <script type=’text/javascript’ src=’path/to/script.js’></script> after the open <form> tag and below the view state information.

RegisterStartupScript v1: Places something like this <script type=’text/javascript’ src=’path/to/script.js’></script> before the close </form> tag:

RegisterStartupScript v2: Places something like this <script type=’text/javascript’>hello();</script> before the </form> tag

Calling the client-side script methods:

Leave a Reply

Your email address will not be published. Required fields are marked *

*