1

How do I enable a check_change for a checkbox in VB.

Here is what I have so far.

Code Behind:

    Protected Sub CheckBoxCash_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBoxCash.CheckedChanged
        Label1.Text = "Cash"
    End Sub

Front end code:

    <asp:Label ID="Label1" runat="server" Text="Empty"></asp:Label>
    <asp:CheckBox ID="CheckBoxPoints" runat="server" Checked="True" />
Bill Quinn
  • 11
  • 2
  • Coincidence or not: Your VB method `Handles CheckBoxCash.CheckedChanged`, but your checkbox name is `CheckBoxPoints` – Tomalak Jan 11 '10 at 18:58

2 Answers2

1

It looks like you're not doing anything that specifically requires a postback here. In that case, I'd skip the postback entirely an do it more like this:

<asp:Label ID="Label1" runat="server" Text="Empty"></asp:Label>
<asp:CheckBox ID="CheckBoxPoints" runat="server" Checked="True" onclick="document.getElementById('Label1').value = 'Cash';" />

Of course, that's the simple version. Production code would also involve checking the label's clientid property in case these controls ever end up inside a naming container (like an asp:panel or gridview). I'd also look for a fallback for when javascript is not enabled, but in this case the Check_Changed server event depends on javascript to fire anyway.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
0

I figured it out, I forgot to set the postback to true

Bill Quinn
  • 11
  • 2