Sunday, August 1, 2010

Open a SharePoint popup after server trip

Last day i had a task in which when user clicks a button few pages got created at runtime and after this i had to show the popup window which will show a aspx page having status of all created pages whether successfully created or failed.

Challenge was to open the popup when button click server trip done (Page rerendered).

My method was creating a javascript at run time to open a popup. But issue was when it runs i gets a javascript error.

"Object Doesn't support this property or method"

Issue was my javascript was getting called even before its supporting js files gets load.

After some rnd i found the solution and here it is.

string strScript = "function OpenDialog() { var option = SP.UI.$create_DialogOptions(); option.url = '" + strPath + "'; option.width = 380; option.height = 330; SP.UI.ModalDialog.showModalDialog(option); } ExecuteOrDelayUntilScriptLoaded(OpenDialog, \"sp.ui.dialog.js\");";

ClientScript.RegisterClientScriptBlock(this.GetType(), "ShowStatusfunction", strScript, true);


Key thing is ExecuteOrDelayUntilScriptLoaded(OpenDialog, \"sp.ui.dialog.js\");";

What it does is, it will wait untill the specified js gets load then it will call the method

Cheers...





No comments: