Skip to main content

Posts

Showing posts with the label javascript

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 mailto htm with no character limit.

The HTML standard for the mailto link is 256 characters. You can get around this by loading the JavaScript redirect instead. var  body = escape(window.document.title + String.fromCharCode(13) + window.location.href + " actully  a Your long text here..." ); body = body.replace( /\//g ,  "%2F" ); body = body.replace( /\?/g ,  "%3F" ); body = body.replace( /=/g ,  "%3D" ); body = body.replace( /&/g ,  "%26" ); body = body.replace( /@/g ,  "%40" ); var  subject =  "Take a look at this!" ; window.location.href =  "mailto:?body="  + body +  "&subject="  + subject;

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);