If your controls are enable then you take some action onto the controls such as checked or unchecked CheckBox and If they are disable then you don't take some action onto the controls.
In previous example we saw checked property of checkbox control .
In previous example we saw checked property of checkbox control .
Example of Dynamically Enable or Disable ASP.NET Controls
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Button2_Click(object sender, EventArgs e)
{
Button1.Enabled = true;
CheckBox1.Enabled = true;
RadioButton1.Enabled = true;
TextBox1.Enabled = true;
}
protected void Button3_Click(object sender, EventArgs e)
{
Button1.Enabled = false;
CheckBox1.Enabled = false;
RadioButton1.Enabled = false;
TextBox1.Enabled = false;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button Control" />
<br />
<br />
<asp:CheckBox ID="CheckBox1" runat="server" Text="CheckBox Controls" />
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server" Width="164px">TextBox Control</asp:TextBox>
<br />
<br />
<asp:RadioButton ID="RadioButton1" runat="server" Text="Radio Button Control" />
<br />
<br />
<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Controls Enable" />
<asp:Button ID="Button3" runat="server" Text="Controls Disable" OnClick="Button3_Click" />
</div>
</form>
</body>
</html>
Output <!DOCTYPE html>
<script runat="server">
protected void Button2_Click(object sender, EventArgs e)
{
Button1.Enabled = true;
CheckBox1.Enabled = true;
RadioButton1.Enabled = true;
TextBox1.Enabled = true;
}
protected void Button3_Click(object sender, EventArgs e)
{
Button1.Enabled = false;
CheckBox1.Enabled = false;
RadioButton1.Enabled = false;
TextBox1.Enabled = false;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button Control" />
<br />
<br />
<asp:CheckBox ID="CheckBox1" runat="server" Text="CheckBox Controls" />
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server" Width="164px">TextBox Control</asp:TextBox>
<br />
<br />
<asp:RadioButton ID="RadioButton1" runat="server" Text="Radio Button Control" />
<br />
<br />
<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Controls Enable" />
<asp:Button ID="Button3" runat="server" Text="Controls Disable" OnClick="Button3_Click" />
</div>
</form>
</body>
</html>
Tidak ada komentar:
Posting Komentar