[英]_doPostBack added twice. one by manual and one by gridview in asp.net
我有一個頁面正在渲染GridView.
在GridView中,我有一個CheckBox
,一旦您check
, uncheck
,就會出現Jquery對話框,並且我需要在該對話框上發回事件。 所以我要在該頁面上添加手動回發。 一切都很好,直到gridview只有1頁。 只要gridview有更多記錄,它就會在頁面上添加_doPostBack方法。 所以我現在在頁面上有一個2 _doPostBack方法,因此沒有任何效果。
如何在我的頁面中定義我不想通過任何控件添加任何_doPostBack方法,因為我已經手動定義了它?
<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&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指向該鏈接
在嘗試彈出一個確認記錄刪除的對話框時,我遇到了類似的問題。 這是我使用的代碼(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()
一起使用的對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.