1

我在下面创建了一个 JQuery UI 按钮。有没有办法添加某种类型的事件导向器,以便当我单击按钮时,我的 vb.net 函数之一在我的 .aspx.vb 文件中被调用?

谢谢

$("#editor-form").dialog({
            autoOpen: false,
            height: 400,
            width: 650,
            modal: true,
            buttons: {
                "Add Editor": function () {
                 //fire serverside event??

我尝试添加它,但它不起作用......没有错误,只是不起作用。

                   $.ajax({
                        type: "POST",
                        url: "CreateTest.aspx/btnAddEditors_Click",
                        //data: "{subject:'" + subject + "',message:'" + message + ",messageId:'" + messageId + "',pupilId:'" + pupilId + "'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (msg) {
                            // Do something interesting here.
                        }
4

1 回答 1

2

在下面的示例中,我有一个对话框,在对话框中我有一个名为更新页面的按钮,单击该按钮将通过 POST 在服务器上执行一个方法

发布示例

    var runDates = "Pages/Mobile/Login.aspx/LoginUser";

    function initDailog() {

        RunDialog = $("#runDatestreeview").dialog({ closeOnEscape: true, stack: false, autoOpen: true,
            modal: false, resizable: true, draggable: true, title: 'Select Run Dates to Auto-Populate Form Fields & Test Exceptions:',
            width: 600, height: 500, position: 'center',
            open: function (type, data) {
                originalContent = $("#treeview").html();
            },
            buttons: { UpdatePage: function () {
                $.post(runDatesUrl,
//the following line sends my entire form or you could send individual values to the server
              $("#form").serialize(),
               function (data) {
                   This is your success function
                   //In my case the server was sending updated data to re-fresh my form fields
                   //so I update my div with the new results/content
                    $("#main").html(data);
                              }, "html");
            },
                Cancel: function () {
                    $(this).dialog("close");
                  }
            }
        });
    }

.加载示例

除了 POST,您还可以对空 div 执行 .LOAD

$("#yourDivNameHere").load(UR, { ID: $("#ID").val(), ErrorCodes: errorTextArea });

编辑

假设您在服务器端代码隐藏文件中有以下方法:

 public static bool AddNewItem(string name, string surname, int age)
    {


      return true;      
    }

现在在帖子中:

buttons:
{
    "Add": function () {
        var name = $("#<%= txtName.ClientID  %>").val();
        var surname = $("#<%= txtSurname.ClientID %>").val();
        var age = $("#<%= txtAge.ClientID %>").val();

        $.ajax({
            type: 'POST',
            url: 'MyWebPage.aspx/AddNewItem',
            data: '{"name":"' + name + '", "surname":"' + surname + '", "age":' + age + '}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                if (msg.d) {
                    alert("Successfully added new item");                                    
                }
            },
            error: function () {
                alert("Error! Try again...");
            }
        });
    },
    "Cancel": function () {
        $(this).dialog("close");
    }
}
于 2013-01-14T21:34:40.010 回答