在Postback后取消选中CheckBox [英] CheckBox is unchecked after Postback

查看:72
本文介绍了在Postback后取消选中CheckBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在用户控件的ItemTemplate(gridview)中使用复选框。我在CheckedChanged事件中写了一些代码。它正在运行。完成活动后,我的页面加载时取消选中复选框。



Hi,
I am using check box in ItemTemplate(gridview) in User Control. I wrote some code in CheckedChanged event. It is Running. after completing the event my page is loading with uncheck checkbox.

<asp:TemplateField ItemStyle-Width="4%">
                                        <ItemTemplate>
                                            <asp:CheckBox Width="10%" ID="chkDocumentName" runat="server" OnCheckedChanged="chkDocumentName_CheckedChanged" AutoPostBack="true"/>
                                        </ItemTemplate>
                                        <ItemStyle Width="3%" />
                                    </asp:TemplateField>













protected void chkDocumentName_CheckedChanged(object sender, EventArgs e)
    {
        for (int i = 0; i < gvDocumentTemplatestatus.Rows.Count; i++)
        {
            CheckBox chkbox = (CheckBox)gvDocumentTemplatestatus.Rows[i].FindControl("chkDocumentName");
            if (chkbox.Checked == true)
            {
                Label lblTemplateId = (Label)gvDocumentTemplatestatus.Rows[i].FindControl("lblTempID");
                Label lblDocumentNumberID = (Label)gvDocumentTemplatestatus.Rows[i].FindControl("lblDocumentNumberID");
                 Label lblTemplateName = (Label)gvDocumentTemplatestatus.Rows[i].FindControl("lblTemplateName");
                 Session["rownumber"] = i.ToString();
                Session["TempID"] = lblTemplateId.Text;
                
            }
            else
            {
                if (Session["rownumber"] != null)
                {
                    if (Convert.ToInt32(Session["rownumber"].ToString()) == i)
                    {
                        strcolumnnumber = "0";
                        Session["SubJobID"] = strcolumnnumber;
                    }
                }
            }
        }
    }





这是我的代码在回复后我的复选框未经检查。







如果有人知道这个告诉我。



问候

Nanda Kishore.CH



This is my code after postback my check box is unchecked.



if any one know about this tell me.

Regards
Nanda Kishore.CH

推荐答案

使用更新面板内部项目模板



ie

use update panel inside item template

i.e.
<updatepanel>
<contenttemplate>
<asp:checkbox width="10%" id="chkDocumentName" runat="server" oncheckedchanged="chkDocumentName_CheckedChanged" autopostback="true" xmlns:asp="#unknown" />
</contenttemplate>
</updatepanel>





如果仍然无法正常工作

然后使用异步回发触发器与此更新面板



if still not working
then use asynchronous postback trigger with this updatepanel


解决方案是向页面添加隐藏字段,表示复选框的状态,然后更新字段的值为ON或关闭或关闭例如,每当点击复选框时。



然后在服务器上检查隐藏字段的值,而不是复选框本身,因为隐藏字段总是发布。



快乐编码!

:)
A solution is to add a hidden field to the page that represents the state of the checkbox, then update the field's value to "ON" or "OFF" for example, whenever the checkbox is clicked.

Then on the server you check the value of the hidden field, not the checkbox itself, as the hidden field is always posted.

Happy Coding!
:)


hi,



这是因为当发生回发时gridview重新创建,所以我们松开了以前的状态,所以它总是未选中,所以把gridview绑定的代码放在page.ispostback



检查gridview在页面加载中绑定的代码它应该在page.ispostback



if(!Page.IsPostBack)

{

绑定gridview这里

}


This is because when postback occurs gridview recreates so we loose the previous state so it will come always unchecked so put the gridview binded code under page.ispostback

check the code where gridview is binded in page load it should be under the page.ispostback

if (!Page.IsPostBack)
{
bind gridview here
}


这篇关于在Postback后取消选中CheckBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆