为什么未引用我的代码隐藏事件处理程序? [英] Why is my code-behind event handler not referenced?

查看:57
本文介绍了为什么未引用我的代码隐藏事件处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Why does my code-behind have no effect and my breakpoint is not reached?

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

I've got this in my WebForm1.aspx file:

<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文件中的事件处理程序为:

The event handler in WebForm1.aspx.cs file is:

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

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

I have a breakpoint on the first line (the assignment to the bool).

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

The breakpoint is not reached when I check the ckbxAllGenres control; and so, of course, the code does not run, and nothing happens.

的确,事件处理程序指示"0引用","0引用".但是为什么会这样呢?

It's true that the event handler indicates "0 references," but why would that be?

WebForm1.aspx的第一行是:

The top line of WebForm1.aspx is:

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

推荐答案

自从我使用网络表单已经一年了,但是我认为您在 AutoPostBack =" 复选框:

It's been a year since I've used web forms, but I think you're missing AutoPostBack="true" on the checkbox:

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

这篇关于为什么未引用我的代码隐藏事件处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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