Justify : Custom validator gets executed only at client side.

 Posted by Bhakti on 12/3/2009 | Category: ASP.NET Interview questions | Views: 2775

The answer is true and false both. Its as per specifications provided in the code. If you want to perform client side validation then it almost becomes browser specific. You can handle such situation by specifying server side validation with “OnServerValidate” tag.

But in case of server side validation with custom validator, you need to be assured that the control being validated is visible and having value.

For an example,

<asp:TextBox ID="txt" runat="server"></asp:TextBox>

<asp:CustomValidator ControlToValidate="txt" OnServerValidate="test" ClientValidationFunction="test()" ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator"></asp:CustomValidator>
<asp:button id="btnSubmit" runat="server"
OnClick="btnSubmit_Click" Text="Submit" />

Public Function test(ByVal obj As Object, ByVal objArgs As ServerValidateEventArgs) As Boolean

If Not obj Is Nothing Then
Return true
End If
End Function
Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)

End Sub

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response