【问题标题】:asp.net jquery trigger c# function on click at modal formasp.net jquery 在模态表单上单击时触发 c# 函数
【发布时间】:2015-11-16 12:54:55
【问题描述】:

我正在尝试将数据从模态表单获取到父表单,但我无法做到。我正在使用 webusercontrol 创建 jquery 模态表单并在 gridview 中显示数据。我想获取选定的行并将其添加到我父表单的网格中。 我正在使用此代码创建我的对话框表单

function dialogAc(ID1) {
    $.ajax({
        type: 'POST',
        url: '<%= ResolveUrl("/faturaIrsaliye/FaturaKaydet.aspx/abc") %>',
        data: "{ID1:'" + ID1 + "' }",
        dataType: 'json',
        async: true,
        cache: false,
        contentType: 'application/json; charset=utf-8',
        success: function (msg) {
            $("#IrsaliyeDetay").append(msg.d);
        },
        failure: function (msg) {
            alert("Error");
        }
    });
    ID11 = ID1;
    $("#dialog-form").dialog("open");
}

这是我的创作方法。

[WebMethod]
        public static string abc(String ID1)
        {
            string sonuc = "";
            Page p = new Page();
            UserControl u =  (UserControl)p.LoadControl("~/faturaIrsaliye/WebUserControl1.ascx");
            WebUserControl1 kk = (u as WebUserControl1);
            kk.irsaliyeBaslikID = ID1.toInt();
            p.Controls.Add(u);
            StringWriter sw = new StringWriter();
            HttpContext.Current.Server.Execute(p, sw, false);
            sonuc = sw.ToString();
            sw.Close();
            return sonuc;
        }

到目前为止一切都很好。 最后一个代码不会触发我的其他方法。我收到 404 not found 错误。

$(function () {
    $("#dialog-form").dialog({
        autoOpen: false,
        height: 500,
        width: 800,
        modal: true,
        buttons: [{
            text: "Select",
            click: function () {
                $.ajax({
                    type: 'POST',
                    url: '<%= ResolveUrl("/faturaIrsaliye/WebUserControl1.ascx/abc") %>',
                    data: "{}",
                    contentType: 'application/json; charset=utf-8',
                    dataType: 'json',
                    success: function (result) {
                        $('#sonuc').html(result.d);
                        alert("clicked");
                    },
                    error: function (response) {
                        alert(response.status + ' ' + response.statusText);
                    }
                });
            },
        }, {
            text: "Close",
            click: function () {
                $(this).dialog('close');
                //window.location.reload(true);
                return false;

            }
        }

        ]
    });
});

【问题讨论】:

    标签: c# jquery asp.net asp.net-ajax


    【解决方案1】:

    ResolveUrl 需要一个相对 URL,例如

    ResolveUrl("~/faturaIrsaliye/WebUserControl1.ascx/abc")
    

    【讨论】:

    • 我之前确实尝试过,但没有成功。我发现了问题。如果我在 aspx 文件中调用的方法有效,但如果它在 ascx 文件中,则返回 404 not found 错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-23
    • 2014-04-28
    • 1970-01-01
    • 2016-02-26
    • 2013-12-05
    • 2017-01-06
    • 1970-01-01
    相关资源
    最近更新 更多