protected void btnSubmit_Click(object sender, EventArgs e) { if (Page.IsValid) { if (String.IsNullOrEmpty(txtPassword.Text)) { lblVerifyError.Visible = true; lblVerifyError.Text = "Password field cannot be empty"; ScriptManager.RegisterStartupScript(this, GetType(), "emailPopup", "document.body.style.padding = '0';$('.modal-backdrop').remove();$('#emailModal').modal('show');", true); return; } if (!VerifyLoginUser(Context.User.Identity.Name, txtPassword.Text)) { lblVerifyError.Visible = true; lblVerifyError.Text = "Incorrect password!"; ScriptManager.RegisterStartupScript(this, GetType(), "emailPopup", "document.body.style.padding = '0';$('.modal-backdrop').remove();$('#emailModal').modal('show');", true); return; } ScriptManager.RegisterStartupScript(this, GetType(), "emailPopup", "document.body.style.padding = '0';$('.modal-backdrop').remove();$('#emailModal').modal('hide');", true); var stationaries = (List <RequestDTO>)Session["ItemDetails"]; //TODO: change back to userName to session["userName"] string userName = Context.User.Identity.Name; string deptCode = ec.GetDeptCodeByUserName(userName); string requestcode = ec.AddRequest(userName, deptCode, stationaries); //send email string fromEmail = emailController.GetUserEmail(Context.User.Identity.Name); string password = txtPassword.Text; string username = Context.User.Identity.Name; try { emailController.NewRequestSendEmail(fromEmail, password, username, requestcode); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Request have been successfully created! Email notifications have been sent successfully!');window.location ='DeptRequisitionList';", true); } catch (Exception ex) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Request have been successfully created! However an error has occurred when sending email!');window.location ='DeptRequisitionList';", true); } //clear Session["ItemDetails"] = null; BindGrid(); //show success message and Request Code System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(@"<script type='text/javascript'>"); sb.Append("$('#myModal').modal('show');"); sb.Append("$('#lblRequestCode').text('" + requestcode + "');"); sb.Append(@"</script>"); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "none", sb.ToString(), false); } }