Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Sunday, 22 June 2014

Define javaScript in Codebehind and Call on Events for SharePoint Modal Dialogbox

commenturl.NavigateUrl = "javascript:ShowPage('" + SPContext.Current.Web.Url + "/SitePages/Sample.aspx?ID=" + id + "')"; ;

 private string GetScript()
        {
            string script = string.Concat("<script type='text/javascript'>",
                            "ExecuteOrDelayUntilScriptLoaded(ShowPage, 'sp.js');",
                            "function ShowPage(URL)        ",
                            " {var options = SP.UI.$create_DialogOptions();",
                        "options.url=URL;",
                        "options.title='Delegate';",
                            "options.autoSize = true;",
                            "options.showClose=true;",
                            "options.allowMaximize=false;",
                            "options.dialogReturnValueCallback= Function.createDelegate(null,DialogCallBack);",
                            "SP.UI.ModalDialog.showModalDialog(options);}",
                            "function DialogCallBack(dialogResult, returnValue) ",
                            "{ if (dialogResult== SP.UI.DialogResult.cancel){",
                                "var notifyId = SP.UI.Notify.addNotification('Message cancelled', false);",
                                "window.location.href='/SitePages/Home.aspx';",
                                "SP.UI.ModalDialog.close(dialogResult);    }",
                                "if (dialogResult== SP.UI.DialogResult.OK)",
                                "{ window.location.href='/SitePages/Home.aspx';",
                                "SP.UI.ModalDialog.close(dialogResult);    ",
                                "}};</script>");
            return script;

        }

Call this script in Page Load:

ScriptManager.RegisterStartupScript(this.Page, GetType(), "popup", GetScript(), false);

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.