如何使用文本框属性的文本更改 [英] how do use On text change of textbox property

查看:90
本文介绍了如何使用文本框属性的文本更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码在按钮点击方法中正常工作。

i have following code that work fine in button click method.

<asp:TextBox CssClass="form-control" runat="server" MaxLength="7" ID="txtRollNo" />
                    <asp:RegularExpressionValidator Display="Dynamic" ValidationGroup="vgEmployee" runat="server" ID="revRollNo" ControlToValidate="txtRollNo" Requried="required" ValidationExpression="^[A-Za-z0-9,/\,-]+$" ErrorMessage="Number,Alpha,- and / only" ></asp:RegularExpressionValidator>
                     <asp:Button CssClass="btn btn-green btn-block " ID="btn_Click"  Width="150" runat="server" OnClick="btn_Click_Click" CausesValidation="True" Text="Check Employee"/>    







Code Behind是




Code Behind is

protected void btn_Click_Click(object sender, EventArgs e)
       {
           if (!string.IsNullOrEmpty(txtRollNo.Text))
           {
               var employee = _service.GetEmployee(txtRollNo.Text);
               if (employee != null)
               {
                   MsgLitteral.ShowNotificationInline("Record Found", true);
               }
               else
               {
                   MsgLitteral.ShowNotificationInline("Record not Found", false);
               }
           }
       }




i want to change it as when roll no is entered by user and move to next field message is dosplayed,weather it is in database or not

推荐答案

ErrorMessage = 数字,Alpha, - 和/或 > < / asp:RegularExpressionValidator >
< asp:按钮 < span class =code-attribute> CssClass = btn btn-green btn-block ID = btn_Click 宽度 < span class =code-keyword> = 150 runat = server OnClick = btn_Click_Click CausesValidation = True 文字 = 检查员工 / >
" ErrorMessage="Number,Alpha,- and / only" ></asp:RegularExpressionValidator> <asp:Button CssClass="btn btn-green btn-block " ID="btn_Click" Width="150" runat="server" OnClick="btn_Click_Click" CausesValidation="True" Text="Check Employee"/>







Code Behind是




Code Behind is

protected void btn_Click_Click(object sender, EventArgs e)
       {
           if (!string.IsNullOrEmpty(txtRollNo.Text))
           {
               var employee = _service.GetEmployee(txtRollNo.Text);
               if (employee != null)
               {
                   MsgLitteral.ShowNotificationInline("Record Found", true);
               }
               else
               {
                   MsgLitteral.ShowNotificationInline("Record not Found", false);
               }
           }
       }




i want to change it as when roll no is entered by user and move to next field message is dosplayed,weather it is in database or not


尝试添加文本框已更改事件并设置AutoPostBack =真正的用于文本框控件。





Try adding text box changed event with setting AutoPostBack="True" for the text box control.


<asp:TextBox CssClass="form-control" runat="server" MaxLength="7" ID="txtRollNo" OnTextChanged="txtRollNo_TextChanged" AutoPostBack="True"  />







protected void txtRollNo_TextChanged(object sender, EventArgs e)
      {
          var employee = _service.GetEmployee(txtRollNo.Text);
          if (employee != null)
          {
            MsgLitteral.ShowNotificationInline("Record Found", true);
          }
          else
          {
             MsgLitteral.ShowNotificationInline("Record not Found", false);
          }
      }

  }


这篇关于如何使用文本框属性的文本更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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