我想PostBack
Page
手動,但不知何故其不工作。我不知道我在這裏做錯了什麼。我正在使用Jquery對話框並在發回頁面之前放置確認框。這是我的代碼。手動回發不能在asp.net工作
HTML
<form id="form1" runat="server">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<asp:CheckBox ID="cbIsCollected" runat="server" AutoPostBack="false" Checked='<%# MWClickAndCollectHelper.CheckOrderCollectedStatus(AlwaysConvert.ToInt(Eval("OrderId"))) %>'
OnCheckedChanged="cbIsCollected_CheckedChanged" CssClass="isCollectedCheckBox" />
</form>
JAVASCRIPT
var isCollectedCheckBox = $('.isCollectedCheckBox input[type=checkbox]');
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();
}
}
$(isCollectedCheckBox).on("change", function() {
var checked = this.checked;
var checkbox = this;
if (checked) {
checkbox.checked = true;
__doPostBack(checkbox, 'JavaScript');
}
});
代碼隱藏
protected void Page_Load(object sender, EventArgs e)
{
ClientScript.GetPostBackEventReference(this, string.Empty);
string targetCtrl = Page.Request.Params.Get("__EVENTTARGET");
postbackId.Text = targetCtrl ?? "First Time Loaded";
if (!Page.IsPostBack)
{
BindGridView(gvOrders, CNCOrderCollection);
}
}
所以,當我Check
的CheckBox
應該回發到服務器和控件ID名稱應該會出現。但在我的情況下,它總是顯示'首次裝入'。這意味着頁面不會將其識別爲回傳。我想提高服務器端CheckBox_changed
事件。
請幫忙。
http://stackoverflow.com/questions/13475428/asp-net-manual-postback-not-working-from-dynamically-created-linkbutton – 2013-03-05 12:08:35
不應該做的__doPostBack調用是__doPostBack(checkbox.id, '的JavaScript'); ? – jbl 2013-03-05 12:19:56
查看我的編輯。我聲明變量爲'isCollectedCheckBox' – 2013-03-05 12:26:27