为什么未引用我的代码隐藏事件处理程序?

问题描述

为什么我的后台代码没有效果并且没有到达断点?

我已经在WebForm1.aspx文件中找到了它:

<asp:checkBox id="ckbxAllGenres" runat="server" Checked="True" OnCheckedChanged="ckbxAllGenres_CheckedChanged" />
<label for="ckbxAllGenres">All</label>
<asp:checkBox id="ckbxAction" runat="server" />
<label for="ckbxAction">Action</label>
<asp:checkBox id="ckbxAdventure" runat="server" />
<label for="ckbxAdventure">Adventure</label>

WebForm1.aspx.cs文件中的事件处理程序为:

protected void ckbxAllGenres_CheckedChanged(object sender,EventArgs e)
{
    bool allGenresChecked = ckbxAllGenres.Checked;
    ckbxAction.Checked = allGenresChecked;
    ckbxAdventure.Checked = allGenresChecked;
    . . .

我在第一行有一个断点(对bool的赋值)。

当我检查ckbxAllGenres控件时,未达到断点;因此,当然,代码不会运行,什么也不会发生。

确实,事件处理程序指示“ 0个引用”,但是为什么会这样呢?

WebForm1.aspx的第一行是:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Flix4Fams_WebForms.WebForm1" %>

解决方法

使用Web表单已经有一年了,但是我认为您在复选框上缺少AutoPostBack="true"

<asp:checkbox 
    id="ckbxAllGenres" 
    runat="server" 
    Checked="True" 
    OnCheckedChanged="ckbxAllGenres_CheckedChanged" 
    AutoPostBack="true" />

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...