protected void btnSaveData_Click(object sender, EventArgs e) { try { if (hidID.Value == "")//Create { LoginUser objEmp = new LoginUser(); objEmp.UserCode = userCode.Value; objEmp.Password = password.Value; objEmp.DepartmentId = Convert.ToInt32(ddlDepartment.SelectedValue); objEmp.UserProfileId = Convert.ToInt32(ddlProfile.SelectedValue); using (LoginService lgService = new LoginService()) { int retVal = lgService.AddLoginUser(objEmp); if (retVal == -1) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "key", "ShowAlert('danger','HR User already present with same usercode for same department.');", true); } else { FillUserList(); } } } else if (hidID.Value != "") { LoginUser objEmp = new LoginUser(); objEmp.UserCode = userCode.Value; objEmp.Password = password.Value; objEmp.DepartmentId = Convert.ToInt32(ddlDepartment.SelectedValue); objEmp.UserProfileId = Convert.ToInt32(ddlProfile.SelectedValue);; objEmp.Id = Convert.ToInt32(hidID.Value); using (LoginService lgService = new LoginService()) { int retVal = lgService.EditLoginUser(objEmp); if (retVal == -1) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "key", "ShowAlert('danger','HR User already present with same usercode for same department.');", true); } else { FillUserList(); } } hidID.Value = ""; } upCreateLoginUser.Update(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "key", "ShowAlert('success','Saved Successfully.');ResetCreateBox();", true); } catch (Exception ex) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "key", "ShowAlert('danger','Error occurred in current operation!! - " + ex.Message + "');", true); } }