Solved

Dialog shows one second and closes immediately

Posted on 2012-03-29
8
1,327 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

I have just recently built a new SharePoint 2007 farm on a complete Windows 2008 R2 server platform and part of my standard build procedure is to implement a warm up routine, usually in the form of a script that is scheduled every morning to launch …
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

21 Experts available now in Live!

Get 1:1 Help Now