Solved

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

Posted on 2008-10-20
2
270 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTML INPUT 6 23
web page freezes after ajax post 7 54
How do I post more than 1 item to php backend 24 32
Scroll 5 news at a time using vticker 2 13
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

697 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