Skip to content

Instantly share code, notes, and snippets.

@monyskynet
Created August 20, 2013 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monyskynet/6288848 to your computer and use it in GitHub Desktop.
Save monyskynet/6288848 to your computer and use it in GitHub Desktop.
Register JavaScript in a page
// Define the name and type of the client script on the page.
String csName = "ButtonClickScript";
Type csType = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the client script is already registered.
if (!cs.IsClientScriptBlockRegistered(csType, csName))
{
System.Text.StringBuilder csText = new System.Text.StringBuilder();
csText.Append("<script type=\"text/javascript\"> { }");
cs.RegisterClientScriptBlock(csType, csName, csText.ToString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment