How to register a javascript script block in a SharePoint Application Page
Posted by Freelance-Puma 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
Links (10/25/2010) « Everything SharePoint/Silverlight said
[…] How to register a javascript script block in a SharePoint Application Page […]
Blog J.Schweiss | Everything Sharepoint said
[…] How to register a javascript script block in a SharePoint Application Page […]