Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 页面刷新后如何保持复选框选中状态?_Javascript_C#_Jquery_Asp.net - Fatal编程技术网

Javascript 页面刷新后如何保持复选框选中状态?

Javascript 页面刷新后如何保持复选框选中状态?,javascript,c#,jquery,asp.net,Javascript,C#,Jquery,Asp.net,我有一个listview并试图删除多个选中的数据。但是,当按下删除按钮时,页面将被刷新,并且复选框未被选中,因此数据不会被删除。这是我的密码: 页面加载: protected void Page_Load(object sender, EventArgs e) { if (Session["username"] == null) Response.Redirect("admin-login"); lblusername.Text = Session["userna

我有一个listview并试图删除多个选中的数据。但是,当按下删除按钮时,页面将被刷新,并且复选框未被选中,因此数据不会被删除。这是我的密码: 页面加载:

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["username"] == null)
        Response.Redirect("admin-login");
    lblusername.Text = Session["username"].ToString();
    string nation;

         bindListview();

 }
删除按钮代码:

protected void btnDelete_Click(object sender, EventArgs e)
{
    try
    {

        foreach (ListViewDataItem Ldi in ListView1.Items)
        {
            CheckBox cb = (CheckBox)(Ldi.FindControl("chkBxSelect"));
            HiddenField hdnFldCandidateID = (HiddenField)(Ldi.FindControl("hdnFldCandidateID"));
            string candidateID = hdnFldCandidateID.Value;

            if (cb.Checked)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Confirm", "Confirm();", true);
                con.Open();
                query = "delete from candidates where candidate_id=" + candidateID + "";
                cmd = new SqlCommand(query, con);
                cmd.ExecuteNonQuery();
                con.Close();
                Response.Redirect("candidate-search");

            }

        }
    }
    catch (Exception ex)
    {
        Response.Write("Error:" + ex);
    }
    finally
    {
        con.Close();
    }
}

此问题与asp.net环境非常相似,问题在于回发呼叫,您需要做的是验证没有回发呼叫并将所有数据绑定到检查,其他解决方案您可以使用controll的ajax调用或使用wcf ajaxenableds,或者如果您不想做所有问题,解决方案是禁用从按钮发回,将
页面加载
事件处理程序代码放在这里。我是javascript新手。请您用示例解释一下好吗?谢谢在您的页面加载中,在您绑定数据的地方,请务必检查是否有ispostback。e、 g.如果(!Page.IsPostBack){databinding},则始终可以将值更改事件附加到复选框,该复选框将javascript函数调用到将布尔值保存到会话的c#函数。然后可以在页面加载时检索该值。效率不是很高,但这可能取决于您的场景