Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change CustomValidator Error Message in JavaScript

Status
Not open for further replies.

Meleagant

Programmer
Aug 31, 2001
166
US
All,

I just started to playing with the CustomValidator object and got it working where my javascript will be called. I'm trying to validate multiple controls with one CustomerValidator and one piece of javascript. I've read from the MSDN that:
It is possible to use a CustomValidator control without setting the ControlToValidate property. This is commonly done when you are validating multiple input controls ...
But I can't get the javascript to run without at least setting one control in the ControlToValidate property so that is one minor issue.

The other half of the problem is how can I dynamically set the ErrorMessage property of the CustomerValidator in my javascript. I can't find any examples of that. Can anyone help?

Here's what I got so far:
Code:
... Inside my javascript tag ...
    function PromiseValidate(source, args) {
        
        //Get Drop Down List SelectedValue
        var ddl = igtab_getElementById('ddlRecordStatus UltraWebTab1');
        
        if (ddl.selectedIndex == 4) {
        
            var checkNo = igtab_getElementById('wteCheckNo UltraWebTab1');
            var checkAmt = igtab_getElementById('wteCheckAmount UltraWebTab1');
            var checkDate = igtab_getElementById('wdcCheckDate UltraWebTab1');
        
            if (checkNo.text == '') {
            alert('set false');
                args.IsValid = false;
                return;
            }
            
            if (checkNo.text == '') {
            alert('set false');
                args.IsValid = false;
                return;
            }
        }
    
        args.IsValid = true;
    }

...Inside my html table...

<td>
<asp:CustomValidator ID="cvOne" runat="server" ClientValidationFunction="PromiseValidate"  ControlToValidate="txtRecordComments" ValidateEmptyText="True"></asp:CustomValidator>

<asp:ValidationSummary ID="vsMaster" runat="server" ShowMessageBox="true" ShowSummary="true" DisplayMode="BulletList" />
</td>

Oh yeah all of this crap is in an Infragistics Warp Pane inside Web Tab to make it even more complicated for me. That explains the igtab_getElementById. ;-)

Thanks
-- Joe --

Journeyman -- The Order of the Seekers of Truth and Penitence
 
hi,

the "source" parameter that you get in that function is an object reference to your custom validtor control.

using that you can control the attributes of the control (that is used by the JavaScript validation code outputted by .NET)

try this (IE Only):

alert(source.outerHTML)

you must be able to find all the properties that you had set as attributes. you can now use DOM to control and change these values (using functions like getAttribute etc)...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top