Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i have following code that work fine in button click method.
ASP.NET
<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 is
C#
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
Posted

1 solution

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"  />


C#
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);
          }
      }

  }
 
Share this answer
 
Comments
Sajid227 29-Oct-14 4:42am    
thanx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900