Solved

How do I call a javascript function from within a RequiredFieldValidator?

Posted on 2008-10-20
2
240 Views
Last Modified: 2010-04-21
I am working on asp.net web page. I want to replace a label with a RequiredFieldValidator message when an error occurs. To achieve this I want to call a javascript function from within the RequiredFieldValidator to trigger the replacement. Can this be done and if so how?
0
Comment
Question by:xdubit
2 Comments
 
LVL 6

Accepted Solution

by:
M3mph15 earned 500 total points
ID: 22765182
I think instead of using a RequiredFieldValidator you should use a CustomValidator and set the ClientValidationFunction to the Javascript function.

<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="CustomValidator" ClientValidationFunction="ValidateControl();" ControlToValidate="YourControl"></asp:CustomValidator>

And then in the javascript function you can validate it. For example if it's a textbox your validating then check if the Length of its text is greater than 0. If not then replace Label with the CustomValidator.
0
 

Author Closing Comment

by:xdubit
ID: 31508126
That did the job. Thanks.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now