jeudi 2 mars 2017

Checkbox Check changed event firing twice C#

I have a listview with checkbox. According to my requirement I uncheck through javascript. But because of that script my Checkchanged event fires twice and returns the previous unchecked(through javascript) value for the second time fires. I am not sure why is it happening when using script. Please find the code below

JavaScript

function CallConfirmBox() {
    alert("456");
    if (confirm('Schedule more than one time slot for the same day will overwrite the file')) {
        return true;
    }
    else {
        var id = document.getElementById('<%= hdnValue.ClientID%>').value;
        alert(id);
        $('#' + id).attr('checked', false);
        alert("123")
        id = "";
        return false;
    }
}

CodeBehind

protected void chkCheck_CheckedChanged(object sender, EventArgs e)
    {
        CheckBox chkCheck = (CheckBox)sender;
        ListViewItem item = (ListViewItem)chkCheck.NamingContainer;
        ListViewDataItem dataItem = (ListViewDataItem)item;
        string lookupId = lvLookup.DataKeys[dataItem.DisplayIndex].Value.ToString();
        hdnValue.Value = chkCheck.ClientID;
        if (lookupMstVal == "ScheduledTime." && lbCheckedIdList.Items.Count > 0 && chkCheck.Checked)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "CallConfirmBox", "CallConfirmBox();", true);//" + chkCheck.ClientID + "
        }

        if (chkCheck.Checked)
            lbCheckedIdList.Items.Add(lookupId);
        else
            lbCheckedIdList.Items.Remove(lookupId);
        hdfLookupId.Value = "";
        foreach (ListItem itm in lbCheckedIdList.Items)
        {
            hdfLookupId.Value += (hdfLookupId.Value == "" ? "" : ",") + itm.Value;
        }
        postbackFlag = true;
    }

Please Help! Thanks.




Aucun commentaire:

Enregistrer un commentaire