<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" .WebForm2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="tb1" runat="server"></asp:TextBox> <asp:CheckBox ID="CheckBox1" runat="server" oncheckedchanged="CheckBox1_CheckedChanged" AutoPostBack="True" /> </div> </form> </body> </html> using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; namespace { public partial class WebForm2 : System.Web.UI.Page { protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { if(CheckBox1.Checked==true) { tb1.Visible = true; } else { tb1.Visible=false; } } protected void Page_Load(object sender, EventArgs e) { tb1.Visible = false; } } }
If this post helps you mark it as answer Thanks
textbox.Enabled = checkBox.Checked;
Mark This Response as Answer -- Chandu http://www.dotnetfunda.com/images/dnfmvp.gif
<script type="text/javascript" language="javascript"> function enableTextBox() { var textBoxID = "<%= txtAddress.ClientID %>"; if (document.getElementById("<%= chkAssociation.ClientID %>").checked == true) document.getElementById(textBoxID).disabled = false; else document.getElementById(textBoxID).disabled = true; } </script> and than the control: <asp:CheckBox Checked="false" OnChange="javascript:enableTextBox();" ID="chkAssociation" runat="server" /> <asp:TextBox ID="txtAddress" Enabled="false" Text="Test" runat="server" />
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TextBoxAndCheckBox.aspx.cs" Inherits="CopyDataFromOneControlToAnother.TextBoxAndDropDownList" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" language="javascript"> function enableTextBox() { var textBoxID = "<%= txtAddress.ClientID %>"; if (document.getElementById("<%= chkAssociation.ClientID %>").checked == true) document.getElementById(textBoxID).disabled = false; else document.getElementById(textBoxID).disabled = true; } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:CheckBox Checked="false" OnChange="javascript:enableTextBox();" ID="chkAssociation" runat="server" /> <asp:TextBox ID="txtAddress" Enabled="false" Text="Test" runat="server" /> </div> </form> </body> </html>
Login to post response