如何在特定面板中生成验证码? [英] How do I generate a captcha in a specific panel?

查看:91
本文介绍了如何在特定面板中生成验证码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我使用了 [ Code_Project ]在我的网站上实现验证码。



代码似乎工作正常,但验证码出现在另一个/空白页面上。

此外,使用下面的代码,但是当生成验证码时,textfields en按钮不可见。任何人都可以帮我吗?

Hi,

I have used the code from [Code_Project] to implement captcha in my website.

The code seems to work fine, but the captcha appears on a different/blank page.
Also, the code below is used, but when the captcha is generated, the textfields en button aren't visible. Can anyone help me out here?

<asp:Panel ID="P_LastStepOrder" runat="server" Visible="false">
    <div style="width: 400px; float:left; margin-left:15px">
        <fieldset style=" width:350px">
            <legend>Customer Contact Info</legend>
            <asp:Label ID="L_CustName" runat="server" Width="200px" Text="Customer name:"></asp:Label>
            <br />
            <asp:TextBox ID="TB_CustName" runat="server" Width="200px"></asp:TextBox>
            <br />
            <asp:Label ID="L_CustEmail" runat="server" Width="200px" Text="Customer email address:"></asp:Label>
            <br />
            <asp:TextBox ID="TB_CustEmail" runat="server" Width="200px"></asp:TextBox>
            <br />
            <br />
            <div>
                 <asp:Label ID="L_CaptchaCheck" runat="server" Font-Bold="True" ForeColor="Red" Text=""></asp:Label>
                 <br />
            </div>
            <asp:TextBox ID="TB_CaptchaImageCode" runat="server"></asp:TextBox>
            <br />
            <asp:Image ID="I_Captcha" runat="server" ImageUrl="~/Webpages/ShoppingCart.aspx"/>
            <br />
            <asp:ImageButton ID="IB_SubmitOrder" runat="server" CausesValidation="False" ImageUrl="~/Images/IB_SubmitOrder.jpg"

                            ToolTip="Submit order" Height="50px" Width="180px" OnClick="Email"/>
        </fieldset>
    </div>
</asp:Panel>





这些标签等位于单击按钮后我设置的面板,也会触发load_Captcha代码。我也注意到图像I_Captcha的指定ImageUrl根本没有做任何事情。





祝你好运,

Mati



These labels etc are located in a Panel which I set visible as soon as a button is clicked, which also triggers the load_Captcha code. I've also noticed that the specified ImageUrl for image I_Captcha does not do anything at all.


Best regards,
Mati

推荐答案

不要在快速答案下发布 - 如果你从文章中得到了代码,那么就会有一个新消息按钮该文章的底部,它会将电子邮件发送给作者。然后他们会被告知你希望与他们交谈。

在这里发布这个依赖于他们匆匆而过并意识到这是为了他们。
Don't post this under Quick Answers - if you got the code from an article, then there is a "new message" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.


显然我必须创建一个新的aspx页面并在该页面上添加代码。



Apperently I had to create a new aspx page and add the code on that page.

using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace x.Webpages
{
    public partial class JpegImageCaptcha : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Create a random code and store it in the Session object.
            this.Session["CaptchaImageText"] = GenerateRandomCode();
            // Create a CAPTCHA image using the text stored in the Session object.
            RandomImage ci = new RandomImage(this.Session["CaptchaImageText"].ToString(), 300, 75);
            // Change the response headers to output a JPEG image.
            this.Response.Clear();
            this.Response.ContentType = "image/jpeg";
            // Write the image to the response stream in JPEG format.
            ci.Image.Save(this.Response.OutputStream, ImageFormat.Jpeg);
            // Dispose of the CAPTCHA image object.
            ci.Dispose();
        }

        // Function to generate random string with Random class.
        private string GenerateRandomCode()
        {
            Random r = new Random();
            string s = "";
            for (int j = 0; j < 5; j++)
            {
                int i = r.Next(3);
                int ch;
                switch (i)
                {
                    case 1:
                        ch = r.Next(0, 9);
                        s = s + ch.ToString();
                        break;
                    case 2:
                        ch = r.Next(65, 90);
                        s = s + Convert.ToChar(ch).ToString();
                        break;
                    case 3:
                        ch = r.Next(97, 122);
                        s = s + Convert.ToChar(ch).ToString();
                        break;
                    default:
                        ch = r.Next(97, 122);
                        s = s + Convert.ToChar(ch).ToString();
                        break;
                }
                r.NextDouble();
                r.Next(100, 1999);
            }
            return s;
        }
    }
}





网页的ASP.NET部分没有添加任何内容。



KR



Nothing was added in the ASP.NET part of the webpage.

KR


这篇关于如何在特定面板中生成验证码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆