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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple custom validation trouble...

Status
Not open for further replies.

song2siren

Programmer
Jun 4, 2003
103
GB
Hello

I just need to create a custom validator to check whether a control contains a value and, if it doesn't, change the style of div tag.

I tried this:

Sub surnameCheck_ServerValidate(sender as Object, e as ServerValidateEventArgs)
Dim strValue As String = e.Value
If not strValue is nothing then
e.IsValid = True
Else
e.IsValid = False
lblSurnameRow.Text = "<div class='row error'>"
End If
End Sub

With my controls like this:

<asp:Label ID="lblSurnameRow" runat="server"><div class="row"></asp:Label>
<span class="formElement"><asp:TextBox ID="frmSurname" onfocus="pviiW3Cbg(this,'#F4DFA9')" onblur="pviiW3Cbg(this,'#E5EFFF')" runat="server" /></span>
<asp:CustomValidator ControlToValidate="frmSurname" Display="Dynamic" runat="server" OnServerValidate="surnameCheck_ServerValidate" />

However, the form is submitted regardless of a value in frmSurname.

Hopefully, I'm missing something really simple, but any suggestions would be much appreciated.

Thanks
 
what you do there is make a server validation. you need to make a client validation too. so you should add a ASP required field validator to your form, bind it to your control and add a custom client script to add for it.

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top