为什么我的代码隐藏没有效果,并且我的断点没有到达?
我的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" />