Joke Collection Website - Blessing messages - How to refresh the verification code in ASP.NET?

How to refresh the verification code in ASP.NET?

Click to refresh the verification code in asp.net:

The sample code is as follows:

& lt script & gt

Function fGetCode ()

{

document . getelementbyid(“get code“)。 src =“ASP . net . aspx+math . random();

}

& lt/script & gt;

& lt tag> verification code

& ltASP:TextBox ID =“txt _ checkCode“runat =“server“Width =“ 178 px“& gt; & lt/ASP:TextBox & gt;

& ltimg src = "default2.aspx" alt = "Can't see clearly? “id =“get code“/& gt。 & lta

href =“JavaScript:fGetCode()“& gt; Replace verification code

asp.net.aspx

Use the system;

Use the system. Assemble. Generics;

Use the system. Linq

Use the system. Web

Use the system. Web . UI

Use the system. Web.UI.WebControls

Use the system. Drawing;

Online examination system for students

{

Public partial classes AjaxAutoCode: System. Web interface

{

//Verification number

Public string authcode = string. Empty;

Protected void Page_Load (object sender, EventArgs e)

{

# regionThe first method of generating verification code

Random Random = new Random();

Verification code = random. Next (1111,9999). ToString();

//Build a picture

Bitmap image = new bitmap (authorization code. Length *12,25);

//Create a canvas

Graph g = graph. FromImage;

attempt

{

G. transparent (color. White);

for(int I = 0; I & lt25; i++)

{

int x 1 = random。 Next (picture. Width);

Int x2 = random. Next (picture. Width);

int y 1 = random。 Next (picture. Height);

Int y2 = random. Next (picture. Height);

//A line connecting two points

G. new pen (color. Silver), x 1, y 1, x2, y2);

}

Font font = new font ("Arial", 12, FontStyle. Bold | FontStyle. Italic);

System. drawing 2d . lineargradientbrush brush = new

System. drawing . drawing 2d . lineargradientbrush(

New rectangle (0,0, image. Width, image. Height), color. Blue, color. Dark blue, 1.2f,

True);

G. Pull rope (verification code, font, brush, 2, 2);

//Draw the foreground noise of the picture.

for(int I = 0; I< 100; i++)

{

int x = random。 Next (picture. Width);

int y = random。 Next (picture. Height);

Image. set pixel(x,y,Color。 from argb(random。 next()));

}

G.DrawRectangle (new pen (color. Silver), 0, 0, image. Width-1, image. Height-1);

System. IO. memory flow ms = new system. IO . memory stream();

Image. Save (ms, system. drawing . imaging . imageformat . gif);

Ms. WriteTo (this. response . output stream);

ms . Close();

This. response . content type =“image/gif“;

}

finally

{

Image. dispose();

g.dispose();

}

# End area

}

}

}

Click "Can't read clearly" to change it, and fGetCode () will be called to request to regenerate the verification code.