【问题标题】:How can I add refresh Button to mscaptcha component?如何将刷新按钮添加到 mscaptcha 组件?
【发布时间】:2014-09-17 18:02:09
【问题描述】:

如何向 mscaptcha 组件添加刷新按钮以更改代码而不由用户刷新页面??

我正在使用:

<httpHandlers>
<add verb="GET" path="CaptchaImage.axd" type="MSCaptcha.CaptchaImageHandler, MSCaptcha"/>
</httpHandlers>

在 Visual C# 中

【问题讨论】:

    标签: c# asp.net captcha


    【解决方案1】:

    您编写的代码在 webconfig 上。在你的页面上写下这段代码:

      //ScriptManager is necessary for update panel
        <asp:ScriptManager ID="sm" runat="server">
        </asp:ScriptManager>
        <div>
            Please enter text
            <asp:TextBox ID="txtCaptcha" runat="server"></asp:TextBox>
        </div>
        // you should use update panel because you want just the captch refresh not all
        the page.
        <asp:UpdatePanel ID="up1" runat="server">
            <ContentTemplate>
                <div>
                    <div style="display: inline-block">
                        //its captcha control
                        <cc1:CaptchaControl ID="Captcha1" runat="server" CaptchaBackgroundNoise="Low" CaptchaLength="5"
                            CaptchaHeight="60" CaptchaWidth="200" CaptchaMinTimeout="5" CaptchaMaxTimeout="240"
                            FontColor="#D20B0C" NoiseColor="#B1B1B1" />
                    </div>
                    <div style="display: inline-block">
                        // its your refresh button
                        <asp:ImageButton ImageUrl="~/refreshpic.png" runat="server" CausesValidation="false" />
                    </div>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
        <div>
            <div>
                <asp:CustomValidator ErrorMessage="Invalid." OnServerValidate="ValidateCaptcha" runat="server" />
            </div>
            <div>
                <asp:Button ID="btnSubmit" runat="server" Text="Register" />
            </div>
        </div>
    

    在代码后面你应该写一些这样的代码:

     protected void ValidateCaptcha(object sender, ServerValidateEventArgs e)
        {
            Captcha1.ValidateCaptcha(txtCaptcha.Text.Trim());
            e.IsValid = Captcha1.UserValidated;
            if (e.IsValid)
            {
              //do some thing
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-05
      • 1970-01-01
      • 2012-05-29
      • 2020-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多