custom validator
-
I have setup a custom validator on a checkbox list 2010 C# asp.net control. The custom control does 'work', but I still have a question about it. When an item is not selected from the checkboxlist control, the OnServerValidate code is executed once the 'submit' button is clicked. Is there a way to display the error message once the foucs has moved from the checkboxlist control to the next item on the web page? If so, can you explain how this would occur and point me to a reference that would explain this process? I have one additional question that is once the OnServerValidate event is fired, the error message does not display. The display occurs once I have code in the 'submiton event' that says if (!Page.IsPostBack) return; I would think once the OnServerValidate event finishes executing, I error message should be displayed. The error message should not wait until the logic in the submit button fires. Thus can you tell me if this is ok and why? if this is not ok, can you tell me why not and possibly point me to a reference to solve this issue? The following is the code I am referring to: [^] public void ValidateNumber(Object source, ServerValidateEventArgs args) { args.IsValid = false; for (int i = 0; i < ChkBoxLstPlan.Items.Count; i++) { if (ChkBoxLstPlan.Items[i].Selected) { args.IsValid = true; } } } protected void submitbutton(object sender, EventArgs e) { if (!Page.IsPostBack) return; } [^]
-
I have setup a custom validator on a checkbox list 2010 C# asp.net control. The custom control does 'work', but I still have a question about it. When an item is not selected from the checkboxlist control, the OnServerValidate code is executed once the 'submit' button is clicked. Is there a way to display the error message once the foucs has moved from the checkboxlist control to the next item on the web page? If so, can you explain how this would occur and point me to a reference that would explain this process? I have one additional question that is once the OnServerValidate event is fired, the error message does not display. The display occurs once I have code in the 'submiton event' that says if (!Page.IsPostBack) return; I would think once the OnServerValidate event finishes executing, I error message should be displayed. The error message should not wait until the logic in the submit button fires. Thus can you tell me if this is ok and why? if this is not ok, can you tell me why not and possibly point me to a reference to solve this issue? The following is the code I am referring to: [^] public void ValidateNumber(Object source, ServerValidateEventArgs args) { args.IsValid = false; for (int i = 0; i < ChkBoxLstPlan.Items.Count; i++) { if (ChkBoxLstPlan.Items[i].Selected) { args.IsValid = true; } } } protected void submitbutton(object sender, EventArgs e) { if (!Page.IsPostBack) return; } [^]
Member 8217517 wrote:
Is there a way to display the error message once the foucs has moved from the checkboxlist control to the next item on the web page? If so, can you explain how this would occur and point me to a reference that would explain this process?
Use client validation script of custom validator and enable Client side validation. If you are validating at server side also, Do have a check property Page.Isvalid before doing any operation. This property will return true only if all validators is passed else it will return true. For details about asp.net validators, you can have a look to one of my post Exploring ASP.NET Validators
Cheers!! Brij Microsoft MVP ASP.NET/IIS Visit my Blog: http://brijbhushan.net