[ROYALINE’s] SharePoint Dynamics

SharePoint Development & Techniques

How to register a javascript script block in a SharePoint Application Page

Posted by Royaline on September 29, 2010


Since a SharePoint application page references a master page file, all javascript needs to reside in the master page. However, when creating an application page to be used within your SharePoint environment, you’ll need to register a client script block.

To do so, add your own variation of javascript within the Page_Load() method of the aspx page that references a master page file:

<script runat="server" language="c#">
    private void Page_Load()
    {
        string myScript = string.Empty;
        myScript += "var showRow= true;";
        myScript += "function toggle(myTable) {";
        myScript += "  myTable.style.display = '';";
        myScript += "  var myTableRows = myTable.rows;";
        myScript += "  for (i = 0; i < myTableRows .length; i++) {";
        myScript += "    if (myTableRows [i].className != 'ChildGridHeaderRow') {";
        myScript += "      myTableRows [i].style.display = (showRow) ? 'none' : '';";
        myScript += "    }";
        myScript += "  }";        
        myScript += "  showRow = !showRow;";
        myScript += "}";
        
        ClientScript.RegisterClientScriptBlock(this.GetType(), "MyOwnJavascriptTitle", myScript, true);
    } 
</script>

END

Advertisements

2 Responses to “How to register a javascript script block in a SharePoint Application Page”

  1. […] How to register a javascript script block in a SharePoint Application Page […]

  2. […] How to register a javascript script block in a SharePoint Application Page […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: