Skip to content
| Marketplace
Sign in
Visual Studio>Controls>验证码控件
验证码控件

验证码控件

ThankfulHeart

|
3,765 installs
| (1) | Free
专门用于注册页面开发的注册码控件
Download

This control is used for registration form to generate random numbers(when you cannot see the verification codes clearly, you can just click the image to refresh it, and it's easily used).

Pleae change the suffix name from "exe" to "zip" after downloading it, and unzip to use that.

【Key Properties】

1)Number:Set random number's maximun number, no more than 10 or less than 1.

2)ValidationGroupName:Set a union name for validation group, used when clicking "Register" button to submit

【For WebForm】

1)After unzipping this, please drag and drop the dll into the ToolBox and drag and drop it onto the page.

2)Set all the validation controls' validationGroupName to the same name(In default, the control's ValidationGroup name is “ValidationCode”)。

3)Do configuration in the web.config in bold:

<configuration>
<system.web>
<httpHandlers>
<add path="DongWeiValidate.req" verb="*" type="VaidationCode.ImageCreate"/>
</httpHandlers>
<compilation debug="true" targetFramework="4.0" />
</system.web>
</configuration>

4)This is the whole aspx page's code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CSharp.Default" %>

<%@ Register Assembly="VaidationCode" Namespace="VaidationCode" TagPrefix="cc1" %>
<!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>
<script language="javascript" type="text/javascript">
// <![CDATA[

function btnClear_onclick() {
document.forms[0].reset();
}

// ]]>
</script>
</head>
<body>
<form id="form1" runat="server">
<p>
Name:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
Display="Dynamic" ErrorMessage="RequiredFieldValidator" ForeColor="Red" ValidationGroup="ValidationCode">*</asp:RequiredFieldValidator>
</p>
<p>
Input your Validation Code<cc1:ValidationCode ID="ValidationCode1" runat="server" />
</p>
<p>
<asp:Button ID="Button1" runat="server" Text="Submit" ValidationGroup="ValidationCode"
OnClick="Button1_Click" />
<input id="btnClear" type="button" value="Reset" onclick="return btnClear_onclick()" /></p>
</form>
</body>
</html>

5)Cs-codes(code-behind):

protected void Button1_Click(object sender, EventArgs e)
{
if (ValidationCode1.IsPassed()) //Check whether what you've inputted matches the created one
{
Response.Redirect("http://www.baidu.com"); //If OK, jump to some other page, please use your own logic codes...
}
else
{
ClientScript.RegisterClientScriptBlock(GetType(), "jskey", "alert('Input number is wrong!');", true);
}
}

【For MVC】

1)Refer the dll file into the "Reference……" gray folder.

2)Do what you can see in the web.config as "For WebForm".

3)In View the generated codes would be shown, click it to change it dynamically.

<img src="DongWeiValidate.req?reqNo=5" id="imgId" title="Cannot see? Click to refresh..." onclick="document.getElementById(imgId).src='DongWeiValidate.req?reqNo=5&rnd='+Math.random()" style="cursor:pointer"/>

4)In some Controller you can use "context.Session["correctcode"]" to compare with the rendered inputted code.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft