Phesant123
asked on
Enable button with a checkbox VB
i am using VB Script. i have a check box and a disabled button. i wish to enable button when checkbox is checked and disable button when checkbox is unchecked. Here is the code I have so far:
Default.aspx
<asp:CheckBox ID="CBFlights" runat="server" Text="Flights" value="ON" onclick="enbutton()"/>
<asp:Button ID="BNFlight" runat="server" Text="Flights" Width="74px" Enabled="False" />
Default.aspx.vb
Sub enbutton()
If CBFlights.Checked = True Then
BNFlight.Enabled = True
Else
BNFlight.Enabled = False
End If
End Sub
Can anyone help here - not sure what I am doing wrong :(
Thanks
Default.aspx
<asp:CheckBox ID="CBFlights" runat="server" Text="Flights" value="ON" onclick="enbutton()"/>
<asp:Button ID="BNFlight" runat="server" Text="Flights" Width="74px" Enabled="False" />
Default.aspx.vb
Sub enbutton()
If CBFlights.Checked = True Then
BNFlight.Enabled = True
Else
BNFlight.Enabled = False
End If
End Sub
Can anyone help here - not sure what I am doing wrong :(
Thanks
ASKER
Hi TimCottee
Thanks for your speedy reply - thats exactly what I require above but I have entered the code above:
<asp:CheckBox ID="CBFlights" runat="server" Text="Flights" value="ON" onclientclick="document.ge tElementBy Id('<%=BNF light.Clie ntID()%>') .disabled= !this.chec ked;"/>
<asp:Button ID="BNFlight" runat="server" Text="Flights" Width="74px" Enabled="False" />
The button remains blanked out when I click in the checkbox - any ideas?
Thanks
Thanks for your speedy reply - thats exactly what I require above but I have entered the code above:
<asp:CheckBox ID="CBFlights" runat="server" Text="Flights" value="ON" onclientclick="document.ge
<asp:Button ID="BNFlight" runat="server" Text="Flights" Width="74px" Enabled="False" />
The button remains blanked out when I click in the checkbox - any ideas?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks TimCottee
That works perfect
That works perfect
Firstly what you really want to be doing is to do this on the client-side and not on the server-side. For a simple task like this there is really no need to make a round-trip to the server.
Use the following code (assuming you are using framework 2.0 or higher, let me know if you would prefer a 1.0/1.1 version).
<asp:CheckBox ID="CBFlights" runat="server" Text="Flights" value="ON" onclientclick="document.ge
<asp:Button ID="BNFlight" runat="server" Text="Flights" Width="74px" Enabled="False" />
I know this is a javascript version but it is much simpler than writing a seperate function when it is not really necessary.
Regards,
TimCottee