CustomValidator
-
Hi I'm a newbie c# programmer and have written a custom validator to validate 2 controls on a web form. I have other controls too on the same form which use the standard ASP.Net validation controls and they work perfectly however, although my custom validator works and writes the error messages to the web form, it also wants to fire off the addVehicleToDB method which is called by clicking the Submit button. This is ok of course if data entry is correct but it happens even when e.IsValid = false;! Obviously I am not fully understanding the order in which events happen so if someone could point me in the right direction that would be great. Here is my custom validator function which is linked to a text box: public void ValidateModelType(Object s, ServerValidateEventArgs e) { lblNoType.Text = "got here"; //if the text box is null if (e.Value == "") { //check that model type has been selected from drop-down list if (ddlModelTypes.SelectedItem == null) { lblNoType.Text = "not valid!"; e.IsValid = false; } else { lblNoType.Text = "all ok"; e.IsValid = true; } } } Thanks Lorna
-
Hi I'm a newbie c# programmer and have written a custom validator to validate 2 controls on a web form. I have other controls too on the same form which use the standard ASP.Net validation controls and they work perfectly however, although my custom validator works and writes the error messages to the web form, it also wants to fire off the addVehicleToDB method which is called by clicking the Submit button. This is ok of course if data entry is correct but it happens even when e.IsValid = false;! Obviously I am not fully understanding the order in which events happen so if someone could point me in the right direction that would be great. Here is my custom validator function which is linked to a text box: public void ValidateModelType(Object s, ServerValidateEventArgs e) { lblNoType.Text = "got here"; //if the text box is null if (e.Value == "") { //check that model type has been selected from drop-down list if (ddlModelTypes.SelectedItem == null) { lblNoType.Text = "not valid!"; e.IsValid = false; } else { lblNoType.Text = "all ok"; e.IsValid = true; } } } Thanks Lorna
InvalidForumException was thrown by your question. Please make sure you post your question in correct forum. Your post has been terminated. :-D
Giorgi Dalakishvili #region signature my articles My blog[^] #endregion