views:

57

answers:

2

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" />
A: 

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

Bill Quinn
+1  A: 

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