User Tools

Site Tools


notes:asp.net:clientscript

ASP.NET ClientScript

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

// Register a JavaScript file Script.js
if (!ClientScript.IsClientScriptIncludeRegistered("MyScript"))
    ClientScript.RegisterClientScriptInclude("MyScript",
        ResolveClientUrl("~/Scripts/Script.js"));
 
// 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/asp.net/clientscript.txt · Last modified: 2020/08/26 (external edit)