问题描述
我使用了 [ ]在我的网站上实现验证码。
代码似乎工作正常,但验证码出现在另一个/空白页面上。
此外,使用下面的代码,但是当生成验证码时,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
推荐答案
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
这篇关于如何在特定面板中生成验证码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!