how to enable and disable the textbox using checkbox

Posted by Kishore22 under ASP.NET on 9/18/2013 | Points: 10 | Views : 7997 | Status : [Member] | Replies : 5
how to enable and disable the textbox using checkbox in asp.net . please help me the source code




Responses

Posted by: Bandi on: 9/18/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Duplicate thread:
http://www.dotnetfunda.com/forums/thread16305-enabling-a-textbox-using-a-checkbox-in-aspnet.aspx

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 9/18/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
You can see the below code:-

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
function enableTextBox()
{
if (document.getElementById("chkAssociation").checked == true)
document.getElementById("txtAddress").disabled = false;
else
document.getElementById("txtAddress").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>


Happy Coding

If it helps you or directs U towards the solution, MARK IT AS ANSWER

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 9/18/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
You can also see the below links:-

http://www.codeproject.com/Tips/299691/Enable-Disable-Textboxes-based-on-CheckBox-using-J
http://stackoverflow.com/questions/1531552/how-to-disable-textbox-depending-on-checkbox-checked
http://stackoverflow.com/questions/16748411/how-to-disable-a-textbox-if-a-checkbox-is-checked-using-jquery
http://stackoverflow.com/questions/9442305/why-cant-i-get-my-textbox-to-enable-disable-with-my-checkbox

Happy Coding.
If it helps you or directs U towards the solution, MARK IT AS ANSWER



Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 9/18/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
<%@ 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

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/18/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi webmaster,

This is duplicate thread... (same as http://www.dotnetfunda.com/forums/thread16305-enabling-a-textbox-using-a-checkbox-in-aspnet.aspx )
Better to deactivate the thread for maintenance purpose.....
Same solutions are also available in the referred thread)

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kishore22, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response