?
Solved

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

Posted on 2008-10-20
2
Medium Priority
?
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
M3mph15 earned 2000 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

777 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