开发者

VB - how to link up a Check_change to code behind for a checkbox

开发者 https://www.devze.com 2022-12-16 14:48 出处:网络
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

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>
    &开发者_如何学Golt;asp:CheckBox ID="CheckBoxPoints" runat="server" Checked="True" />


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号