Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.net Run 3 sliders vertically as opposed to horizontally 9 18
html input type 3 21
CSS Logo Problem. 2 4
Not seen Link button 5 13
This article discusses how to create an extensible mechanism for linked drop downs.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
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…

919 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

17 Experts available now in Live!

Get 1:1 Help Now