Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

working with my first custom validation

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
I am trying to validate a control based on the value of another contril and really don't know where to start. This is what I have so far which doesn't work yet.

My sub is
Protected Sub healthyes( _
ByVal sender As System.Object _
, ByVal objArgs As ServerValidateEventArgs)

Dim bIsValid As Boolean = False
Dim strTemp As String

strTemp = healthpart.SelectedItem.Text
If strTemp = "yes" Then
objArgs.IsValid = True
Else
objArgs.IsValid = False
End If

End Sub

my control is

<asp:customvalidator
ControlToValidate=&quot;healthpart&quot;
ClientValidationFunction=&quot;healthyes1&quot;
OnServerValidate=&quot;healthyes&quot;
Display=&quot;Dynamic&quot;
CssClass=&quot;errormessages&quot;
Text=&quot;You have verified that the user has insurance. Please enter a date.&quot;
/>

here is what I am really trying to do. Say I have a dropdown menu with the values of yes and no. If the value of the dropdown is equal to yes then a second element which is a textbox must have a value. I am just lost right now.
 
I have changed my sub a little bit

Sub healthyes( _
ByVal sender As System.Object _
, ByVal objArgs As ServerValidateEventArgs)

Dim bIsValid As Boolean = False
Dim strTemp As String
Dim strTemp1 As String

strTemp = healthpart.SelectedItem.Text
strTemp1 = healthdate.Text

If strTemp = &quot;yes&quot; and strTemp1 <> &quot;&quot; Then
objArgs.IsValid = True
Else
objArgs.IsValid = False
End If

End Sub

right now I get no error message, and the message is not displayed
 
I figured out my problem. It always helps to have that runat&quot;server&quot; thing in there.
 
hehe glad you caught it bud, cause I couldn't see a error. That'l do donkey, that'l do
[bravo]
 
Is there a way to return custom error messages from a function. In other words based on the validating that I do in the function would depend on the message the user saw??
 
If you give the customValidator an id, and have it declared in your code-behind with the &quot;protected withevents&quot; declaration, then you should be able to access it's .text property and set it to whatever you like based on user input.
penny1.gif
penny1.gif
 
then your saying it would have to be in a code-behind file, and could not be on the same page??
 
no, it could be on the same page... just give it an id, and reference the .text property
penny1.gif
penny1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top