Click here to Skip to main content
15,889,495 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
XML
<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>

This is the JpegImage.aspx's html code:
XML
<%@ 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>

The problem is with this page_load event of jpegImage.cs:
C#
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;
        }

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.
Posted
Updated 20-Jul-10 4:20am
v3

Hey mate, this is only a suggestion, add the ALT attribute to the Image Tag & try again then tell us.
 
Share this answer
 
Thanks for the reply

Did you mean to add Alternate Text attribute to ASP Image tag?
I think so and I did that. Still the same.

By the way I am getting one warning that in the wizard step I have used
ImageUrl as

<asp:Image runat="server" ImageUrl="../Images/CaptchaImage/JpegImage.aspx"></asp:Image>

but Resharper(visual studio companion) advising me that image url must be a Image not File.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900