Web表单ajax回发对话框endrequest - 源元素null

时间:2015-06-04 05:54:19

标签: javascript jquery asp.net ajax webforms

我继承了一些代码,我似乎无法将其中的一部分工作。 实际上,当按下对话框的ok按钮时,ajaxEndRequest方法中的source元素将返回null。 任何其他按钮,它返回正确的元素(即不是从对话框)。 任何人都可以提供有关如何使其工作的任何提示?请让我知道,如果你有任何问题。 提前致谢。 (另外 - 对于大量的代码感到抱歉 - 我附上了与之相关的任何内容)。

页面加载

protected void Page_Load(object sender, EventArgs e)
{
    this._uiPurchaseOrders.RegisterDoPostBackScript(this);
}

DoPostBack脚本

internal void RegisterDoPostBackScript(Page page)
{
    UpdatePanel linesUpdatePanel = page.Master.FindChildControl<UpdatePanel>("ContentPlaceHolder linesPanel");
    UpdatePanel headerUpdatePanel = page.Master.FindChildControl<UpdatePanel>("ContentPlaceHolder headerPanel");
    string linesUpdatePanelId = linesUpdatePanel != null ? linesUpdatePanel.ClientID : "";
    string headerUpdatePanelId = headerUpdatePanel != null ? headerUpdatePanel.ClientID : "";

    string postBackMethod = String.Format(@"
    function doPostBack(argument, refreshLines, refreshHeader) {{
        var panelsToRefresh = [];
        if (refreshLines) panelsToRefresh.push(""{0}"");
        if (refreshHeader) panelsToRefresh.push(""{1}"");
        Sys.WebForms.PageRequestManager.getInstance().beginAsyncPostBack(panelsToRefresh, ""{2}"", argument, null, null);
    }}", linesUpdatePanelId, headerUpdatePanelId, page.ClientID);

    page.ClientScript.RegisterClientScriptBlock(page.GetType(), "doPostBack", postBackMethod, true);
}

对话HTML

<asp:UpdatePanel runat="server">
    <ContentTemplate>
        <asp:Panel runat="server">
            <asp:Button Text="Receive" runat="server" Width="100" CommandArgument="receive" ID="receiveButton" OnClientClick='<%# "return validateReceipt(\&#39;" + Eval("RowId") + "\&#39;)" %>' />
        </asp:Panel>
    </ContentTemplate>
</asp:UpdatePanel>
<div id="confirmDialog" style="display:none;">
    <br />
    You are over receiving this item. Continue receive?
</div>

的document.ready

$(function () {
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(ajaxPageLoaded);
     Sys.WebForms.PageRequestManager.getInstance().add_endRequest(ajaxEndRequest);
    configureDialog("#confirmDialog", null, 180, "Confirm Received", null, "OK", "Cancel", function (dialogAction) { doPostBack(dialogAction, false, true); });
});

配置对话框

function configureDialog(selector, width, height, title, action, okButton, cancelButton, postbackAction, validationGroup, closeAction) {
    $(selector).dialog({
        autoOpen: false,
        modal: true,
        appendTo: "form",
        title: title,
        close: function (event, ui) {
            var dialogAction = $("#dialogAction").val();
            if (dialogAction != "") {
                postbackAction(dialogAction);
            }
        }
    });

    $(selector).keydown(function (event) {
        if (event.keyCode == 13) {
            $(this).parent().find(".ui-dialog-buttonpane button:eq(0)").trigger("click");
            return false;
        }
    });

    var buttons = {};

    if (okButton != null) {
        buttons[okButton] = function () {
            var isValid = true;

            if (validationGroup != undefined) {
                isValid = performGroupValidation(validationGroup);
            }

            if (isValid) {
                if (action != null) $("#dialogAction").val(action);
                if (closeAction != undefined) closeAction();
                $(this).dialog("close");
            }
        };
    }

    if (cancelButton != null) {
        buttons[cancelButton] = function () {
            if (action != null) $("#dialogAction").val("");
            if (closeAction != undefined) closeAction();
            $(this).dialog("close");
        };
    }

    $(selector).dialog("option", "buttons", buttons);

    if (width != null) {
        $(selector).dialog({
            width: width
        });
    }

    if (height != null) {
        $(selector).dialog({
            height: height
        });
    }
}

对话框打开

function validateReceipt(rowId) {
    var row = $("input[value='" + rowId + "']").closest("tr").next();
    var lineInfo = getLineInfo(row);

    var valid = performGroupValidation(rowId);

    if (valid && (lineInfo.QuantityReceived + lineInfo.ReceiveQuantity  > lineInfo.QuantityOrdered)) {
        $("#confirmDialog").dialog({
            buttons: {
                "OK": {
                    id: "receivePOOK",
                    text: "OK",
                    click: function () {
                        $("#dialogAction").val("receivePO[..]" + rowId);
                        $("#receivedRow").val(rowId);
                        $(this).dialog("close");
                    }
                },
                "Cancel": function () {
                    $("#dialogAction").val("");
                    $(this).dialog("close");
                }
            }
        });

        $("#confirmDialog").dialog("open");
        return false;
    }

    if (valid && !lineInfo.StockDetailsPopulated) {
        $("#newStockDetailsDialog").dialog("open");
        return true;
    }

    return valid;
}

获取源元素

function getSourceElement(sender, args) {
    if (sender._postBackSettings.sourceElement == null) {
        return null;
    }
    else {
        return sender._postBackSettings.sourceElement;
    }
}

EndRequest

function ajaxEndRequest(sender, args) {
    var sourceElement = getSourceElement(sender, args);
    if (sourceElement == null) return;
    var source = $(sourceElement);

    if (sourceElement...) {
        ...
    }
    else if ...
    else if (sourceElement.id == "receivePOOK") {
        // Never gets here, because source element is null
        var rowId = $("input[id*='receivedRow']").val();
        var row = $("input[value='" + rowId + "']").closest("tr").next();
        var parentRow = row.prev();

        var quantityReceived = $(".quantityReceivedField input", row).val();
        $(".lineQuantityReceived", parentRow).html(quantityReceived);
        calculateGrandTotal();

        $("input[id*='receivedRow']").val("");
    }
}

0 个答案:

没有答案