?
Solved

Dialog shows one second and closes immediately

Posted on 2012-03-29
8
Medium Priority
?
1,602 Views
Last Modified: 2012-04-04
Hello, I am using SP.UI.ModalDialog.showModalDialog. The question is that it pops out and closes immediately.

What I want is I can control the form. I can add buttons on the form. Clicking "Submit" or "Close" it to complete some kind of tasks.
 <asp:Button ID="Edit" runat="server" Text="Edit" OnClientClick="javascript:Edit_Click()">
               
            </asp:Button> 
            <script type="text/javascript">
                              function Edit_Click() {
                                  var options = SP.UI.$create_DialogOptions();

                                  options.title = "My Dialog Title";
                                  options.width = 400;
                                  options.height = 600;
                                  options.url = "/_layouts/test.aspx";
                                  options.showClose=true;
                                  SP.UI.ModalDialog.showModalDialog(options);


                              };

                </script>

Open in new window

0
Comment
Question by:zhshqzyc
  • 4
  • 3
8 Comments
 
LVL 9

Expert Comment

by:BlueYonder
ID: 37781583
It is probably closing because of a post back.  Check out ajax tools, http://www.asp.net/ajaxlibrary/download.ashx,  and the modal popup.  There is an example on the page too.  You may want to put it into an updatepanel.
0
 

Author Comment

by:zhshqzyc
ID: 37781600
No, I did't use ajax at all . SP.UI.ModalDialog.showModalDialog is the new feature of SharePoint 2010.
0
 
LVL 2

Accepted Solution

by:
echefjosef earned 1500 total points
ID: 37782349
It is probably because you do not have a dialogReturnValueCallback specificed in your options.  This is the delegate that gets called on dialog close for refreshes, redirects, validatation, etc.  If you don't need to do any of this, then try adding this to your options array:

dialogReturnValueCallback: DialogCallback

Then add this in your script block:

function DialogCallback(dialogResult, returnValue) {
      //Receiver
}
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:zhshqzyc
ID: 37784265
Is it equal to return false for my function?
0
 
LVL 2

Expert Comment

by:echefjosef
ID: 37784282
No... Your function just does an unstated "return", so no value is actually passed back.  With the callback function, the close of the modal window will execute it.  It has no logic or return values either, so will just "return;" as well, rather than "return false;"
0
 

Author Comment

by:zhshqzyc
ID: 37784307
Can we use
<asp:Button ID="Edit" runat="server" Text="Edit" OnClientClick="javascript:Edit_Click(); return false;" />

Open in new window

to prevent postback?
Because it works out.
0
 
LVL 2

Expert Comment

by:echefjosef
ID: 37784402
I don't believe that would cause any issues at all... :)
0
 

Author Closing Comment

by:zhshqzyc
ID: 37806419
Maybe this is true.
But when I added return:false, It was working.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft SharePoint Foundation 2010 and Microsoft SharePoint Server 2010 do not offer the option to configure the location of the SharePoint diagnostic trace log files during installation.  This can, however, be configured through Central Administr…
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question