开发者

How to disable and Enable TextBox acording to checklbox

开发者 https://www.devze.com 2023-01-27 14:50 出处:网络
<asp:CheckBox ID=\"htmlChkNotify开发者_StackOverflow中文版\" runat=\"server\" OnCheckedChanged=\"ToggleTextBox(this,\'htmlTxtNotifyemailaddress\')\" />
<asp:CheckBox ID="htmlChkNotify开发者_StackOverflow中文版" runat="server" OnCheckedChanged="ToggleTextBox(this,'htmlTxtNotifyemailaddress')" />  
<asp:TextBox ID="htmlTxtNotifyemailaddress" runat="server" Enabled="false"></asp:TextBox>  

function ToggleTextBox(CheckBox, TextBoxID) {

     var TextBox = document.getElementById(TextBoxID);  
     if (CheckBox.checked) {  
         TextBox.disabled = false;  
         TextBox.value = "";  
     }  
     else {  
         TextBox.disabled = true;  
         TextBox.value = "";  
     }  
 } 

I have write like but when I run the code then error message comeing " can't be pass this literal" something like that, so how can I do it?

Actually u can also see demo in stackoverflow "Notify daily of any new answers" I want to fire event like.

Thank you


OnCheckChanged is expecting an ASP.Net event handler, it's not for JavaScript, for that attach your event handler like this:

htmlChkNotify.Attributes.Add("onclick",  
   "ToggleTextBox(this,'" + htmlTxtNotifyemailaddress.ClientID + "');");

I broke it down to 2 lines for readability here only, but the idea is to generate an onclick inline handler, rather than the server-side event handler it's currently trying to bind, in a place it can't pass this (which is why the parser fails).

0

精彩评论

暂无评论...
验证码 换一张
取 消