?
Solved

asp.net javascript validation

Posted on 2011-10-08
1
Medium Priority
?
232 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:Phil5780
1 Comment
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 2000 total points
ID: 36937769
try this
<head>
        //Sumbit val test
        function ValidateSubmit() {

            return ValidateCaptchaConfirm();
        }


        //Validate captcha confirm
        function ValidateCaptchaConfirm() {
var flag=true;
            var txtCaptchaConfirm = document.getElementById  ('txtCaptchaConfirm').value;
            var divValSubmit = document.getElementById('divValSubmit');

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

        
</head>

<form>

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

</form>

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

755 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