none
Modal dialog box, opens then closes

    Question

  • HI Everyone,

    I am currently stuck on the following,

    I am trying to open a modal dialog, but it closes immediately after being opened.

    Can anyone please assist.

    My code:

    function ShowDialog(url) {
        ExecuteOrDelayUntilScriptLoaded(ShowDialog, "sp.ui.js "); 
            var options = SP.UI.$create_DialogOptions(); 
            options.url = url;
            options.width = 300;
            options.height = 400;
            options.dialogReturnValueCallback = Function.createDelegate(
                        null, portal_modalDialogClosedCallback);
            SP.UI.ModalDialog.showModalDialog(options);
        }
    
        function portal_modalDialogClosedCallback(result, value) {
            if (value == '1') {
                this.statusId = SP.UI
                .Status
                .addStatus("Tweet Posted",
                   "Your tweet has been posted",
                    true);
                SP.UI.Status.setStatusPriColor(this.statusId, "Green");
            }
    
            if (value == '0') {
                this.statusId = SP.UI
                .Status
                .addStatus("Tweet Failed",
                    "Your tweet has not been posted.",
                    true);
                SP.UI.Status.setStatusPriColor(this.statusId, "Green");
            }
    
            setTimeout(RemoveStatus, 6000);
        }
    
        function RemoveStatus() {
            SP.UI.Status.removeStatus(this.statusId);
        }

    Button btnTweet = new Button { Text = "Tweet", CssClass = "tdTweet" };
                    btnTweet.OnClientClick = string.Concat("ShowDialog('", PageUrl, "')");

    Any ideas please

    Thursday, November 29, 2012 6:30 AM

Answers

  • I figured it out.

    string sscripts = @"function ShowDialog() {
                                    var options = SP.UI.$create_DialogOptions();
                                    options.url = 'http://www.google.com';
                                    options.width = 500;
                                    options.height = 450;


                                    SP.UI.ModalDialog.showModalDialog(options);
                                }";

                System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, this.GetType(),
                 "createfunc", sscripts, true);

                System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, this.GetType(),
                 "OpenWindow", "ExecuteOrDelayUntilScriptLoaded(ShowDialog, 'sp.js');", true);


    • Marked as answer by JPRoelofse Friday, November 30, 2012 9:56 AM
    Friday, November 30, 2012 8:13 AM

All replies

  • Hi Everyone,

    I changed my code to the follow, it work but not like i want.

    Can anyone please assist.

    Hi,

    Can anyone please assist me with the following.

    See the code below:

    <script language="javascript" type="text/javascript">

        ExecuteOrDelayUntilScriptLoaded(ShowDialog, 'sp.js');

        function ShowDialog() {

            var options = SP.UI.$create_DialogOptions();

            options.url = 'http://sp_server/PageHolder/WickedTweetInsert.aspx';

            options.width = 500;

            options.height = 450;

            SP.UI.ModalDialog.showModalDialog(options);

        }

    </script>

    <table>

        <tr>

            <td>

                <asp:Button ID="btnTweet" runat="server" Text="Tweet" OnClientClick="ExecuteOrDelayUntilScriptLoaded(ShowDialog, 'sp.js');" />

            </td>

        </tr>

    </table>

    I Need to call this function “ExecuteOrDelayUntilScriptLoaded(ShowDialog, 'sp.js');” for my code to work. It works if it is directly on the page, but the problem with this is that it will load everytime the page loads, I just want it on the button click. But the code for the button click does not work.

    Any Ideas?

    Friday, November 30, 2012 4:47 AM
  • I figured it out.

    string sscripts = @"function ShowDialog() {
                                    var options = SP.UI.$create_DialogOptions();
                                    options.url = 'http://www.google.com';
                                    options.width = 500;
                                    options.height = 450;


                                    SP.UI.ModalDialog.showModalDialog(options);
                                }";

                System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, this.GetType(),
                 "createfunc", sscripts, true);

                System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, this.GetType(),
                 "OpenWindow", "ExecuteOrDelayUntilScriptLoaded(ShowDialog, 'sp.js');", true);


    • Marked as answer by JPRoelofse Friday, November 30, 2012 9:56 AM
    Friday, November 30, 2012 8:13 AM