Skip to main content

Posts

Showing posts with the label client script

Register client side scripts in code behind

Quick way to register client side scripts.     Let us take the css files first: CssLink cssLink = new CssLink (); cssLink . DefaultUrl = "/_layouts/appname/cssfiletoregister.css" ; this . Page . Header . Controls . Add ( cssLink );     string scriptPath = "/_layouts/appname/jstoregister.js" ; if (! this . Page . ClientScript . IsClientScriptBlockRegistered ( scriptPath )) this . Page . ClientScript . RegisterClientScriptBlock ( this . GetType (), scriptPath , "

Create a jQuery alert programmatically

From the code behind:   Assuming you have jquery on your page already.   StringBuilder  strScriptFeatured =  new   StringBuilder (); strScriptFeatured.Append( "$(document).ready(function(){" ); strScriptFeatured.Append( "alert('Your alert here!');" ); strScriptFeatured.Append( "});" ); Page.ClientScript.RegisterStartupScript( this .GetType(),  "Script" , strScriptFeatured.ToString(),  true );   QED  

Add Client Script to codebehind c# ASP.NET

To register a js file in the codebehind - just use the "ClientScript.RegisterClientScriptInclude" Page.ClientScript.RegisterClientScriptInclude("blockui", string.Format("{0}/{1}", SPContext.Current.Site.RootWeb.Url.ToString(), "Style%20Library/PitchIn/Scripts/jquery.blockUI.js")); To add script tags, then build the string and pass the value: string loadingimage = @" "; Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "loadingimg", loadingimage, false);