0

我有一个条款和条件复选标记,复选框标题上链接了政策。

<div>
    <asp:CheckBox runat="server" ID="ckIAgree" ClientIDMode="Static" Text="" CssClass="pull-left checkbox" ValidationGroup="Security" />
    <span class="termsconditions">I have read and agree to the site <asp:LinkButton runat="server" ID="lnkTermsandConditions" CausesValidation="false" NavigateUrl="#" onclick="onclick_TermsandConditions" Text="Terms and Conditions" />.</span>
    <div class="clearfix"></div>
</div>

在 onclick 事件中,我将一个布尔值设置为“true”,表示他们已经点击了链接。

//Make sure link has been clicked
protected void onclick_TermsandConditions(object sender, EventArgs e)
{
    termsClicked = true;
}

我确实在页面顶部声明了变量,我认为这可能会导致我的问题,因为当我单击条款和条件链接时页面会重新加载。

bool termsClicked = false;

我确实有一个自定义验证器,可确保选中复选框,然后检查“termsClicked”变量的值。“termsClicked”变量总是显示为假。

//Validate Terms
protected void cvValidateTerms(object source, ServerValidateEventArgs args)
{
    args.IsValid = ckIAgree.Checked;
    if (termsClicked == false)
    {
        args.IsValid = false;
        cvTermsConditions.ErrorMessage = "You must view the terms and conditions";
    }
}
4

2 回答 2

1

termsClicked is only true when you show them the terms and conditions. It is not true when they post back the check mark (even if they previously read your terms/conditions). You'll have to use the session or some other persistent state mechanism (maybe the ViewState) to remember that they clicked the link in some previous request/response.

于 2012-11-20T18:38:50.110 回答
-1

确保您的变量是否全局声明?

不要在页面加载事件中声明变量。

于 2012-11-20T16:50:48.820 回答