Click here to Skip to main content
15,896,359 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hai
How to enable and disable checkbox from server server side and client side.

i want to disable check boxex when page laod after if i click but from form it will enable check box.my problem is ,in design time and page load event i write a code like
VB
chkPPT.Enabled = False
and when button click even i write code for enable check box like
JavaScript
var chkPdf = document.getElementById('<%=chkPdf.ClientID%>');
            chkPdf.disabled = false;  or document.getElementById("ctl00_ContentPlaceHolder1_chkPdf").disabled = false;
but not work.


what problem when disable from server side and try to enable in java script not work,but second time it will disable from client side and can enable in client side.

Note : no span tag between check boxs


Pls reply me asap


Actually i want disable three check boxes from page load event and need to enable from client side in button onclient click event(java script).

Reagards
Aravind
Posted
Updated 11-Sep-13 23:03pm
v2
Comments
Thanks7872 12-Sep-13 4:53am    
First decide what you want to do. Secondly,decide whether you want it from client side or server side. Third, what are the criteria to enable/disable checkbox,i mean on page_load or some event. Define all the things clearly in order to make some one able to understand the problem.
Aravindba 12-Sep-13 5:04am    
thank for ur reply
Actually i want disable three check boxes from page load event and need to enable from client side in button onclient click event(java script).

Enable using JavaScript (Source: http://forums.asp.net/t/1260908.aspx[^] ):
C#
<asp:CheckBox runat="server" ID="CheckBox1"></asp:CheckBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="ChkEnabled(); return false;" />

XML
<script language="javascript" type="text/javascript">
  function ChkEnabled(){
        var a = document.getElementById('<%=CheckBox1.ClientID %>');
         a.removeAttribute('disabled');
        a.parentNode.removeAttribute('disabled');
    }
</script>

To disable in Page_Load:
CheckBox1.Enabled = false;

Regards..:)
 
Share this answer
 
v5
Comments
Aravindba 12-Sep-13 5:17am    
How to give disabled in server side ,it will show error like "'disabled' is not a member of 'System.Web.UI.WebControls.CheckBox'."
Thanks7872 12-Sep-13 5:24am    
Refer updated answer.
Aravindba 12-Sep-13 5:32am    
check boxes only not work,if i try in button it will work ,like disable in design time and from java script i can enable button.
Aravindba 12-Sep-13 5:28am    
your code works when enable and disable in client side,but my need page load i need to disable check box and enable from client side.
if u disable from server side page load or in design time(Enabled="False") it always disable can't enable from client side.
And this problem appear only in ie8,9 .but in chrome and mozila it works fine.did u check in ie 8 or 9 ?
Thanks7872 12-Sep-13 5:33am    
Try the updated code now. I tested and working fine.
Hai all
if i disable check boxes form server side or in design time, i cant enable check boxes from client side using javascript,this problem appear only in IE version,but chrome and mozila it works fine.

for this i call a one function at page load in client side and disable check boxes after i can enable check boxes from javascript . and my code is

JavaScript
window.onload = function disablecheckbox() {
         document.getElementById("ctl00_ContentPlaceHolder1_chka").disabled = true;
         document.getElementById("ctl00_ContentPlaceHolder1_chkb").disabled = true;
         document.getElementById("ctl00_ContentPlaceHolder1_chkc").disabled = true;
         document.getElementById("ctl00_ContentPlaceHolder1_chkd").disabled = true;
         document.getElementById("ctl00_ContentPlaceHolder1_chke").disabled = true;
         document.getElementById("ctl00_ContentPlaceHolder1_btnsave").disabled = true;
     }




Regards
Aravind
 
Share this answer
 
Comments
Thanks7872 12-Sep-13 6:16am    
Update question. This is not an answer,so remove this.
Aravindba 12-Sep-13 6:26am    
here i disable check box on page load client side,and easily can enable from client side
Thanks7872 12-Sep-13 6:29am    
So this is an answer right?
Aravindba 15-Sep-13 2:00am    
yea,ur answer is also work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900