| Author: Shanmugam 04 Jul 2008 | Member Level: Gold | Rating:  Points: 6 |
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <input id="Text1" type="text" runat="server" /> <input id="Checkbox1" type="checkbox" onclick="CHangeStatus()" /> </div> </form> <script language="javascript"> function CHangeStatus() { document.getElementById ('<%=Text1.ClientID %>').disabled=document.form1.Checkbox1.checked } </script> </body> </html>
|
| Author: Hubli Sunil 04 Jul 2008 | Member Level: Diamond | Rating:  Points: 6 |
Hi,
You can write the code as follows,
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %> <!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> <script language="javascript"> var txtBoxClientId = "<%= txtBox.ClientID.ToString()%>"; function Check(a) { if (a.checked == true) document.getElementById(txtBoxClientId).disabled = false; else document.getElementById(txtBoxClientId).disabled = true; } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="txtBox" runat="server"></asp:TextBox> <asp:CheckBox ID="chkBox" runat="server" Checked="true"/> </div> </form> </body> </html>
in the codebehind file write as follows in the pageload event, protected void Page_Load(object sender, EventArgs e) { chkBox.Attributes.Add("onclick", "Check(this);"); }
|