Solved

Custom  Validator , .Net

Posted on 2009-05-14
6
169 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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