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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:37:52+00:00 2026-05-25T16:37:52+00:00

I want to validate product code for duplication using ajax call(in jquery) for webservice

  • 0

I want to validate product code for duplication using ajax call(in jquery) for webservice in which web method is written. now if success function executes as ‘duplicate product code’ it should not allow the user to save record. so how can i check this on Save buttons click event

  • 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-25T16:37:53+00:00Added an answer on May 25, 2026 at 4:37 pm

    First, create the below method in the page code behind.

    using System.Web.Services;
    
    [WebMethod]
        public static bool CheckDuplicateCode(string productCode)
        {
            bool isDuplicate = false;
    
            int pCode = Convert.ToInt32(productCode);
    
            //check pCode with database 
            List<int> productCodes = GetProductCodeInDb();
    
            foreach (var code in productCodes)
            {
                if (pCode == code)
                {
                    isDuplicate = true;
                    break;
                }
            }
            return isDuplicate;
        }
    

    And in the page markup just before the end body tag insert this code

     <script type="text/javascript">
        $(document).ready(function () {
            $('#<%=btnSave.ClientID %>').click(function () {
                SaveProduct();
            });
        });
    
        function SaveProduct() {
    
            //Get all the data that you are trying to save
            var pCode = $('#<%= txtProductCode.ClientID %>').val();
    
            //pass the product code to web method to check for any duplicate
                $.ajax({
                    type: "POST",
                    url: "/InsertProductPage.aspx/CheckDuplicateCode",
                    data: "{'productCode': '" + pCode + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        AjaxSuccees(msg);
                    },
                    error: AjaxFailed
                });
            }
    
            function AjaxSuccees(msg) {
                if (msg.d == true) {
                      return true;
                    //insert the rest of data
                }
                else {
                    alert("Product code already exists");
                     return false;
                }
            }
    
            function AjaxFailed(msg) {
                alert(result.status + ' ' + result.statusText);
            }
    </script>
    

    Hope this helps

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

Sidebar

Related Questions

I want to validate my text are while entering data. I had written code
I want to validate below data using regex and python. Below is the dump
I have some MET data I want to validate which would look something like
I am using asp.net mvc 2.0 and jquery validate 1.7 ( http://bassistance.de/jquery-plugins/jquery-plugin-validation/ ) What
The text string I want to validate consists of what I call segments. A
I want to validate a text box that doesn't accept any special characters using
I want validate HTML code in Java. Like this: HTMLValidator.validateHTML(aaa<b>bbb<b>); // Returns false, because
How can we validate the below code ? I want validate the input named
I want to validate the value a user enters in a text box, so
I want to validate a set of credentials against the domain controller. e.g.: Username:

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.