Initially, I was trying to bind my internal Validation_Event to the either the bound control’s KeyUp event (when it’s binding.DataSourceUpdateMode = DataSourceUpdateMode.OnPropert圜hanged) or the control’s Validated event (when it’s binding.DataSourceUpdateMode = DataSourceUpdateMode.OnValidation) from within the constructor of my control. (It turns out that when I originally started this endeavor I started with a printout of Rocky’s ReadWriteAuthorization.cs however, I still couldn't quite figure things out at that time.) I finally figured out and solved my problem! Thanks ajj3085 and Rocky for your help. KKoteles replied on Friday, October 05, 2007 Obviously there are many areas open for improvement (like being able to set each icon as well as setting it's respective offset from the base ErrorProvider icon, etc) however, I was hoping someone might be able to lead me in the right direction for both trying to tie this into the control events automatically (without needing the Initialize method). errorWarnInfoProvider1.Initialize( this.Controls) Unfortunately that means you need to add the following line (or something like it) within the associated form's constructor: I like it a lot, but I can't figure out how to get it to "hook" itself to the appropriate events automatically - so I took a short cut. If you take a look at the code in my attachment (don't forget to update the references for CSLA before you try to compile!), you can see I've created an ErrorWarnInfoProvider object that that displays all three levels of severity for the BrokenRulesCollection. I couldn't find anything else so I tried my hand at extending it. I've always liked the idea of the ErrorProvider however, all it displays are the errors. KKoteles posted on Thursday, October 04, 2007 I found an appropriate regex here and the following will validate your email text box for you (note I've set the email text to lower case to allow for a simpler regex - always a good idea in my opinion). Next - as per my comment, there is no need to turn autovalidation off while you are validating - it sort of defeats the purpose :-) The correct way to let the system know that the validation has failed is to use the CancelEventArgs parameter provided - i.e. Let's deal with TxtEmail_Validating first.Īll those checks that could finally lead to the message "Email cannot be left blank" are a waste of time - if you choose an appropriate regex to test against.īut if you were going to leave them in, you need to exit appropriately once you have discovered that the validation has failed.Īlso there is no need to set the focus to the control that you are validating because you have not yet left that control.įinally, you went to all the trouble of trimming the text in the textbox, but didn't use it when matching to the regex. In the case of Password Validation.Even after entering password as per the parameters within the Regex,it throws "Invalid Password" message.I saw questions here based on validation but none of them have satisfactory solution to my question.Ĭan anyone help me to rectify this error? I want to achieve Validation without ErrorProvider which is another option. But when I remove the text within the texbox and re-enter it, validation doesn't work the 2nd time and does not throw the message "Invalid Email" I am using AutoValidate feature to cancel validation if the parameters within the Regex match.But the problem is when I use AutoValidate or Set CauseValidation to false,the validation of TextBox is done the first time the form is loaded. Regex r = new Regex( (r.IsMatch(TxtPassword.Text)) Private void TxtPassword_Validated( object sender, EventArgs e) MessageBox.Show( " Invalid Email Format") Regex r = new Regex( (r.IsMatch(TxtEmail.Text)) MessageBox.Show( " Email Cannot be Left Blank") If (StrEmail = " " || StrEmail.IndexOf( " ") > 0 || StrEmail.IndexOf( ' "') > 0 || StrEmail = " " || StrEmail.IndexOf( " ") > 0) Private void TxtEmail_Validating( object sender, CancelEventArgs e)
0 Comments
Leave a Reply. |