protected void OkButton_Click(object sender, EventArgs e) { if (IsValid) { if (Service.GetGameByName(GameNameTextBox.Text) != null) { CustomValidator cv = new CustomValidator(); cv.ErrorMessage = "Spelet finns redan"; cv.IsValid = false; Page.Validators.Add(cv); } else { try { int id; id = Service.NewGame(GameNameTextBox.Text, GameTextBox.Text); Gal.SaveCover(ImageFileUpload.PostedFile.InputStream, Convert.ToString(id) + ".jpg"); Session["a"] = true; if (!Directory.Exists(Convert.ToString(id))) { Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.GetData("APPBASE").ToString(), @"Pictures\" + id)); } Response.Redirect("spel/" + id); } catch (Exception) { CustomValidator cv = new CustomValidator(); cv.ErrorMessage = "Uppladningen misslyckades"; cv.IsValid = false; Page.Validators.Add(cv); } } } }
protected void BtnCreateEvent_Click(object sender, EventArgs e) { var author = this.User.Identity.GetUserId(); if (author == null) { var err = new CustomValidator(); err.IsValid = false; err.ErrorMessage = "You are not logged in!"; this.Page.Validators.Add(err); } var newEvent = new Event() { AuthorId = author, Description = this.tbDescription.Text, Name = this.tbName.Text, DateCreated = DateTime.Now, CategoryId = int.Parse(this.DropDownCategories.SelectedValue) }; if (!string.IsNullOrEmpty(this.dtEventStart.Text)) { DateTime startDate; if (DateTime.TryParse(this.dtEventStart.Text, out startDate)) { newEvent.DateTimeStarts = startDate; } } if (this.EventImage.HasFile) { string filename = Path.GetFileName(this.EventImage.FileName); var extension = filename.Substring(filename.LastIndexOf('.') + 1); if (!ValidationConstants.AllowedExtensions.Contains(extension)) { var err = new CustomValidator(); err.IsValid = false; err.ErrorMessage = "Please upload image with allowed extension (png/jpg/gif/bmp)!"; this.Page.Validators.Add(err); return; } var imagesPath = this.Server.MapPath("~/Public/EventImages/"); if (!Directory.Exists(imagesPath)) { Directory.CreateDirectory(imagesPath); } this.EventImage.SaveAs(imagesPath + filename); newEvent.ImageLocation = "/Public/EventImages/" + filename; } this.db.Events.Add(newEvent); this.db.SaveChanges(); this.Response.Redirect("~/Home"); }
protected void Button1_Click(object sender, EventArgs e) { Validate(); if (IsValid) { try { var filestream = FileUpload.FileContent; string fileName = Path.GetFileName(FileUpload.PostedFile.FileName); var saveimg = BlogicGallery.SaveImage(filestream, fileName); Session["Save"] = true; Response.Redirect("~/default.aspx?name="+Server.UrlEncode("/img/"+fileName)); } catch (Exception) { var error = new CustomValidator { IsValid = false, ErrorMessage = "Något har blivit fel prova igen" }; this.Page.Validators.Add(error); } } }
protected void LogInButton_Click(object sender, EventArgs e) { User user; user = Service.GetUser(NameTextBox.Text); if (user == null) { CustomValidator cv = new CustomValidator(); cv.ErrorMessage = "Fel användarnamn eller lösenord"; cv.IsValid = false; Page.Validators.Add(cv); } else if (user.Password == PasswordTextBox.Text) { Label1.Text = user.UserName; LogInButton.Visible = false; RgistertButton.Visible = false; LogOutButton.Visible = true; NameTextBox.Visible = false; PasswordTextBox.Visible = false; Session["user"] = user; } else { CustomValidator cv = new CustomValidator(); cv.ErrorMessage = "Fel användarnamn eller lösenord"; cv.IsValid = false; Page.Validators.Add(cv); } }
// The id parameter name should match the DataKeyNames value set on the control public void PatientFormView_UpdateItem(int PatientID) { try { var patient = Service.GetPatient(PatientID); if (patient == null) { CustomValidator cv = new CustomValidator(); cv.ErrorMessage = "Patiensen kunde inte hittas"; cv.IsValid = false; Page.Validators.Add(cv); return; } if (TryUpdateModel(patient)) { Service.UpdatePatient(patient); Session["a"] = "Patienten har Ändrats!!!"; Response.Redirect(GetRouteUrl("PatientDetails", new { id = patient.PatientID })); } } catch { CustomValidator cv = new CustomValidator(); cv.ErrorMessage = "Ett fel inträffade när patienten skulle skulle uppdateras"; cv.IsValid = false; Page.Validators.Add(cv); } }
protected void UploadButton_Click(object sender, EventArgs e) { if (IsValid) { if (FileUpload.HasFile) { try { var name = Gallery.SaveImage(FileUpload.FileContent, FileUpload.FileName); Response.Redirect(String.Format("?img={0}{1}", name, "&Success=true")); } catch { CustomValidator message = new CustomValidator(); message.IsValid = false; message.ErrorMessage = "Något gick fel vid uppladdningen av din fil :<"; this.Page.Validators.Add(message); SuccessLabel.Visible = false; } } else { throw new ArgumentException(); } } }
protected void Login_Click(object sender, EventArgs e) { using (Database db = new MySqlDatabase()) { if (db.AdminLoginAuthentication(Email.Text.Trim(), Password.Text.Trim())) { Session["AdminLogin"] = Email.Text.Trim(); Response.Redirect("ManagePages.aspx"); } else { CustomValidator CustomValidatorCtrl = new CustomValidator(); CustomValidatorCtrl.IsValid = false; CustomValidatorCtrl.ValidationGroup = "LoginUserValidationGroup"; CustomValidatorCtrl.ErrorMessage = "Login Failed !"; this.Page.Form.Controls.Add(CustomValidatorCtrl); Session.Remove("AdminLogin"); } } }
protected void Page_Load(object sender, EventArgs e) { lnkAddUpSell.Click += new EventHandler(lnkAddUpSell_Click); i = 1; while (i <= upSellProducts) { TextBox txt = new TextBox(); txt.ID = "txtUpSellAddition" + i; plhUpSellAdditions.Controls.Add(txt); CustomValidator upCustomValidator = new CustomValidator(); upCustomValidator.ControlToValidate = txt.ID; upCustomValidator.Enabled = true; upCustomValidator.EnableViewState = true; upCustomValidator.SetFocusOnError = true; upCustomValidator.Text = "This is not a valid product"; upCustomValidator.ErrorMessage = "A upsell product you added is invlaid."; upCustomValidator.ServerValidate += RelatedProductValidation; plhUpSellAdditions.Controls.Add(upCustomValidator); LiteralControl l = new LiteralControl(); l.Text = "<br/><br/>"; plhUpSellAdditions.Controls.Add(l); i++; } if (product.UpSellList.Count > 0) { rptUpSell.DataSource = product.UpSellList; rptUpSell.DataBind(); } }
//after inserting new invoice protected void InvoiceDetailsView_ItemInserted(object sender, DetailsViewInsertedEventArgs e) { if (e.Exception != null) { var customValidator = new CustomValidator(); customValidator.IsValid = false; customValidator.ErrorMessage = "Save failed: " + e.Exception.InnerException.Message; customValidator.ValidationGroup = "sum"; Page.Validators.Add(customValidator); e.ExceptionHandled = true; } else { int rowcount = e.AffectedRows; if (rowcount == -1) { string name = e.Values["Name"].ToString(); MsgLiteral.Text = "Success"; alertLabel.Text = "Invoice of " + name + " has been saved"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "ShowAlertModal();", true); //update the order(converted to true) thats invoice has been created.. long orderID = Convert.ToInt64(Session["OrderID"]); orderBL.UpdateConvertOrder(orderID); } } //ShowAlertModal(); MiniInvoiceFormView.DataBind(); MiniInvoiceDetailsView.DataBind(); InvoiceGridView.DataBind(); MiniInvoiceUpdatePanel.Update(); Session["EditInvoiceID"] = 0; Session["EditOrderID"] = 0; InvoiceDetailsView.DataBind(); }
protected void btnCrear_Click(object sender, EventArgs e) { try { if (personaServicio.ExisteNifPersona(txtNif.Text)) { CustomValidator err = new CustomValidator(); err.IsValid = false; err.ErrorMessage = "Ya existe una persona con el nif especificado"; Page.Validators.Add(err); return; } else { var personaModelo = new PersonaModelo(); personaModelo.NifPersona = txtNif.Text; personaModelo.Nombres = txtNombre.Text; personaModelo.Apellidos = txtApellidos.Text; personaModelo.Direccion = txtDireccion.Text; personaServicio.Crear(personaModelo); Response.Redirect("Index.aspx", true); } } catch (Exception) { CustomValidator err = new CustomValidator(); err.IsValid = false; err.ErrorMessage = "Ocurrio un error al insertar el registro"; Page.Validators.Add(err); } }
public MultipleSelectControl(MultipleSelect item, RepeatDirection direction) { this.item = item; l = new Label(); l.Text = item.Title; l.CssClass = "label"; l.AssociatedControlID = item.Name; this.Controls.Add(l); list = new CheckBoxList(); list.RepeatDirection = direction; list.ID = item.Name; list.CssClass = "alternatives"; list.DataSource = item.GetChildren(); list.DataTextField = "Title"; list.DataValueField = "ID"; list.DataBind(); this.Controls.Add(list); if (item.Required) { cv = new CustomValidator { Display = ValidatorDisplay.Dynamic, Text = "*" }; cv.ErrorMessage = item.Title + " is required"; cv.ServerValidate += (s, a) => a.IsValid = !string.IsNullOrEmpty(AnswerText); cv.ValidationGroup = "Form"; this.Controls.Add(cv); } }
protected void CallDetailsObjectDataSource_Updated(object sender, ObjectDataSourceStatusEventArgs e) { if (e.Exception != null) { var customValidator = new CustomValidator(); customValidator.IsValid = false; customValidator.ErrorMessage = "Update failed: " + e.Exception.InnerException.Message; customValidator.ValidationGroup = "sum"; Page.Validators.Add(customValidator); e.ExceptionHandled = true; } else { CallListUpdatePanel.Update(); MiniDetailBasicUpdatePanel.Update(); CallDetailsView.DataBind(); this.CallListGridView.DataBind(); this.CallListGridView.SelectedIndex = -1; this.CallMiniDetailFormView.DataBind(); this.CallMiniMoreDetailsView.DataBind(); MessageLiteral.Text = "Success </br></br> <p> Call has been successfully updated <br/> "; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "ShowAlertModal();", true); CallDetailsView.ChangeMode(DetailsViewMode.Insert); Session["EditCallID"] = 0; } }
protected void AccountDetailsView_ItemInserted(object sender, DetailsViewInsertedEventArgs e) { long accountId = Convert.ToInt64(Session["AccountID"]); if (e.Exception != null) { var customValidator = new CustomValidator(); customValidator.IsValid = false; customValidator.ErrorMessage = "Insert failed: " + e.Exception.InnerException.Message; customValidator.ValidationGroup = "avs"; Page.Validators.Add(customValidator); e.ExceptionHandled = true; } else { if (accountId > 0) { AccountGridView.DataBind(); string accountName = e.Values["Name"].ToString(); TextBox AccountName = OpportunityDetailsView.FindControl("AccountNameTextBox") as TextBox; AccountName.Text = accountName; AccountList.Update(); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "CloseModals(['BodyContent_ModalPanel1','BodyContent_ModalPanel291']);", true); } } }
private void CheckForEfExceptions(ObjectDataSourceStatusEventArgs e, string function) { if (e.Exception.InnerException is DbUpdateConcurrencyException) { var concurrencyExceptionValidator = new CustomValidator { IsValid = false, ErrorMessage = "The record you attempted to edit or delete was modified by another " + "user after you got the original value. The edit or delete operation was canceled " + "and the other user's values have been displayed so you can " + "determine whether you still want to edit or delete this record." }; Page.Validators.Add(concurrencyExceptionValidator); e.ExceptionHandled = true; } else if (e.Exception.InnerException is DbEntityValidationException) { var concurrencyExceptionValidator = new CustomValidator(); concurrencyExceptionValidator.IsValid = false; StringBuilder errors = new StringBuilder(); foreach (var err in ((DbEntityValidationException)e.Exception.InnerException).EntityValidationErrors) { foreach (var msg in err.ValidationErrors) { var validator = new CustomValidator(); validator.IsValid = false; validator.ErrorMessage = msg.ErrorMessage; Page.Validators.Add(validator); e.ExceptionHandled = true; } } } }
public static void AddValidationSummary(this Page page, string errorMessage) { var validator = new CustomValidator(); validator.IsValid = false; validator.ErrorMessage = errorMessage; page.Validators.Add(validator); }
protected void InsertValidationErrorMessage(string message) { CustomValidator tempValidator = new CustomValidator(); tempValidator.IsValid = false; tempValidator.Display = ValidatorDisplay.None; tempValidator.ErrorMessage = message; Page.Form.Controls.Add(tempValidator); }
private void CreateErrorMsg(string message) { CustomValidator err = new CustomValidator(); err.IsValid = false; err.ErrorMessage = message; Page.Validators.Add(err); return; }
/// <summary> /// Initializes a new instance of the <see cref="BirthdayPicker"/> class. /// </summary> public BirthdayPicker() : base() { CustomValidator = new CustomValidator(); CustomValidator.ValidationGroup = this.ValidationGroup; HelpBlock = new HelpBlock(); WarningBlock = new WarningBlock(); }
/// <summary> /// Initializes a new instance of the <see cref="RockCheckBoxList"/> class. /// </summary> public RockCheckBoxList() : base() { CustomValidator = new CustomValidator(); CustomValidator.ValidationGroup = this.ValidationGroup; HelpBlock = new HelpBlock(); WarningBlock = new WarningBlock(); }
public void DisplayCustomMessageInValidationSummary(string message) { CustomValidator CustomValidatorCtrl = new CustomValidator(); CustomValidatorCtrl.IsValid = false; CustomValidatorCtrl.Visible = false; CustomValidatorCtrl.ErrorMessage = message; Control form=this.Page.FindControl("form1"); form.Controls.Add(CustomValidatorCtrl); }
protected void Connection_Click(object sender, EventArgs e) { if (IsValid) { SqlConnection cnx = new SqlConnection("data source=.;initial catalog=ECommerce_DB;integrated security=yes"); SqlCommand cmd = new SqlCommand(); cmd.Connection = cnx; cmd.CommandText = "select count(*) from Client where login=@p1 and pwd=@p2 and enabled=1"; cmd.Parameters.Add("@p1", SqlDbType.VarChar).Value = login.Text; cmd.Parameters.Add("@p2", SqlDbType.VarChar).Value = pwd.Text; cnx.Open(); int nb = (int)cmd.ExecuteScalar(); cmd.CommandText = "select count(*) from Client where login=@p1 and pwd=@p2 "; int nb2 = (int)cmd.ExecuteScalar(); if (nb == 1) { if (CheckBox1.Checked) { HttpCookie cookie; cookie = new HttpCookie("VinciEAnnence"); cookie.Values.Add("login", login.Text); Response.Cookies.Add(cookie); } else { Session["login"] = login.Text; } Response.Redirect("Accueil.aspx"); } else {CustomValidator val = new CustomValidator(); val.IsValid = false; String errmsg = "Combinaison Nom utilisateur/mot de passe incorrecte"; if (nb2 == 1) { errmsg = "Veuillez valider votre adresse courriel!"; } val.ErrorMessage = errmsg; this.Page.Validators.Add(val); } } }
protected void DepartmentsObjectDataSource_Inserted(object sender, ObjectDataSourceStatusEventArgs e) { if (e.Exception != null) { if (e.Exception.InnerException is DuplicateAdministratorException) { var duplicateAdministratorValidator = new CustomValidator(); duplicateAdministratorValidator.IsValid = false; duplicateAdministratorValidator.ErrorMessage = "Insert failed: " + e.Exception.InnerException.Message; Page.Validators.Add(duplicateAdministratorValidator); e.ExceptionHandled = true; } } }
protected virtual Control AddCustomValidator(Control container, Control editor) { var cv = new CustomValidator(); cv.ID = Name + "_rev"; cv.ControlToValidate = editor.ID; cv.Display = ValidatorDisplay.Dynamic; cv.Text = GetLocalizedText("ValidationText") ?? ValidationText; cv.ErrorMessage = GetLocalizedText("ValidationMessage") ?? ValidationMessage; cv.ServerValidate += OnServerValidate; container.Controls.Add(cv); return cv; }
protected void OfficeAssignmentsObjectDataSource_Updated(object sender, ObjectDataSourceStatusEventArgs e) { if (e.Exception != null) { var concurrencyExceptionValidator = new CustomValidator(); concurrencyExceptionValidator.IsValid = false; concurrencyExceptionValidator.ErrorMessage = "The record you attempted to " + "update has been modified by another user since you last visited this page. " + "Your update was canceled to allow you to review the other user's " + "changes and determine if you still want to update this record."; Page.Validators.Add(concurrencyExceptionValidator); e.ExceptionHandled = true; } }
private void SetUpCustomValidator(CustomValidator validator) { if (Column.DataTypeAttribute != null) { switch (Column.DataTypeAttribute.DataType) { case DataType.Date: case DataType.DateTime: case DataType.Time: validator.Enabled = true; DateValidator.ErrorMessage = HttpUtility.HtmlEncode(Column.DataTypeAttribute.FormatErrorMessage(Column.DisplayName)); break; } } else if (Column.ColumnType.Equals(typeof(DateTime))) { validator.Enabled = true; DateValidator.ErrorMessage = HttpUtility.HtmlEncode(DefaultDateAttribute.FormatErrorMessage(Column.DisplayName)); } }
private void CheckForOptimisticConcurrencyException(ObjectDataSourceStatusEventArgs e, string function) { if (e.Exception.InnerException is OptimisticConcurrencyException) { var concurrencyExceptionValidator = new CustomValidator(); concurrencyExceptionValidator.IsValid = false; concurrencyExceptionValidator.ErrorMessage = "The record you attempted to edit or delete was modified by another " + "user after you got the original value. The edit or delete operation was canceled " + "and the other user's values have been displayed so you can " + "determine whether you still want to edit or delete this record."; Page.Validators.Add(concurrencyExceptionValidator); e.ExceptionHandled = true; } }
public IEnumerable<IndividueltArbete.Model.Doctor> PatientListView_GetData() { try { return Service.GetpDoctors(); } catch { CustomValidator cv = new CustomValidator(); cv.ErrorMessage = "Ett fel inträffade när läkarna skulle hämtas"; cv.IsValid = false; Page.Validators.Add(cv); return null; } }
public IndividueltArbete.Model.Patient PatientFormView_GetItem([RouteData]int id) { try { return Service.GetPatient(id); } catch { CustomValidator cv = new CustomValidator(); cv.ErrorMessage = "Ett fel inträffade när patienten skulle skulle hämtas"; cv.IsValid = false; Page.Validators.Add(cv); return null; } }
protected override WebCntrls.BaseValidator CreateWebValidator() { _webCustomValidator = new WebCntrls.CustomValidator(); // Adding wrapper event handlers for event properties exposed by // the aggregated control. For more details about the mechanism, // please see the comment in the constructor of // Mobile.UI.AdRotator. ServerValidateEventHandler eventHandler = new ServerValidateEventHandler(WebServerValidate); _webCustomValidator.ServerValidate += eventHandler; return(_webCustomValidator); }
/// <include file='doc\CustomValidator.uex' path='docs/doc[@for="CustomValidator.CreateWebValidator"]/*' /> protected override WebCntrls.BaseValidator CreateWebValidator() { _webCustomValidator = new WebCntrls.CustomValidator(); // Adding wrapper event handlers for event properties exposed by // the aggregated control. For more details about the mechanism, // please see the comment in the constructor of // Mobile.UI.AdRotator. ServerValidateEventHandler eventHandler = new ServerValidateEventHandler(WebServerValidate); _webCustomValidator.ServerValidate += eventHandler; return _webCustomValidator; }
public IEnumerable<DoctorType> DoctorTypeDropDownList_GetData() { try { return Service.GetDoctorType(); } catch { CustomValidator cv = new CustomValidator(); cv.ErrorMessage = "Ett fel inträffade när läkartyperna skulle hämtas"; cv.IsValid = false; Page.Validators.Add(cv); return null; } }