问题描述
大家好,
我真的不知道为什么我的page_load事件执行两次...
注册我的网站时,我已经放置了验证码图片
我正在调用JpegImage.aspx页面以加载图像的注册代码.
Hi guys,
I have really no clue why my page_load event executing twice...
I have placed captcha Image while registration of my WEBSITE
Registration code where I am calling JpegImage.aspx page to load the Image.
<asp:WizardStep Title="CAPTCHA" ID="wsCaptcha" runat="server">
<div class="divContainerBox">
<div class="divContainerRow">
<div class="divContainerCell">
<b><asp:Image runat="server" ImageUrl="../Images/CaptchaImage/JpegImage.aspx"></asp:Image></b>
</div>
<div class="divContainerRow">
<div class="divContainerTitle">
Please copy what you see in the image above into the box below.
</div>
</div>
<div class="divContainerRow">
<div class="divContainerCell">
<asp:TextBox ID="txtCaptcha" runat="server"></asp:TextBox>
</div>
</div>
</div>
</div>
</asp:WizardStep>
这是JpegImage.aspx的html代码:
This is the JpegImage.aspx''s html code:
<%@ Page language="c#" CodeFile="JpegImage.aspx.cs" AutoEventWireup="false" Inherits="jayee.DatingWeb.Images.CaptchaImage.JpegImage" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>JpegImage</title>
<meta name="GENERATOR" content="microsoft visual studio 7.0"/>
<meta name="CODE_LANGUAGE" content="c#"/>
<meta name="vs_defaultClientScript" content="JavaScript"/>
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"/>
</head>
<body>
<form id="_JpegImage" method="post" runat="server">
</form>
</body>
</html>
问题在于jpegImage.cs的以下page_load事件:
The problem is with this page_load event of jpegImage.cs:
public partial class JpegImage : Page
{
private readonly Random _random = new Random();
private IWebContext _webContext;
private void Page_Load(object sender, EventArgs e)
{
if (IsPostBack != true)
{
_webContext = ObjectFactory.GetInstance<IWebContext>();
_webContext.CaptchaImageText = GenerateRandomCode();
var ci = ObjectFactory.GetInstance<ICaptcha>();
ci.Text = _webContext.CaptchaImageText;
ci.Width = 200;
ci.Height = 50;
ci.FamilyName = "Century Schoobook";
Response.Clear();
Response.ContentType = "image/jpeg";
ci.Image.Save(Response.OutputStream, ImageFormat.Jpeg);
ci.Dispose();
}
}
private string GenerateRandomCode()
{
string s = "";
for (int i = 0; i < 6; i++)
s = String.Concat(s, _random.Next(10).ToString());
return s;
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
Load += Page_Load;
}
谁能帮我解决我做错的地方,为什么仅Firefox会给我带来麻烦.我观察到没有其他page_load
事件运行两次.
Can anyone please help where I was doing wrong why Firefox alone giving me trouble. I have observed no other page_load
events are running twice.
推荐答案
这篇关于Page_load事件仅在Firefox 3.6.6上执行两次(在IE和crome上正常工作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!