本文整理汇总了C#中System.Web.UI.WebControls.CustomValidator类的典型用法代码示例。如果您正苦于以下问题:C# CustomValidator类的具体用法?C# CustomValidator怎么用?C# CustomValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CustomValidator类属于System.Web.UI.WebControls命名空间,在下文中一共展示了CustomValidator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: OkButton_Click
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);
}
}
}
}
开发者ID:sslnustudent,项目名称:Projekt,代码行数:35,代码来源:NewGame.aspx.cs
示例2: BtnCreateEvent_Click
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");
}
开发者ID:team-voltron,项目名称:EventSystem,代码行数:60,代码来源:Create.aspx.cs
示例3: Button1_Click
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);
}
}
}
开发者ID:so222es,项目名称:1DV406,代码行数:26,代码来源:Default.aspx.cs
示例4: UploadButton_Click
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();
}
}
}
开发者ID:hk222gn,项目名称:vt14-2-1-galleriet,代码行数:26,代码来源:Default.aspx.cs
示例5: PatientFormView_UpdateItem
// 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);
}
}
开发者ID:sslnustudent,项目名称:vt14-3-1-individuellt-arbete,代码行数:31,代码来源:Edit.aspx.cs
示例6: LogInButton_Click
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);
}
}
开发者ID:sslnustudent,项目名称:Projekt,代码行数:30,代码来源:MasterPage.Master.cs
示例7: Login_Click
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");
}
}
}
开发者ID:nageshverma2003,项目名称:TrackProtectSource,代码行数:26,代码来源:AdminHome.aspx.cs
示例8: Page_Load
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();
}
}
开发者ID:xcrash,项目名称:cuyahogacontrib-Cuyahoga.Modules.ECommerce,代码行数:33,代码来源:UpSellEditor.ascx.cs
示例9: InvoiceDetailsView_ItemInserted
//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();
}
开发者ID:jasimuddin534,项目名称:jasim_basis,代码行数:36,代码来源:Invoices.aspx.cs
示例10: btnCrear_Click
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);
}
}
开发者ID:josseline,项目名称:BaseDeDatos,代码行数:33,代码来源:Crear.aspx.cs
示例11: MultipleSelectControl
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);
}
}
开发者ID:Jobu,项目名称:n2cms,代码行数:29,代码来源:MultipleSelectControl.cs
示例12: CallDetailsObjectDataSource_Updated
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;
}
}
开发者ID:jasimuddin534,项目名称:jasim_basis,代码行数:30,代码来源:Calls.aspx.cs
示例13: AccountDetailsView_ItemInserted
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);
}
}
}
开发者ID:jasimuddin534,项目名称:jasim_basis,代码行数:28,代码来源:Opportunities.aspx.cs
示例14: CheckForEfExceptions
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;
}
}
}
}
开发者ID:aranhasete,项目名称:EF5-for-Real-Web-Applications,代码行数:34,代码来源:Customers.aspx.cs
示例15: AddValidationSummary
public static void AddValidationSummary(this Page page, string errorMessage)
{
var validator = new CustomValidator();
validator.IsValid = false;
validator.ErrorMessage = errorMessage;
page.Validators.Add(validator);
}
开发者ID:ppucik,项目名称:DOZP,代码行数:7,代码来源:Extensions.cs
示例16: InsertValidationErrorMessage
protected void InsertValidationErrorMessage(string message)
{
CustomValidator tempValidator = new CustomValidator();
tempValidator.IsValid = false;
tempValidator.Display = ValidatorDisplay.None;
tempValidator.ErrorMessage = message;
Page.Form.Controls.Add(tempValidator);
}
开发者ID:ThePublicTheater,项目名称:NYSF,代码行数:8,代码来源:GenericControl.cs
示例17: CreateErrorMsg
private void CreateErrorMsg(string message)
{
CustomValidator err = new CustomValidator();
err.IsValid = false;
err.ErrorMessage = message;
Page.Validators.Add(err);
return;
}
开发者ID:uzoneteam,项目名称:UZone,代码行数:8,代码来源:Contact.aspx.cs
示例18: BirthdayPicker
/// <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();
}
开发者ID:NewSpring,项目名称:Rock,代码行数:12,代码来源:BirthdayPicker.cs
示例19: RockCheckBoxList
/// <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();
}
开发者ID:NewSpring,项目名称:Rock,代码行数:12,代码来源:RockCheckBoxList.cs
示例20: DisplayCustomMessageInValidationSummary
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);
}
开发者ID:Marceli,项目名称:Date-Calculator,代码行数:11,代码来源:Default.aspx.cs
注:本文中的System.Web.UI.WebControls.CustomValidator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论