Monday, September 6, 2010

Display Javascript Popup with Server side code in sharepoint 2010

Simple add the below method in your code behind

public void Popup()
{
// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript";

//String csname2 = "ButtonClickScript";
Type cstype = this.GetType();

// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;

// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{

String cstext1 = "alert('Common are u still copying ...!');";

cs.RegisterStartupScript(cstype, csname1, cstext1, true);
}

}