|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
CUSTOMVALIDATOR works but page goes on on FALSEI have this customvalidator <asp:CustomValidator id="ComboValidator" runat="server" ErrorMessage="CustomValidator" /> (The OnServerValidate method is set in Events windows of the Control Property) THIS IS THE METHOD private void ValidarCombo(object sender, ServerValidateEventArgs e) { int counter=0; foreach(Control control in this.Controls[1].Controls) { if(control.GetType().ToString().IndexOf("DropDownList")!=-1) { DropDownList combo=(DropDownList)control; if(combo.SelectedItem.Value=="---") { counter++; } } } e.IsValid=(counter==0); counter++; } It works perfectly. If a DropDownList is not selected, e.Valid is set to false and also Page.IsValid BUT the page continues as if it was TRUE. Am I missing something?? Thanks in advance Two things:
1. You must *always* test Page.IsValid in your Click event method before saving. The Click event method gets called whether IsValid is true or false. So its up to you to stop it from running your Save code. 2. If you are trying to prevent saving a "no selection" state, you can use the RequiredFieldValidator. Just set its InitialText property to the value of the no selection item. ("---" in your case, I think.) --- Peter Blum www.PeterBlum.com Email: PLB***@PeterBlum.com Creator of "Professional Validation And More" at http://www.peterblum.com/vam/home.aspx Show quoteHide quote "Jose Fernandez" <ppcu***@hotmail.com> wrote in message news:OE1L8XvZFHA.3364@TK2MSFTNGP09.phx.gbl... > Hola > > I have this customvalidator > > <asp:CustomValidator id="ComboValidator" runat="server" > ErrorMessage="CustomValidator" /> (The OnServerValidate method is set in > Events windows of the Control Property) > > > THIS IS THE METHOD > private void ValidarCombo(object sender, ServerValidateEventArgs e) > { > int counter=0; > foreach(Control control in this.Controls[1].Controls) > { > if(control.GetType().ToString().IndexOf("DropDownList")!=-1) > { > DropDownList combo=(DropDownList)control; > if(combo.SelectedItem.Value=="---") > { > counter++; > } > } > } > e.IsValid=(counter==0); > counter++; > } > > It works perfectly. If a DropDownList is not selected, e.Valid is set to > false and also Page.IsValid BUT the page continues as if it was TRUE. Am I > missing something?? > Thanks in advance >
SRE (Simple Rule Engine)
Help, DropDown Web Control not Retuning "SelectedValue" "Google Suggests" and the AJAX .NET Wrapper? CustomValidator VALIDA pero NO FUNCIONA Drop down listbox - extra properties, possible? REGEX para Email how to capture click event in aspx from placeholder ->control How do I create an Unordered List (UL) with ASP.NET? I want to do a process once per page process, but 'touch' all instances of my server control. Control opens over another |
|||||||||||||||||||||||