Dialog shows one second and closes immediately

Posted on 2012-03-29
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()">
            <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";



Open in new window

Question by:zhshqzyc
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3

Expert Comment

ID: 37781583
It is probably closing because of a post back.  Check out ajax tools,,  and the modal popup.  There is an example on the page too.  You may want to put it into an updatepanel.

Author Comment

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

Accepted Solution

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) {
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.


Author Comment

ID: 37784265
Is it equal to return false for my function?

Expert Comment

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;"

Author Comment

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.

Expert Comment

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

Author Closing Comment

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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