User Tools

Site Tools

ASP.NET ClientScript

A few examples of registering JavaScript code using the ClientScript class:

// Register a JavaScript file Script.js
if (!ClientScript.IsClientScriptIncludeRegistered("MyScript"))
// Ragister a JavaScript code block.
if (!ClientScript.IsClientScriptBlockRegistered("MyCode"))
    ClientScript.RegisterClientScriptBlock(this.GetType(), "MyCode",
        "<script language='JavaScript'> /* some js code here */ </script>");
// Ragister a JavaScript startup code block. This code will be inserted at the end of the page
// after all HTML controls are in place. 
if (!ClientScript.IsStartupScriptRegistered("MyStartupCode"))
    ClientScript.RegisterStartupScript(this.GetType(), "MyStartupCode",
        "<script language='JavaScript'> /* some startup js code here */ </script>");
notes/ · Last modified: 2020/08/26 (external edit)