0

I have a requirement, where I want to check whether user is not inserting the same Project, Survey No again and again.

It should fire an alert if it enters the same combination twice on button click

Here is my HTML:-

<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 tried the below link, but it was not for the combination. It was just for one textbox value, So it was not working in my case.

check duplicate data with javascript

Kindly let me know how to deal with the combination part

2
  • are you asking how to send two values? instead of one? Commented Sep 1, 2016 at 7:01
  • @Mysterio11: yes, for the checking the combination of two values. Commented Sep 1, 2016 at 7:02

1 Answer 1

-1

I have made a few changes to the answer linked by you

    var projval=$('#ddlProject').val();
    var survey=$('#txtSurvey1').val();
    $.ajax({
     type: "POST",
     url: "YourPage.aspx/DoesDataExist",
    data: JSON.stringify({
        proj :projval, // the names of the properties must match with the parameters in the backend function
        surv :survey
       }),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
     success: function(msg) {
    if(msg.d) {
        // This is a duplicate, alert user with message
        // Block the server-side click from happening with return false;
        return false;
      }
   }
  });

this is 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;
}
Sign up to request clarification or add additional context in comments.

12 Comments

let me try and check with your answer :)
I am getting error as Microsoft JScript runtime error: Object expected at line var projval=$("#ddlProject").val();
replace $("#ddlProject").val() with $('<%="#"+ddlProject.ClientId%>') and try
i resolved that error, but now getting error as Microsoft JScript runtime error: Object doesn't support this property or method
tell me have you included the jquery library?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.