Solved

Custom  Validator , .Net

Posted on 2009-05-14
6
165 Views
Last Modified: 2013-12-17
I want to design a custom validator , that fires only when the element which it validates is visible in the form, otherwise it should not fire.

I know that the javascript function for Custom Validator takes the source and eventargs parameters, but how can I get the ID of the element on which the custom validator was applied ?

If I get to know that I can handle the rest . Please tell me how can I do that ?
0
Comment
Question by:puneetdudeja
  • 3
  • 3
6 Comments
 
LVL 9

Accepted Solution

by:
tetorvik earned 500 total points
ID: 24382806
in javascript use source.controltovalidate for this
0
 
LVL 9

Expert Comment

by:tetorvik
ID: 24382847
sample below:
js:

        function Validate(source, args) {

              if (document.getElementById(source.controltovalidate).value == "invalidString") {

                   args.IsValid = false;

                }

            }
 

aspx:

    <asp:CustomValidator ID="CustomValidator1"

            runat="server" ErrorMessage="CustomValidator" 

            ControlToValidate="someTextBox" ClientValidationFunction="Validate">

     </asp:CustomValidator>

Open in new window

0
 
LVL 2

Author Comment

by:puneetdudeja
ID: 24382987
source.controltovalidate is undefined when the Validate function gets called.

It's not working.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 9

Expert Comment

by:tetorvik
ID: 24383026
it's working here. do you have ControlToValidate set up correctly? Like below:
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

        <asp:CustomValidator ID="CustomValidator1"

            runat="server" ErrorMessage="CustomValidator" ControlToValidate="TextBox1" ClientValidationFunction="Validate"></asp:CustomValidator>

Open in new window

0
 
LVL 2

Author Comment

by:puneetdudeja
ID: 24383116
Your above code is working fine.
But what I need to do is in the following function which is not working :

function validate(source,e)
    {
        if(document.getElementById(source.controltovalidate).style.display=='none')
            e.IsValid=true;
            else
            {
                      if(document.getElementById(source.controltovalidate).value=='')
                             e.IsValid=false;
                     else
                           e.IsValid=true;
            }
    }
0
 
LVL 2

Author Comment

by:puneetdudeja
ID: 24383220
I have found the problem in my function.

thanks for your help.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

22 Experts available now in Live!

Get 1:1 Help Now