Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.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
C# 复选框的OnCheckedChanged事件的编译错误_C#_Asp.net Ajax - Fatal编程技术网

C# 复选框的OnCheckedChanged事件的编译错误

C# 复选框的OnCheckedChanged事件的编译错误,c#,asp.net-ajax,C#,Asp.net Ajax,我在aspx页面中有复选框,在代码隐藏中有oncheckedchanged事件处理程序。 我的aspx页面如下 <div align="center"> <table width="500px"> <tr> <td> <fieldset id="fs1" runat="server"> <legend>Ty

我在aspx页面中有复选框,在代码隐藏中有oncheckedchanged事件处理程序。 我的aspx页面如下

<div align="center">
    <table width="500px">
        <tr>
            <td>
                <fieldset id="fs1" runat="server">
                    <legend>Type </legend>
                    <table>
                        <tr>
                            <td>
                                <asp:CheckBox ID="CBNPatient" runat="server" Text="New Patient" OnCheckedChanged="CBNPatient_CheckedChanged" AutoPostBack="true" />
                            </td>
                            <td>
                                <asp:CheckBox ID="CBNPhPatient" runat="server" Text="New Patient By Phone" OnCheckedChanged="CBNPhPatient_CheckedChanged" AutoPostBack="true" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <fieldset id="fsAdd" runat="server" visible="false">
                                    <table>
我得到一个编译错误,如下所示:

 protected void CBNPatient_CheckedChanged(object sender,EventArgs e  )
        {
            if (CBNPatient.Checked == true)
            {

                HtmlGenericControl fieldset = (HtmlGenericControl)Master.FindControl("fsAdd");
                fieldset.Visible = true;
                PatAdd = true;               

            }
            else
            {
                HtmlGenericControl fieldset = (HtmlGenericControl)Master.FindControl("fsAdd");
                fieldset.Visible = false;
                PatAdd = false;
            }

        }

        protected void CBNPhPatient_CheckedChanged(object sender, EventArgs e)
        {
            if (CBNPhPatient.Checked == true)
            {

                HtmlGenericControl fieldset = (HtmlGenericControl)Master.FindControl("fsAdd");
                fieldset.Visible = true;
                PhPatAdd = true;
            }
            else
            {
                HtmlGenericControl fieldset = (HtmlGenericControl)Master.FindControl("fsAdd");
                fieldset.Visible = false;
                PhPatAdd = false;
            }
        }
“ASP.framepages\u registration\u raddock\u aspx”不包含“CBNPartient\u CheckedChanged”的定义,并且找不到接受类型为“ASP.framepages\u registration\u raddock\u aspx”的第一个参数的扩展方法“CBNPartient\u CheckedChanged”(是否缺少using指令或程序集引用?) 复选框位于字段集中。这会导致任何问题吗

请帮我做这个。 谢谢
Soumya

看,这还不是一个完整的答案,但有几件事你应该注意:

  • 如果条件语句中有布尔变量(
    if
    ),则不必将它们与
    true
    false
    进行比较。只需测试它们,如
    if(CBNPatient.Checked)
  • 看看您的代码,您正在执行相同的逻辑,只是根据复选框的选择更改bool值。这两种方法都可以简化为:

        HtmlGenericControl fieldset = (HtmlGenericControl)Master.FindControl("fsAdd");
        fieldset.Visible = CBNPatient.Checked;
        PatAdd = CBNPatient.Checked;
    

  • 您好,Soumya,您在系统中添加了参考。Web@Soumya,您可以发布您的页面指令部分吗?您最近添加了这些处理程序吗?您的标记可能已更改,但由于某种原因,代码未重新生成。重建(并在必要时重新部署)整个项目。我的引用中有System.web…请在我使用命名空间UnicareSystemWeb.FramePages.Registration{公共部分类raddock:System.web.UI.page的代码中找到我的page指令{