Dialog shows one second and closes immediately

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

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
zhshqzycAuthor Commented:
No, I did't use ajax at all . SP.UI.ModalDialog.showModalDialog is the new feature of SharePoint 2010.
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) {

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

zhshqzycAuthor Commented:
Is it equal to return false for my function?
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;"
zhshqzycAuthor Commented:
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.
I don't believe that would cause any issues at all... :)
zhshqzycAuthor Commented:
Maybe this is true.
But when I added return:false, It was working.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SharePoint

From novice to tech pro — start learning today.