Solved

Dialog shows one second and closes immediately

Posted on 2012-03-29
8
1,291 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 500 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
 

Author Comment

by:zhshqzyc
ID: 37784265
Is it equal to return false for my function?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

There is one common problem that all we SharePoint developers share: custom solution deployment. This topic can't be covered fully in this short article, so all I want to do in this one is to review it from a development-to-operations perspectiv…
Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now