javascript - Web forms ajax postback dialog endrequest - source element null -
i've inherited code, , can't seem part of working. source element in ajaxendrequest method coming null when ok button of dialog pushed. other button, , comes correct element (i.e. not dialog). can offer hints on how working? please let me know if have questions. in advance. (also - sorry mountains of code - i've attached thats relevant it).
page load
protected void page_load(object sender, eventargs e) { this._uipurchaseorders.registerdopostbackscript(this); }
dopostback script
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); }
dialog 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(\'" + eval("rowid") + "\')" %>' /> </asp:panel> </contenttemplate> </asp:updatepanel> <div id="confirmdialog" style="display:none;"> <br /> on receiving 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); }); });
configure dialog
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 }); } }
dialog opening
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; }
get source element
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 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(""); } }
Comments
Post a Comment