M
Mattyw
Hi,
I'm relatively new to Web Forms, I have been using Required Field
Validators and Regular Expression Validators on a Web Form I am
developing and everything works as expected using Visual Studio.NET
2003 and VB code behind.
I have a radio button and textbox, and basically i need the textbox to
be required based on the user selecting "Yes" from the radio button.
I've read through the newsgroups and found that a Custom Validator
could achieve this result, but am unsure how to implement it.
I have added a Custom Validator then a Required Field Validator to be
fired should the radiobutton be "Yes" and included it in the codebehind
page in the Custom Validator as below:
Private Sub CustomValidator1_ServerValidate(ByVal source As
System.Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs) Handles
CustomValidator1.ServerValidate
if radiobutton.selectedvalue.text = "Yes"
then requiredfield.isvalid = true
else
requiredfield.isvalid = false
End if
End Sub
When I run the above the required field validator runs whatever is
checked by the radio button, so I'm obviously missing something or am I
thinking too logically???. I assumed that the above code would make the
required field validator "true" if "Yes" was selected and then display
the "error" and the validator would not fire based on "no" being
selected.
Any help would be grateful...I have a suspicion I'm going in the wrong
direction!!.
Cheers
Mattyw
I'm relatively new to Web Forms, I have been using Required Field
Validators and Regular Expression Validators on a Web Form I am
developing and everything works as expected using Visual Studio.NET
2003 and VB code behind.
I have a radio button and textbox, and basically i need the textbox to
be required based on the user selecting "Yes" from the radio button.
I've read through the newsgroups and found that a Custom Validator
could achieve this result, but am unsure how to implement it.
I have added a Custom Validator then a Required Field Validator to be
fired should the radiobutton be "Yes" and included it in the codebehind
page in the Custom Validator as below:
Private Sub CustomValidator1_ServerValidate(ByVal source As
System.Object, ByVal args As
System.Web.UI.WebControls.ServerValidateEventArgs) Handles
CustomValidator1.ServerValidate
if radiobutton.selectedvalue.text = "Yes"
then requiredfield.isvalid = true
else
requiredfield.isvalid = false
End if
End Sub
When I run the above the required field validator runs whatever is
checked by the radio button, so I'm obviously missing something or am I
thinking too logically???. I assumed that the above code would make the
required field validator "true" if "Yes" was selected and then display
the "error" and the validator would not fire based on "no" being
selected.
Any help would be grateful...I have a suspicion I'm going in the wrong
direction!!.
Cheers
Mattyw