Joke Collection Website - Blessing messages - How to refresh the verification code in ASP.NET?
How 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.
- Related articles
- What's the message of login guardian?
- Call for "touching messages" (mobile phones)
- How to set the night mode of the mobile phone?
- Quit your job halfway and send text messages.
- What are the "loans" mentioned by a large number of customers of the three major operators? What should I do if I am "loaned"?
- Bank of communications bank inquiry
- Blessing words for the newcomers who have just received the certificate.
- How to turn off QQ yellow diamond for telecom mobile phone?
- How to protect personal privacy in the era of big data?
- How to make SMS chat go on Three ways to make SMS chat go on.