views:

58

answers:

2

i have a textarea which i want to disable when I check a checkbox. I made a working demo in plain HTML and JavaScript , but When I am migrating to Asp.net, neither the function is being executed nor I can keep the OnSelect event in my check box.

<asp:CheckBox ID="ChkOthers" runat="server" Text="Others(Please Explain)" Width="205px" AutoPostBack="True" OnCheckedChanged="ChkOthers_CheckedChanged" />
<asp:TextBox ID="TxtOtherReason" runat="server" MaxLength="1024" TextMode="MultiLine" />

i want to create client side validation when check box is checked textbox is enable else disable.

+2  A: 

It has been a while for me since I used ASP.NET but from memory there is something like an "OnClientClick" event and a validation property in asp.net properties for a control that you can use to call client side JavaScript code..

Sorry for the vague answer - perhaps someone can expand on it.

filip-fku
Sorry i cant find any onclientclick.plz explane.
A: 

You are using a server side handling of the event. Use a client side handling with "OnClientClick". You can do something like:

<asp:CheckBox ID="ChkOthers" runat="server" 
     Text="Others(Please Explain)" 
     Width="205px" 
     AutoPostBack="True" 
     OnClientClick="alert(this.checked);" 
     OnCheckedChanged="ChkOthers_CheckedChanged" />

It seems this also does not work. I am yet to prove.

Also see a similar post on StackOverflow: http://stackoverflow.com/questions/1135134/onclick-vs-onclientclick-for-an-aspcheckbox and there is also an issue in MS site: http://connect.microsoft.com/VisualStudio/feedback/details/103398/checkbox-onclientclick

Kangkan
can you define detail