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 528217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:57:51+00:00 2026-05-13T08:57:51+00:00

i write the code for captcha from the website, but when i run the

  • 0

i write the code for captcha from the website, but when i run the code it is working fine captcha image is coming but i place the textbox and a button but they are not visible only capctch image is displaying this is code check out

source code

<body>
<form id="form1" runat="server">

<IMG height="30" alt="" src="Turing.aspx"  style="width :120px;height:60px" /><br />
    <br />

    <asp:TextBox ID="TextBox1" runat="server" Visible ="true" ></asp:TextBox><br />
    <asp:Button ID="Button1" runat="server" Text="Button"  Visible ="true" />
</form>
</body>

Code behind:

protected void Page_Load(object sender, EventArgs e)
{

    getImage();
}

private void getImage()
{
    Bitmap objBMP = new System.Drawing.Bitmap(150,60);
    Graphics objGraphics = System.Drawing.Graphics.FromImage(objBMP);
    objGraphics.Clear(Color.IndianRed );
    objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
    Font objFont = new Font("Arial", 25, FontStyle.Italic );
    string randomStr = "";
    int[] myIntArray = new int[5];
    int x;
    Random autoRand = new Random();

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

    Session.Add("randomStr", randomStr);

    objGraphics.DrawString(randomStr, objFont, Brushes.NavajoWhite, 3, 3);
    Response.ContentType = "image/GIF";
    objBMP.Save(Response.OutputStream, ImageFormat.Gif);
    objFont.Dispose();
    objGraphics.Dispose();
    objBMP.Dispose();
}

protected void Button1_Click(object sender, EventArgs e)
{
    if (Session["randomStr"].ToString()==TextBox1 .Text .ToString ())
    {
        Response.Write("yes ok");
    }
    else
    {
        Response.Write("Not Inserted");
    }
}

but button and textbox is not visible when page executed

  • 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-05-13T08:57:51+00:00Added an answer on May 13, 2026 at 8:57 am

    You are highjacking the response and returning your generated image instead of the pages html with this line of code.

        objBMP.Save(Response.OutputStream, ImageFormat.Gif);
    

    A possible way around this is to instead save the image to the filesystem on the server and set the image src to point at this. However this will obviously result in a lot of image files which will have to be cleaned up with either a background process or when the captcha is submitted.

    A more elegant solution would be to use a HTTPHandler although you must ensure you reference IRequiresSessionState in order to save your value to session. You can now refer to this handler in the images source property:

    <IMG height="30" alt="" src="CaptchaHandler.ashx"  style="width :120px;height:60px" />
    

    [WebService(Namespace = “http://tempuri.org/“)]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    public class CaptchaHandler : IHttpHandler, IRequiresSessionState 
    {
    
        public void ProcessRequest(HttpContext context)
        {
            Bitmap objBMP = new System.Drawing.Bitmap(150, 60);
            Graphics objGraphics = System.Drawing.Graphics.FromImage(objBMP);
            objGraphics.Clear(Color.IndianRed);
            objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
            Font objFont = new Font("Arial", 25, FontStyle.Italic);
            string randomStr = "";
            int[] myIntArray = new int[5];
            int x;
            Random autoRand = new Random();
    
            for (x = 0; x < 5; x++)
            {
                myIntArray[x] = System.Convert.ToInt32(autoRand.Next(0, 9));
                randomStr += (myIntArray[x].ToString());
            }
    
            context.Session.Add("randomStr", randomStr);
    
            objGraphics.DrawString(randomStr, objFont, Brushes.NavajoWhite, 3, 3);
            context.Response.ContentType = "image/GIF";
            objBMP.Save(context.Response.OutputStream, ImageFormat.Gif);
            objFont.Dispose();
            objGraphics.Dispose();
            objBMP.Dispose(); 
    
        }
    
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
    

    Edit: I meant IRequiresSessionState not IReadOnlySessionState

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 430k
  • Answers 430k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Software written and used within the same company. May 15, 2026 at 2:00 pm
  • Editorial Team
    Editorial Team added an answer since this always contains a reference to the object of… May 15, 2026 at 2:00 pm
  • Editorial Team
    Editorial Team added an answer You can read about page output caching on MSDN: http://msdn.microsoft.com/en-us/library/ms178597.aspx… May 15, 2026 at 2:00 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.