I am trying to PostBack the Page manually, BUT somehow its not working. I am not sure what i am doing wrong here. I am using Jquery dialog boxes and putting the confirmation box before posting back the page. here is my code.
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');
}
});
CODE-BEHIND
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);
}
}
So when I Check the CheckBox it should postback to server and the ControlID name should appear. BUT in my case its always shows 'First time Loaded'. that means page does not recognize it as a postback. I want to raise server side CheckBox_changed event.
Please help.