custom validator problem
-
I have a dropdown list with some options and then some textboxes. If optionA is selected from the dropdown a value MUST be entered into the textbox1. If any other option is selected from the dropdown, it is OK for textbox1 to be empty. I am trying to use a custom validator to accomplish this, but whenever i click the submit button is just skips over the code in the ServerValidate function for the custom validator. Anyone have any ideas as to why this is occurring? THanks Cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
Hi Cav. Can you post enough of the code for us to get a better idea of what's happening?
-
Hi Cav. Can you post enough of the code for us to get a better idea of what's happening?
OnClick event for the submit button just has a If Page.IsValid then // other code here End this is the Custom Validator Validate event Code (just checking to see if the dropdown is a certain value.. if so, sets the IsValid to T or F): Private Sub cvVendor_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles cvVendor.ServerValidate If (drpOpCode.SelectedItem.Value = "CORPORATE") OrElse (drpOpCode.SelectedItem.Value = "DIVISION") Then If txtVendor.Text = "" Then args.IsValid = False End If Else args.IsValid = True End If End Sub When I run the program, it never does into this code... cant figure out why... My required field validator will work, but the Custom Validator will not. Skips right over it. Thanks Cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
-
OnClick event for the submit button just has a If Page.IsValid then // other code here End this is the Custom Validator Validate event Code (just checking to see if the dropdown is a certain value.. if so, sets the IsValid to T or F): Private Sub cvVendor_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles cvVendor.ServerValidate If (drpOpCode.SelectedItem.Value = "CORPORATE") OrElse (drpOpCode.SelectedItem.Value = "DIVISION") Then If txtVendor.Text = "" Then args.IsValid = False End If Else args.IsValid = True End If End Sub When I run the program, it never does into this code... cant figure out why... My required field validator will work, but the Custom Validator will not. Skips right over it. Thanks Cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
Hi Cav. Is it possible you haven't set the
ControlToValidate
property? Can you list the attribute values at work for this control? -
Hi Cav. Is it possible you haven't set the
ControlToValidate
property? Can you list the attribute values at work for this control?ID=cvVendor ClientValidationFunction = nothing ControlToValidate = txtVendor 'the textbox Display = Static EnabledClientScript = True Enabled = True EnabledViewState = True need anything else? im developing in VS.net thx "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
-
ID=cvVendor ClientValidationFunction = nothing ControlToValidate = txtVendor 'the textbox Display = Static EnabledClientScript = True Enabled = True EnabledViewState = True need anything else? im developing in VS.net thx "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
Hmmm... I'm at a loss. I was initially thinking that maybe you needed to set
OnServerValidate="cvVendor_ServerValidation"
then I noticed you're using the Handles keyword... I'm really not sure why this wouldn't be firing under the circumstances. Do you know for sure the code isn't getting called (i.e. are you using Trace.Write or breakpoints to verify this?) Since you're not using a client validation function, try settingEnableClientScript
to false and see if that does anything. -
Hmmm... I'm at a loss. I was initially thinking that maybe you needed to set
OnServerValidate="cvVendor_ServerValidation"
then I noticed you're using the Handles keyword... I'm really not sure why this wouldn't be firing under the circumstances. Do you know for sure the code isn't getting called (i.e. are you using Trace.Write or breakpoints to verify this?) Since you're not using a client validation function, try settingEnableClientScript
to false and see if that does anything.Yeah.. im using breakpoints... doesnt ever even hit it... EnableClientScript to false doesnt do anything either... the location of the function shouldnt matter, right? (ie. above/below the submit_btnOnClick event, right)? "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
-
Yeah.. im using breakpoints... doesnt ever even hit it... EnableClientScript to false doesnt do anything either... the location of the function shouldnt matter, right? (ie. above/below the submit_btnOnClick event, right)? "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
Yea, the location shouldn't matter. Just for kicks, try setting the
OnServerValidate
attribute inline within the asp:... tag and remove theHandles
keyword from your function. I just read a thread on a google search which sounded very similar to what you're describing; the author indicated the function worked when assigned inline as an attribute but wasn't working otherwise. -
Yeah.. im using breakpoints... doesnt ever even hit it... EnableClientScript to false doesnt do anything either... the location of the function shouldnt matter, right? (ie. above/below the submit_btnOnClick event, right)? "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
It appears it will run if I have text actually in the textbox, but when the textbox is blank it will not... Will Custom Validators not work with empty textboxes? Thanks cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
-
It appears it will run if I have text actually in the textbox, but when the textbox is blank it will not... Will Custom Validators not work with empty textboxes? Thanks cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
Perhaps this is a bug?
-
It appears it will run if I have text actually in the textbox, but when the textbox is blank it will not... Will Custom Validators not work with empty textboxes? Thanks cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
It is not a bug. Custom validators when assigned to a text box only go off when there is text in the control. What you want to do is make sure that the
ControlToValidate
is NOT set. I use custom validators to validate many different controls at once. Also make sure the the button has theCausesValidation
property set to true. If you are still having some problems, I can send you my validation code. -
It is not a bug. Custom validators when assigned to a text box only go off when there is text in the control. What you want to do is make sure that the
ControlToValidate
is NOT set. I use custom validators to validate many different controls at once. Also make sure the the button has theCausesValidation
property set to true. If you are still having some problems, I can send you my validation code.So if I keep the control to Validate NOT set and the Causes Validation set to true, I will then be able to have a conditional statement saying: If X is chosen from the dropdown Then there HAS to be something in the textbox Else it is OK to have nothing in textbox ? Thanks Cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson