Thursday, August 2, 2012

Open Modal Dialog In serverside Code in sharepoint 2010

Hi,

When We will  call  SP.UI.ModalDialog.showModalDialog(options) in server side it will throw error "Object does not support this property" because the SP.Js will not get loaded in server side.

Solution;
Use ExecuteOrDelayUntilScriptLoaded method to avoid the error.

Javascript Function in .aspx Page 

 function ShowDialogTest() {
if (confirm('Do u want to continue?')) {
var modalDialog;
var urls = '<%=SPContext.Current.Web.Url %>'
urls = urls + '/_layouts/GetSPUserList/DisplayUser.aspx?caseid=' + document.getElementById('<%=hdnCase.ClientID %>').value;
var options = { showClose: true, };
var options = {
url: urls,
tite: 'Workflow Task',
allowMaximize: false,
showClose: true,
width: 800,
height: 600
};
modalDialog = SP.UI.ModalDialog.showModalDialog(options);
}

}   code behind page Server side code
ScriptManager.RegisterStartupScript(this, this.GetType(), ClientID, "ExecuteOrDelayUntilScriptLoaded(ShowDialogTest, \"SP.js\");", true);

No comments: