Solved

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

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
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…

803 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