1
Answer

How Do I Checked If Employee Exist Or Not

Sajid Hussain

Sajid Hussain

10y
598
1

i have a web application,in which a user information form.i want to check if employee exist or not when user a user roll no which is also PK.
THAT may be by using on text change or using button click event
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"/>
and codebehind is

 protected void btn_Click_Click(object sender, EventArgs e)         {             if (!string.IsNullOrEmpty(txtRollNo.Text))             {                 Employee emp = _service.GetAllEmployee().Where(x => x.Employee_Id==Employee.Cnic).LastOrDefault();                   if (emp != null)                 {                     MsgLitteral.ShowNotificationInline("Record Found", false);                   }                 else                 {                     MsgLitteral.ShowNotificationInline("Record Not Found", false);                 }               }         }
Problem is that when i press the button is always return Record found,although there is no record against that employee Id.
Answers (1)