繁体   English   中英

单击按钮即可同时执行客户端和服务器端功能-特定方案

[英]Performing both client side and server side functions on button click - Specific Scenario

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

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

我正在使用以下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" />

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>

后面的代码:

protected void btnProceed_Click1(object sender, EventArgs e)
{
    Response.Write("DD");
    //your proceed
}

暂无
暂无

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

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