Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在特定于按钮单击的场景中执行客户端和服务器端功能_C#_Javascript_Asp.net_Checkbox - Fatal编程技术网

C# 在特定于按钮单击的场景中执行客户端和服务器端功能

C# 在特定于按钮单击的场景中执行客户端和服务器端功能,c#,javascript,asp.net,checkbox,C#,Javascript,Asp.net,Checkbox,我有一个复选框、标签和按钮控件。 如果未选中复选框并单击按钮,我需要在标签中显示一条消息,说明首先选中复选框。 如果选中复选框,然后单击按钮,则应允许我继续 这与“条款和条件”屏幕非常相似,如果不选中复选框,则不允许继续 我正在使用下面的javascript。请告诉我如何实现此功能 <script type="text/javascript"> function testCheckbox() { var obj = document.getElementById('<%

我有一个复选框、标签和按钮控件。 如果未选中复选框并单击按钮,我需要在标签中显示一条消息,说明首先选中复选框。 如果选中复选框,然后单击按钮,则应允许我继续

这与“条款和条件”屏幕非常相似,如果不选中复选框,则不允许继续

我正在使用下面的javascript。请告诉我如何实现此功能

<script type="text/javascript">
function testCheckbox() {
    var obj = document.getElementById('<%= chkTerms.ClientID %>');
    if (obj.checked == false) {
        document.getElementById("lblCheck").style.visibility = "visible";
        return false;
    }
}
</script>
<asp:Label ID="lblTerms" runat="server" Text="I agree to the Terms and Conditions">   </asp:Label>

<asp:Label ID="lblCheck" runat="server" Text="Please agree to the terms and conditions to proceed"></asp:Label>

<asp:Button ID="btnProceed" runat="server" OnClientClick ="return testCheckbox()"   OnClick="btnProceed_Click" Text="Submit" />

函数testCheckbox(){
var obj=document.getElementById(“”);
if(obj.checked==false){
document.getElementById(“lblCheck”).style.visibility=“visible”;
返回false;
}
}
ASPX:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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></title>
<script src="js/jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#lblCheck').hide();
        $('#btnProceed').click(function () {
            var $this = $('#chkTerms')

            if ($this.is(':checked')) {
                $('#lblCheck').hide();
                return true;
            } else {
                $('#lblCheck').show();
                return false;
            }
        });
    });
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:CheckBox ID="chkTerms" runat="server" Text="I agree to the Terms and Conditions"/><br />
<asp:Label ID="lblCheck" runat="server" Text="Please agree to the terms and conditions to proceed"/><br />
<asp:Button ID="btnProceed" runat="server" Text="Submit" onclick="btnProceed_Click1" />
</form>
</body>
</html>
ASPX:


在上面的代码中,您有2个标签和1个按钮在上面的代码中,您有2个标签和1个按钮。我尝试使用您提供的将label的enabled view state属性设置为false的早期解决方案,但它没有按预期工作。让我试试你现在提供的jquery。它不起作用@Samiey。在页面加载时,它显示标签文本-请同意处理页面加载的条款和条件,我想这是问题所在。不知何故,我们需要使文本不可见。它工作得如此顺利。你是冠军。我需要在jquery上动手…谢谢@Samiey MehdiThanks@Samiey Mehdi。我尝试使用您提供的将label的enabled view state属性设置为false的早期解决方案,但它没有按预期工作。让我试试你现在提供的jquery。它不起作用@Samiey。在页面加载时,它显示标签文本-请同意处理页面加载的条款和条件,我想这是问题所在。不知何故,我们需要使文本不可见。它工作得如此顺利。你是冠军。我需要在jquery上动手…谢谢@Samiey Mehdi
protected void btnProceed_Click1(object sender, EventArgs e)
{
    Response.Write("DD");
    //your proceed
}