Custom Validator and Client-Side function question

I have a custom validator that checks the "ControlToValidate" input text against a javscript function. This is what I have so far:

                <asp:TextBox ID="createFileText" runat="server" />
                <asp:CustomValidator ID="CustomValidator1" runat="server"
                    ErrorMessage="Some error, try again."
                    ClientValidationFunction="CheckFileExists"
                    ControlToValidate="createFileText" />

JS Function:
function CheckFileExists(sender, args)
{ ?? alert(sender.ControlToValidate) ?? }

In the javscript function, I'm trying to get the name of the ControlToValidate from the sender, expecting "createFileText" back. I tried sender.ControlToValidate but got an undefined error. Is this possible?
bemara57Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
FlorinAntociConnect With a Mentor Commented:
Hi.

1. Just some info - customvalidators are fire-ing event only if the validating field is not empty (has nothing to do with you question - but just in case)

2. Now, getting to your question, you should use: sender.attributes["controltovalidate"].value   - in order to get the controltovalidate id....

 function vfunction(sender,args)
    {
       alert(sender.attributes["controltovalidate"].value);
       
    }


3. In order to find such "undocumented" things... try to debug the javascript code
   a. IE ->tools->IE options->advanced->disable javascript debug- disable this
   b. You can't set brakepoints...but in the javascript function you need to debug, just add something like alert(vvv);, where vvv is not defined  - and the code will stop there, because vvv is undefined - and VS 2005 IDE will alow you to quick watch any variable within the function, and browse attributes colections or properties.


Regards
0
 
bemara57Author Commented:
Thanks, but it turned out to simply be sender.controltovalidate. Found out using your method :)
0
All Courses

From novice to tech pro — start learning today.