Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8431561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:53:17+00:00 2026-06-10T05:53:17+00:00

One of my forms has a captcha. I am forced to use this captcha

  • 0

One of my forms has a captcha.

I am forced to use this captcha since there’s a lot of code already written before me.

This way is simple:

There is an ashx file. An image will be created using that file. At the same time, that file will create a session with the same value from the image.

Upon submission, the code will check whether they are the same. If so, continue. if not, return.

Upon page refresh, the captcha will update.

Then I need to add in ajax update panel as the requirement.

Then the captcha is still working fine in chrome and safari but it is not refreshing when the page loads again in IE and firefox.

I created a simple page just for captcha

aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs" Inherits="Default7" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <img height="30" alt="" src="Handler.ashx" width="80"><br>
            <asp:Button ID="btnSubmit" runat="server" Text="Submit" 
                onclick="btnSubmit_Click"/>
        </ContentTemplate>
    </asp:UpdatePanel>
    <div>

    </div>
    </form>
</body>
</html>


aspx.cs

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

public partial class Default7 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {

    }
}

handler.ashx 

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Web.SessionState;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Text;

public class Handler : IHttpHandler,System.Web.SessionState.IRequiresSessionState {
    public void ProcessRequest(HttpContext context)
        {
            Bitmap objBMP = new System.Drawing.Bitmap(60, 20);
            Graphics objGraphics = System.Drawing.Graphics.FromImage(objBMP);
            //objGraphics.Clear(Color.Blue);

            objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;

            //' Configure font to use for text
            Font objFont = new Font("Arial", 8, FontStyle.Bold);
            string randomStr = "";
            int[] myIntArray = new int[5];
            int x;

            //That is to create the random # and add it to our string
            Random autoRand = new Random();

            for (x = 0; x < 5; x++)
            {
                myIntArray[x] = System.Convert.ToInt32(autoRand.Next(0, 9));
                randomStr += (myIntArray[x].ToString());
            }

            randomStr = GetRandomString();

            //This is to add the string to session cookie, to be compared later
            context.Session.Add("randomStr", randomStr);



            //' Write out the text
            objGraphics.DrawString(randomStr, objFont, Brushes.White, 3, 3);

            //' Set the content type and return the image
            context.Response.ContentType = "image/GIF";
            objBMP.Save(context.Response.OutputStream, ImageFormat.Gif);

            objFont.Dispose();
            objGraphics.Dispose();
            objBMP.Dispose();

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        private string GetRandomString()
        {
            string[] arrStr = "A,B,C,D,1,2,3,4,5,6,7,8,9,0".Split(",".ToCharArray());
            string strDraw = string.Empty;
            Random r = new Random();
            for (int i = 0; i < 5; i++)
            {
                strDraw += arrStr[r.Next(0, arrStr.Length - 1)];
            }
            return strDraw;
        }


}

Any idea?


I got the answer now.

change image control to server control.

and in code behind change the image source with current date time

<img height="30" alt="" src="/Handler.ashx" width="80" runat="server" id="imgCaptcha">

imgCaptcha.Src = "Handler.ashx?dt=" + DateTime.Now.ToString();

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:53:19+00:00Added an answer on June 10, 2026 at 5:53 am

    change image control to server control.

    and in code behind change the image source with current date time

    <img height="30" alt="" src="/Handler.ashx" width="80" runat="server" id="imgCaptcha">
    
    imgCaptcha.Src = "Handler.ashx?dt=" + DateTime.Now.ToString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I noticed that my Designer.vb file of one of my forms has a lot
I have a Windows application that has 2 Forms . From one form I
The recent update (V 20.x) of Chrome has broken one of my forms with
I'm maintaining a Windows app that has multiple forms in the one window (
I have written a simple CRUD form which has one select list. However the
System.Windows.Forms.Form has only one scroll event- Scroll , but it is necessary to recognize
I have three pages that has forms on them. They all lead to one
I'm trying to set several forms in one page. Each has textarea with TinyMCE
There is a similar question at WPF versus Windows Forms which has some good
I'm trying to use mustache templates to render very simple forms, however, one of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.