Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6903859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:58:41+00:00 2026-05-27T07:58:41+00:00

I have some controls with CustomValidators like following. However the SetFocusOnError is not working,

  • 0

I have some controls with CustomValidators like following. However the SetFocusOnError is not working, the page doesn’t jump to the first control if validation fails. I could set focus in the javascript, but the problem with it is that always the last control that is not valid gets the focus, which is not what I want, I want the first control that is not valid gets the focus.

Can anyone tell me how to fix this? Thanks.

function ValidateRootCause(source, args) {
    var status = document.getElementById("<%=statusDropDownList.ClientID %>");
    var RootCause = document.getElementById("<%=txtRootCause.ClientID %>");

    args.IsValid = true;
    if (RootCause.value == "" && (status.value == 21 || status.value == 18)) {
        args.IsValid = false;
        RootCause.focus();
    }
}

        <tr>
            <td width="45%">Root Cause (Why it Happens)<span class="littlefont">*</span>                
            <asp:CustomValidator ID="cvRootCause" runat="server" 
                    ErrorMessage="Required Field!" CssClass="warning" 
                    ClientValidationFunction="ValidateRootCause" ValidationGroup="formValidation" SetFocusOnError="True">
            </asp:CustomValidator>
            </td>
            <td width="55%">

                <asp:TextBox ID="txtRootCause" runat="server" TextMode="MultiLine" 
                    MaxLength="1000"></asp:TextBox>
            </td>
        </tr>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:58:41+00:00Added an answer on May 27, 2026 at 7:58 am

    Create a global (outside of your function) JavaScript variable called “focusGiven” or something like that. In your if(), wrap another if() check around your focus call. This way it will only happen once.

    var focusGiven = false;
    function ValidateRootCause(source, args) {
        var status = document.getElementById("<%=statusDropDownList.ClientID %>");
        var RootCause = document.getElementById("<%=txtRootCause.ClientID %>");
    
        args.IsValid = true;
        if (RootCause.value == "" && (status.value == 21 || status.value == 18)) {
            args.IsValid = false;
    
            if (!focusGiven) {
                RootCause.focus();
                focusGiven = true;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET page using the AJAX control toolkit for some controls. A
I have a repeater control and some controls like dropdown/Buttons/Checklist for search as all
I have some controls on the page which are Invisible on page load. But
I have a page with some controls, usercontrols etc. when I change a div
I have some dynamically created inputs which are not server-side controls. I want to
I have one aspx page with some controls. Also i have one DIV which
I have a datalist control which some controls(ex: button) are in it. I want
I have an MVC page, with some controls inside a form. The part I
I have some controls like TWebBrowser, TRichText etc. which I want to scroll them
In my application I have some controls like NSButton and NSTextfield I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.