Sometimes it becomes necessary to enable or disable a controls, or group of controls on a web page, based on choices made in that page. Controls which could govern this type of change include Checkboxes or RadioButtons, for example. Naturally, if there were multiple controls which need to be enabled or disabled in this manner, it would be better to put them all in a container control, like the Panel.
This sample shows how to do this, using 2 checkboxes. Using the 'OnCheckChanged' event of the Checkbox, it's very easy to get this scenario setup quickly.
<script language="VB" Runat="server"> Sub Page_Load(Source as Object, E as EventArgs) EnableCheckBox End Sub
Sub doIt(Source as Object, E as EventArgs) EnableCheckBox End Sub
Sub EnableCheckBox() if chk1.checked="True" then chk2.Enabled="True" else chk2.enabled="False" End If End Sub </script> <html> <head> <meta name="GENERATOR" Content="ASP Express 5.0"> <title>Disabling/Enabling Controls w/Checkbox</title> </head> <body> <form id="form1" Runat="server"> <asp:Checkbox Text="Check box #1" id="chk1" AutoPostBack="true" OnCheckedChanged="doIt" Runat="server" /> <asp:Checkbox Text="Check box #2" id="chk2" Runat="server" /> </form> </body> </html>
|
No responses found. Be the first to respond and make money from revenue sharing program.
|