Reputation: 10297
Why does my code-behind have no effect and my breakpoint is not reached?
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>
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;
. . .
I have a breakpoint on the first line (the assignment to the bool).
The breakpoint is not reached when I check the ckbxAllGenres control; and so, of course, the code does not run, and nothing happens.
It's true that the event handler indicates "0 references," but why would that be?
The top line of WebForm1.aspx is:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Flix4Fams_WebForms.WebForm1" %>
Upvotes: 0
Views: 220
Reputation: 14640
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" />
Upvotes: 3