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 8736715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:21:45+00:00 2026-06-13T10:21:45+00:00

I am working in C#.Net. i am having an asp button.. <asp:Button ID=btnSubmitData ToolTip=Show

  • 0

I am working in C#.Net. i am having an asp button..

<asp:Button ID="btnSubmitData" ToolTip="Show" runat="server" Text="SHOW" CausesValidation="false"
                            OnClientClick="return FindSelectedItems();" OnClick="btnShow_Click" />

The function called in OnClientClick is,

function FindSelectedItems() {

    var sender = document.getElementById('lstMultipleValues');
    var cblstTable = document.getElementById(sender.id);
    var checkBoxPrefix = sender.id + "_";
    var noOfOptions = cblstTable.rows.length;
    var selectedText = "";
    var total = 0;
    for (i = 0; i < noOfOptions; ++i) {
        if (document.getElementById(checkBoxPrefix + i).checked) {
            total += 1;
            if (selectedText == "")
                selectedText = document.getElementById
                               (checkBoxPrefix + i).parentNode.innerText;
            else
                selectedText = selectedText + "," +
             document.getElementById(checkBoxPrefix + i).parentNode.innerText;
        }
    }
    var hifMet1 = document.getElementById('<%=hifMet1.ClientID%>');
    hifMet1.value = selectedText;

    if (total == 0) {
        var panel = document.getElementById('<%=pnlOk.ClientID%>');
        document.getElementById('<%=pnlOk.ClientID%>').style.display = 'block';
        var Label1 = document.getElementById('<%=Label3.ClientID%>');
        Label1.innerHTML = "Atleast one metric should be selected.";
        var btnLoc = document.getElementById('<%=btnLoc.ClientID%>');
        btnLoc.disabled = true;
        var btnProd = document.getElementById('<%=btnProd.ClientID%>');
        btnProd.disabled = true;
        var btnLastYear = document.getElementById('<%=btnLastYear.ClientID%>');
        btnLastYear.disabled = true;
        return false;
    }
    else if (total > 2) {
        var panel = document.getElementById('<%=pnlOk.ClientID%>');
        document.getElementById('<%=pnlOk.ClientID%>').style.display = 'block';
        var Label1 = document.getElementById('<%=Label3.ClientID%>');
        Label1.innerHTML = "Only two metrics can be compared.";
        var btnLoc = document.getElementById('<%=btnLoc.ClientID%>');
        btnLoc.disabled = true;
        var btnProd = document.getElementById('<%=btnProd.ClientID%>');
        btnProd.disabled = true;
        var btnLastYear = document.getElementById('<%=btnLastYear.ClientID%>');
        btnLastYear.disabled = true;
        return false;
    }
    else {
        return true;
    }
}

Once i click the SHOW Button, i need to do a validation to check at least one checkbox should get checked in checkbox list. That alert message i am getting (i.e) “Atleast one metric should be selected”. But after this part, the page gets reloaded.

I want to avoid the page refresh at this point. What should i do here.?

  • 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-06-13T10:21:46+00:00Added an answer on June 13, 2026 at 10:21 am

    One way is to hook your validation function into the proper ASP .Net validation lifecycle by using a CustomValidator control and a client validation function.

    With a few minor changes you can turn your JavaScript code into a client validation function.

    Full example here.

    Relevant Snippets

    <script language="javascript"> 
       function ClientValidate(source, arguments)
       {
            // Your code would go here, and set the IsValid property of arguments instead
            // of returning true/false
    
            if (arguments.Value % 2 == 0 ){
                arguments.IsValid = true;
            } else {
                arguments.IsValid = false;
            }
       }
    </script>
    
    <asp:CustomValidator id="CustomValidator1"
               ControlToValidate="Text1"
               ClientValidationFunction="ClientValidate"
               OnServerValidate="ServerValidation"
               Display="Static"
               ErrorMessage="Not an even number!"
               ForeColor="green"
               Font-Name="verdana" 
               Font-Size="10pt"
               runat="server"/>
    
      <asp:Button id="Button1"
           Text="Validate" 
           OnClick="ValidateBtn_OnClick" 
           runat="server"/>
    

    Client validation should always be double-checked with server validation; using a CustomValidator with both client/server validation functions is a good way to accomplish this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on Asp.net MVC3 web application. I'm having one page on which appx.
ASP.NET Application I am having some confusion with showing images. IE is fully working
I'm working on an ASP.NET application and I'm having difficulty in understanding why a
I am working with an ASP.NET MVC application. I have one master page having
I'm working on an ASP.NET WebForms CMS application, and having a bit of trouble
I am currently working on a ASP.NET AJAX application. Having decided to not use
I am working through Steve Sanderson's book Pro ASP.NET MVC Framework and I having
I'm working on an ASP.NET MVC 3 application and having some issues. I've got
I'm currently working with EF4 and asp.net mvc 3 and I'm certainly having some
I am working on an ASP.NET 2.0 website. The issue that I'm having is

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.