通过后面的代码传递验证表达式 [英] Passing validation expression through code behind

查看:49
本文介绍了通过后面的代码传递验证表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在asp.net 3.5中工作.
我的要求是通过数据库动态检查密码长度,并显示带有验证控件而不带有标签的消息.另外,当控件从文本框控件移至按钮单击时,应显示消息.

目前,我正在单击按钮并在标签控件上显示消息.

下面是代码:

Hi all,

I am working in asp.net 3.5.
My requirement is to check password length dynamically through database and show message with validation control not with label. Also, message should be displayed when control move from textbox control instead on button click.

Presently i am doing this on button click and showing message on label control.

Below is the code:

If System.Text.RegularExpressions.Regex.IsMatch(txtnew_pwd.Text, ".*(?=.{" & ViewState("len") & ",}).*") = False Then
              lblmsg.Text = "Minimum Password Length Required: " & ViewState("len") & " " & "Character"
              Exit Sub
      End If



在上面的viewstate("len")包含所需的长度.

有人可以帮我吗?

谢谢



In above viewstate("len") contains length that is required.

Can anyone help me on this ?

Thanks

推荐答案

谢谢您的提问.您要显示带有验证控件而不带有标签的消息.因此,您需要使用类似下面的代码.

Thank you for your question. You want to show message with validation control not with label. So you need to use like bellow code.

protected void TextValidate(object source, ServerValidateEventArgs args)
{
   args.IsValid = (args.Value.Length >= 8);
}





<asp:textbox id=TextBox1 runat="server"></asp:textbox>
<asp:CustomValidator id="CustomValidator1" runat="server"

   OnServerValidate="TextValidate"

   ControlToValidate="TextBox1"

   ErrorMessage="Text must be 8 or more characters.">
</asp:CustomValidator>



通过使用此代码,您可以自己完成其余的工作.

谢谢,
Mamun



By using this code you do rest of the things yourself.

Thanks,
Mamun


按下另一个按钮并将代码编写为:
并使其在页面加载事件中的可见性为假.
我已经用C#和模糊的文本框完成了编码
VB的变化
Take another button and write code as:
and make it visibility false on page load event.
I have done coding in C# and on blur of textbox
change in VB
protected void Page_Load(object sender, EventArgs e)
{
  btnCheck.Visible=false;
    string handler = ClientScript.GetPostBackEventReference(this.btnCheck, "");
    textboxnamne.Attributes.Add("onblur", handler);

}


并在按钮上单击事件调用代码为


and on button click event call code as

protected void btnCheck_Click(object sender, EventArgs e)
   {
     <pre lang="vb">If System.Text.RegularExpressions.Regex.IsMatch(txtnew_pwd.Text, ".*(?=.{" & ViewState("len") & ",}).*") = False Then
              lblmsg.Text = "Minimum Password Length Required: " & ViewState("len") & " " & "Character"
              Exit Sub
      End If



}



}


这篇关于通过后面的代码传递验证表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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