0

我有一个页面,我正在渲染GridView.在 GridView 中,我有一个CheckBox,一旦你check,,uncheckJquery 对话框出现,我需要在该对话框上的回发事件。所以我在该页面上添加了手动回发。一切都很好,直到 gridview 只有 1 页。一旦 gridview 有更多记录,它就会在页面上添加一个 _doPostBack 方法。所以我现在在页面上有一个 2 _doPostBack 方法,因此没有任何效果。

我如何在我的页面中定义我不想通过任何控件添加任何 _doPostBack 方法,因为我已经手动定义了它?

这是我的 HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
    <title>Store Management</title>
    <script src="/js/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="/js/jquery-ui.min-1.10.1.js" type="text/javascript"></script>
    <link href="/assets/styles/StorePortal/style-22012013.css" rel="stylesheet"
    type="text/css" />
    <link href="/assets/styles/StorePortal/jquery-ui.css" rel="stylesheet"
    type="text/css" />
    <link href="../App_Themes/AbleCommerce/ComponentArt.css" rel="stylesheet"
    type="text/css" />
    <link href="../App_Themes/AbleCommerce/print.css" rel="stylesheet" type=
    "text/css" />
    <link href="../App_Themes/AbleCommerce/style.css" rel="stylesheet" type=
    "text/css" />
    <link href="../App_Themes/AbleCommerce/webparts.css" rel="stylesheet" type=
    "text/css" />
</head>

<body>
    <form action=
    "portal.aspx?q=bbaae796d951c95311f5ec3e599784079c6093ee&amp;q1=COV" id=
    "form1" method="post" name="form1">
        <div>
            <input id="__EVENTTARGET" name="__EVENTTARGET" type="hidden" value=
            "" /> <input id="__EVENTARGUMENT" name="__EVENTARGUMENT" type=
            "hidden" value="" />
        </div><script type="text/javascript">
//<![CDATA[
        var theForm = document.forms['form1'];
        if (!theForm) {
        theForm = document.form1;
        }
        function __doPostBack(eventTarget, eventArgument) {
        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
        }
        }
        //]]>
        </script>

        <div>
            <input id="__VIEWSTATEENCRYPTED" name="__VIEWSTATEENCRYPTED" type=
            "hidden" value="" />
        </div>
      <script type="text/javascript"> --> this one is added by me manually
//<![CDATA[
        var theForm = document.forms['form1'];
        if (!theForm) {
            theForm = document.form1;
        }
        function __doPostBack(eventTarget, eventArgument) {
            if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
                theForm.__EVENTTARGET.value = eventTarget;
                theForm.__EVENTARGUMENT.value = eventArgument;
                theForm.submit();
            }
        }
        //]]>
        </script>

        <div>
            <input id="__EVENTTARGET" name="__EVENTTARGET" type="hidden" value=
            "" /> <input id="__EVENTARGUMENT" name="__EVENTARGUMENT" type=
            "hidden" value="" /> /// sOME CODE HERE
        </div>
     --> this one is added by me manually
    </form>
</body>
</html>

现在,如果我删除了我添加的 _doPostBack,gridview 分页就可以工作了。但是当我在gridview 中只有一页时,我在jquery 对话框中的事件不起作用,因为它找不到_doPostBack。

回答:

我已经删除了我添加的 _doPostBack(),而是在我的 Page_Load() 上添加了它,即使没有需要此方法的 asp.net 控件,它也会添加 _doPostBack()。

ClientScript.GetPostBackEventReference(this, string.Empty);

非常感谢@Tim Schmelter 指向该链接

4

1 回答 1

1

在尝试弹出确认删除记录的对话框时,我遇到了类似的问题。这是我使用的代码(jQuery UI 对话框),它运行良好。不要添加新的doPostBack. 相反,尝试遵循这个想法。您可以对其进行调整以满足您的要求:

// When the user tries to delete a record, show a confirmation.
$(".confirmationButton").click(function(e) {
    // Stop the PostBack
    e.preventDefault();

    $(".confirmationDialog").dialog("open");
}); 

$(".confirmationDialog").dialog({
    buttons: {
    "No": function() {
        $(this).dialog("close");
    },
    "Yes": function() {
        $(this).dialog("close");
            // User confirmed deletion, so carry on with the PostBack.
            eval($("#ctl00_MainContentPlaceHolder_hdnBtnPostBack").val());
        }
    }
});

在您的代码某处(检查页面源代码时),您会发现如下内容:

<input id="ctl00_MainContentPlaceHolder_hdnBtnPostBack" type="hidden" value="__doPostBack('ctl00$MainContentPlaceHolder$btnDelete','')" name="ctl00$MainContentPlaceHolder$hdnBtnPostBack">

这就是您将使用的对象eval()

于 2013-07-23T10:18:12.780 回答