jQuery-UI对话框 [英] jQuery-UI Dialog

查看:63
本文介绍了jQuery-UI对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用来自jquery-ui网站的此代码示例来显示对话框形式. 如何向确定"按钮添加功能.我希望此按钮调用javascript函数"PageValidation",如果返回true,则调用C#函数,该函数会将数据保存在db中,然后关闭模式窗体.如果"PageValidation返回false,则不执行任何操作,并且不关闭模式形式.

I'm using this code sample that came from jquery-ui website to show the dialog form. How can I add functionality to the "OK" button. I want this button to invoke a javascript function "PageValidation", and if it returned true, then call a C# function that will save the data in the db, and then close the modal form. If "PageValidation returned false then do nothing and don't close the modal form.

这是代码:

            $('#dialog').dialog({
                autoOpen: false,
                width: 600,
                buttons: {
                    "Ok": function() { 
                        $(this).dialog("close"); 
                    }, 
                    "Cancel": function() { 
                        $(this).dialog("close"); 
                    } 
                }
            });

谢谢.

推荐答案

您可以将函数添加到确定"函数中,如下所示:

You can add your function in the "OK" function like this:

                "Ok": function() { 
                    MyFunc();
                    $(this).dialog("close"); 
                }, 

然后,编写MyFunc()的主体,如下所示:

then, write the body of MyFunc() , like this:

function MyFunc(){
     if (PageValidation())
           AjaxCSharpCall();
}

并最终编写AjaxCSharpCall()的正文以将ajax请求发送到页面,您可以在其中执行C#函数.像这样的东西:

and finally write the body of AjaxCSharpCall() to send an ajax request to a page, in which you can do your C# function. something like this:

function AjaxCSharpCall()    {
     $.ajax({
       type: "POST",
       url: "MyPage.aspx",
       data: "doFunction=True",
       success: function(){
         alert( "C# Function was executed!" );
       }
     });
}

这篇关于jQuery-UI对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆