C#中的验证控制 [英] Validation Control in C#

查看:50
本文介绍了C#中的验证控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经使用文本框创建了用户名,密码并确认了密码.我的查询是我们要输入的密码,如果没有输入,应该输入确认密码,否则应该显示错误.为此,应如何编写代码.

问候
Balamurugan

Hi,
I have created user name, password and confirm password using Textbox. My query is what we are typing in password we should type in confirm password if not it should shows errors. For this how should write the code.

Regards
Balamurugan

推荐答案

您可以使用 ASP.NET CompareValidator控件 [
You can use Compare Validator Control which allows you to compare the value entered by the user into an input control.

Look some more details: ASP.NET CompareValidator Control[^]

Try this code:
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" />

<asp:RequiredFieldValidator ID="req6" runat="server" ControlToValidate="txtPassword" Text="*" />

Confirm Password <asp:TextBox ID="txtPasswordC" runat="server" TextMode="Password" />

<asp:CompareValidator runat="server" ID="Comp1" ControlToValidate="txtPassword" ControlToCompare="txtPasswordC" Text="Password mismatch" />



这是相同的类似讨论:
在更改密码"屏幕中比较验证程序问题 [使用CompareValidator来检查密码字段并确认密码字段 [



Here is similar discussion on same:
Compare Validator Issue in Change Password Screen[^]
Use CompareValidator to check password field and confirm password field[^]


Try this:

public bool IsPasswordsEqual(string password1, string password2)
{
	if (password1.Equals(password2))
        {
		return true;
	}

	return false;
}


在提交按钮单击事件或ConfirmPassword文本框离开事件上使用此方法


use this method on submit button click event or confirmpassword textbox leave event
as

if(!IsPasswordsEqual(Textbox1.Text,TextBox2.Text))
{
    MessageBox.Show("Enter same password in both");
}


这篇关于C#中的验证控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆