Link to home
Start Free TrialLog in
Avatar of Phil5780
Phil5780

asked on

asp.net javascript validation

I've got an asp.net web page that contains a form with textboxes which need to be validated upon submit.  I've got javascriptt that validates each field on the page.  The validation works perfectly for each '<asp:textbox onblur=...' independently.  But when I try to call Javascript upon the '<asp:button onfocus=...' it gets called (and successfully validates) but the page submits even though the Javascript runs "return false;".  Why is this happening and how can I stop it?  

Note that my submit button is referenced by an updatepanel as a trigger.  I've tried to hook into the 'onclick' submit event but it doesn't exist on the page.  What am I missing here?
<head>
        //Sumbit val test
        function ValidateSubmit() {

            ValidateCaptchaConfirm();
        }


        //Validate captcha confirm
        function ValidateCaptchaConfirm() {

            var txtCaptchaConfirm = document.getElementById  ('txtCaptchaConfirm').value;
            var divValSubmit = document.getElementById('divValSubmit');

            //Validate captcha confirm box
            if (trim(txtCaptchaConfirm) == '') {
                divValSubmit.style.display = 'block';
                return false;
            }
            else {
                divValSubmit.style.display = 'none';
            }
        }

        
</head>

<form>

<asp:LinkButton runat="server" ID="btnNext" ClientIDMode="Static" onclick="btnNext_Click" onfocus="ValidateSubmit()"></asp:LinkButton>

</form>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Kiran Sonawane
Kiran Sonawane
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial