Verify for redundant entries in the database when the button is clicked

I have a specific requirement that involves verifying whether the user is repeatedly inputting the same Project and Survey No.

An alert should be triggered if the same combination is entered twice upon button click.

Below is the HTML code snippet:

<td class="label">
                    Project :
                </td>
                <td class="field" style="width: 10%;">
                    <asp:DropDownList ID="ddlProject" runat="server" Width="80%" AutoPostBack="true"
                        OnSelectedIndexChanged="ddlProject_SelectedIndexChanged">
                        <asp:ListItem Value="0">--Select--</asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td class="label">
                    Survey No :
                </td>
                <td class="field">
                    <asp:TextBox ID="txtSurvey1" runat="server" Width="80%" ReadOnly="true"></asp:TextBox>
                </td>

I attempted to use the link below, but it only worked for one textbox value, not the combination as required in my case.

check duplicate data with javascript

Please advise on how to address the combination aspect.

Answer №1

Upon reviewing the provided answer, I have implemented some modifications

    var projval=$('#ddlProject').val();
    var survey=$('#txtSurvey1').val();
    $.ajax({
     type: "POST",
     url: "YourPage.aspx/DoesDataExist",
    data: JSON.stringify({
        proj :projval, // ensure parameter names match backend function
        surv :survey
       }),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
     success: function(msg) {
    if(msg.d) {
        // Alert user of duplicate entry
        // Prevent server-side click with return false;
        return false;
      }
   }
  });

This section pertains to the backend webservice

  [WebMethod]
  public static bool DoesDataExist(string proj, string surv )
  {
      SqlCommand commandrepeat1 = new SqlCommand("Select * from table where project="+proj+" and Survey="+surv+" ");
      commandrepeat1.Connection = objconnection;
      objconnection.Close();
      objconnection.Open();
      SqlDataReader drmax1;
      drmax1 = commandrepeat1.ExecuteReader();
      drmax1.Read();
      if (drmax1.HasRows)
      {
          objconnection.Close();
          return true;
      }

      objconnection.Close();
      return false;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error: The method area is not supported for this.mesh.geometry

Recently, I've been experimenting with JavaScript, Three.js, and Leapmotion. To enhance my program, I decided to incorporate the leap widgets library which can be found here. However, after investing numerous hours into this project, I encountered a ...

Having trouble displaying a cube using three.js even though I have meticulously organized the object-oriented structure of my application

Creating a cube or any other geometric figure with three.js can be crystal clear when your code is simple. However, when trying to incorporate module logic in an OO-style structure for your application, you might encounter some challenges. I have faced sim ...

What is the best way to modify the styling of my CSS attributes?

I'm currently working with this CSS code: input:checked + .selectablelabel .check { visibility: hidden; } Now, I want to change the visibility property to "visible" using JavaScript. I attempted the following: $(document).on('click', & ...

Comparison Between IBM Worklight Adapter and Traditional AJAX Request

I'm looking for a thorough explanation of the differences between IBM Worklight adapter and a regular AJAX request, specifically in terms of architecture. Can anyone help clarify this for me? ...

What is the most efficient method for producing an IEnumerable<T> or ICollection<T> in a concise manner?

Many times we encounter a situation where a function requires an IEnumerable or ICollection as a parameter. If we only have single items to pass, without a collection to hold them, we typically create a temporary collection before passing it to the functio ...

React 16 is able to efficiently render an array of numbers into table data using the map function

In my quest to display the most frequently used words, I have successfully fetched data from an API. I have set up the state for words and mapped the array in render(). However, instead of displaying the words along with their counts, I only see numbers ...

Display the overall count prior to conducting grouping

I want to display the total count before performing a group by operation. Here is the data table I am working with. +----------+------------+------------+---------+---------+--------+--------+---------+ | match_id | date | tournament | playerA | pl ...

Extract the data from a JSON object

I am working with a Json string that looks like this: var Result= [{"CompanyID":32,"Roles":["Admin"]}] My goal is to extract the value of CompanyID from this data. One method I attempted was: var obj = JObject.Parse(Result); int Id=obj["CompanyID"]; ...

What causes JavaScript image to stop loading while displaying a prompt dialog?

I have nearly finished my project. I will include a codepen link at the end of the post for debugging purposes. What Should Happen? The img element has an id property of dragon, and the image specified in the src attribute should be pre-loaded as the defa ...

Retrieve data from HTML Form arrays using JavaScript

I have a situation in my forms where arrays are being sent back in the following format: <input class="checkbox-service" name="services['electricity']" type="checkbox"> <input class="checkbox-service" name="services['water'] ...

Is it possible that on OS X, Firefox with jQuery does not display errors generated in AJAX handlers?

Encountering an error in a jQuery AJAX handler on Firefox + jQuery + OS X results in the error being silently ignored. For example, you can check out the code snippet here: http://jsfiddle.net/bGuX9/ While Chrome accurately logs both errors in the JavaSc ...

Is there a way to send a variable to PHP and execute it on the current page?

I need to integrate an inventory search feature on a local clothing store's website. The challenge lies in setting up the PHP script that pulls and organizes the data to run on the same page as the search form itself. Given my limited experience with ...

Increase the value of an array element based on the input from a specified label

In my JavaScript code, I am trying to increment the value of items by adding a label input from the user. I have set up an input label and button to receive and store the user input values. In my array, I have five items with unique Id's. However, I a ...

How to use jQuery to set a background image using CSS

I've been working on setting backgrounds dynamically with a jQuery script, but it seems like the .css function is not working as expected. Here's the code snippet: $(document).ready(function () { $(".VociMenuSportG").each(function () { ...

What are the steps to set up TeamCity for executing Selenium tests?

Currently, I am in the process of configuring a TeamCity server on Windows to execute automated tests with Selenium. Unfortunately, I have encountered difficulties getting Chrome to launch properly from within TeamCity. I experimented with both Powershell ...

When using videojs, I have the ability to include a Text Track event handler, however, there is currently no option to remove it

I implemented a listener for the 'cuechange' event on a Text Track and it's functioning correctly. However, I am unable to figure out how to remove this listener. I have attempted the instructions below to remove the listener, but it continu ...

Server-side Data Fetching with Nuxt.js

Is there a method to exclusively retrieve data from an API on the server-side in NuxtJS due to me needing to include my API_TOKEN in the request headers? Sample Code: <template> <div> <h1>Data obtained using asyncData</h1> ...

What could be causing my array to be undefined upon the creation of a Vue component?

I'm struggling to comprehend why my array is showing as undefined in my Vue component. The issue arises in the following scenario: The SelectCategories.vue component uses the router to navigate to the Quiz.vue component. Here, I utilize props to tran ...

Disable or set input text to read-only in Internet Explorer 9 and earlier versions using JavaScript or jQuery

Can anyone offer any suggestions on how to accomplish this task? I attempted using JavaScript with the code below, but it did not yield the desired results. element.readOnly="true"; element.readonly="readonly"; element.disabled="disabled"; I also tried ...

An easy way to switch animations using CSS display:none

Dealing with some missing gaps here, hoping to connect the dots and figure this out. I'm attempting to create a functionality where a div slides in and out of view each time a button is clicked. Eventually, I want multiple divs to slide out simultane ...