简体   繁体   English

复选框选中状态在ASP.NET中出错

[英]check box checked state getting wrong in ASP.NET

My ASP.NET application has two Check-boxes. 我的ASP.NET应用程序有两个复选框。 I want to checked a check-box another check-box checked on condition.The condition is if another check-box is not checked than only is checked otherwise not. 我想选中一个复选框,另一个复选框处于选中状态。条件是是否选中另一个复选框而不是选中另一个复选框。 For that i have to check that checked state.And this is doing by **$(chkmanual).is(":checked")** 为此,我必须检查该检查状态。这是通过**$(chkmanual).is(":checked")**

Code snipet given below: 代码片段如下:

function UpdateCheck() {
  var chkmanual = $("[id*=chkManual]");
  alert($(chkmanual).is(":checked")); //here i getting always true. 
  if (!$(chkmanual).is(":checked"))
  {                 
     chkmanual.click();
  }
}

My check box like: 我的复选框如下:

<asp:DataList ID="dgDeviceList" runat="server">
  <HeaderTemplate>
     <table cellpadding="5" cellspacing="5" width="100%">
        </HeaderTemplate>
           <ItemTemplate>
              <tr>
                  <td>
              <ajaxToolkit:ToggleButtonExtender ID="ToggleExManual" runat="server" TargetControlID="chkManual" CheckedImageAlternateText="Check" UncheckedImageAlternateText="UnCheck" UncheckedImageUrl="~/images/empty.png"
CheckedImageUrl="images/checkbox.png" ImageWidth="30" ImageHeight="30" DisabledCheckedImageUrl="~/images/DisableCheckbox.png"                                           DisabledUncheckedImageUrl="~/images/DisableEmpty.png" />
              <ajaxToolkit:ToggleButtonExtender ID="ToggleExPatientOwned" runat="server" TargetControlID="chkPatientOwned" CheckedImageAlternateText="Check" UncheckedImageAlternateText="UnCheck" UncheckedImageUrl="~/images/empty.png"
 CheckedImageUrl="images/checkbox.png" ImageWidth="30" ImageHeight="30" DisabledCheckedImageUrl="~/images/DisableCheckbox.png"DisabledUncheckedImageUrl="~/images/DisableEmpty.png" />
    <asp:CheckBox ID="chkManual" runat="server" Text="Manual" Width="100px" CssClass="chkPosition" Enabled="false" />
    <asp:CheckBox ID="chkPatientOwned" runat="server" Text="Patient Owned" Width="130px" onclick="javascript:UpdateCheck();" CssClass="chkPosition" Enabled="false" />
              </td>
            </tr>
           </ItemTemplate>
          <FooterTemplate>
         </table>
       </FooterTemplate>
</asp:DataList>

Demo FIDDLE 演示FIDDLE

HTML 的HTML

<input type="checkbox" id="manual">
<input type="checkbox" onclick="updateCheck(this);">

Jquery jQuery的

function updateCheck(sender)
{
    if(!$(sender).prev('#manual').prop('checked'))
        $(sender).attr("checked",true);
    else
        $(sender).attr("checked",false); 
}

You can simply check it by using a javascript in your asp.net client side code (aspx page). 您只需在asp.net客户端代码(aspx页)中使用JavaScript即可对其进行检查。 Try the following code, it is simple and work for you. 尝试以下代码,它很简单,可以为您工作。

<script type="text/javascript">
    function EnableDisableCB() {
        if (document.getElementById('<%=checkBox1.ClientID%>').checked) {
            document.getElementById('<%=checkBox2.ClientID%>').disabled = true;
        }
        else {
            document.getElementById('<%=checkBox2.ClientID%>').disabled = false;
        }
    }
</script>

above simple script will enable disable your 2nd checkbox depending on your 1st checkbox condition. 上面的简单脚本将根据您的第一个复选框条件启用禁用第二个复选框的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM