我有一个在GridView中渲染GridView.的页面,我有一个CheckBox,一旦你check,uncheck,Jquery对话框出现,我需要在该对话框上回发事件。因此,我在该页面上添加了一个手动回发。一切都很好,直到gridview只有一页。一旦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&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中只有1个页面时,我在jquery对话框中的事件无法工作,因为它找不到_doPostBack。
答案:
我删除了我添加的_doPostBack(),并将其添加到我的Page_Load()中,该方法添加了一个_doPostBack(),即使没有需要此方法的asp.net控件也是如此。
ClientScript.GetPostBackEventReference(this, string.Empty);非常感谢@Tim Schmelter指出了这个链接
发布于 2013-07-23 18:18:13
当我试图弹出一个确认删除记录的对话框时,我也遇到了类似的问题。这是我用过的代码(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()中使用的对象。
https://stackoverflow.com/questions/17807194
复制相似问题