Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 20 textchanged like (txtDescription1_TextChanged..............txtDescription20_TextChanged>
events like below code.by doing like this the result should come very slowly i want this event in jquery code can u plz help any one........
C#
protected void txtDescription1_TextChanged(object sender, EventArgs e)
        {
            DataTable qpdataset1 = new DataTable();
            if (!txtDescription1.Text.Equals(String.Empty) && (drpdownlistState.Text.Equals("VAT SALES")))
            {
                txtVatPercent1.Text = "5";
                txtSno1.Text = "1";

            }
            else if (!txtDescription1.Text.Equals(String.Empty) && (drpdownlistState.Text.Equals("CST SALES")))
            {

                txtVATAmt1.Text = "2";
                txtSno1.Text = "1";
            }
            else
            {
                txtVatPercent1.Text = "";
                txtSno1.Text = "1";


            }

            string desname = txtDescription1.Text.ToString();
            qpdataset1 = getqtyandprice(desname);
            DataSet dsCustomerChecking = GetRequiredDataTable("SELECT * FROM TAXINVOICE where CUSTOMERNAME = '" + txtcustomername.Text.Trim() + "'");
            if (dsCustomerChecking.Tables[0].Rows.Count > 0)
            {

                if (qpdataset1.Rows.Count > 0)
                {

                    txtPrice1.Text = qpdataset1.Rows[0]["UnitPrice"].ToString();

                    DropDownListUOM1.Text = qpdataset1.Rows[0]["UOM"].ToString();

                }
            }
        }


What I have tried:

i am new in jquery i have no idea about on this events functions in jquery
Posted
Updated 28-Jun-17 21:54pm
v2
Comments
Thanks7872 28-Jun-17 4:41am    
Add a class to all the textboxes. Define change event for that class

$(".yourclass").on('change', function() {......alert($(this).val())..});
Kornfeld Eliyahu Peter 28-Jun-17 9:17am    
Where you hide jQuery?
On what base you decided that 20 event handler-definitions make you application slow?
As you are going to SQL you have to come to the server anyway - not sure jQuery can help you here...

1 solution

use Jquery ajax in your code pass all the form inputs to your webmetod. 

Here is Clint side code

$(".txtDescription").on('change', function() {

if($(this).val()=='' &&$("#drpdownlistState").val()=="SALES"
{
  $('#txtVatPercent1').val("5");
  $('#txtSno1').val("1");
}
else if(your condition)
{
//Change this code 
 $('#txtVatPercent1').val("5");
  $('#txtSno1').val("1");
}
else
{
//Change this code 
 $('#txtVatPercent1').val("5");
  $('#txtSno1').val("1");
}

  $.ajax({
                type: "POST",
                url: "/Services/Webform1.aspx/DescriptionChange",
                data: "{txtDescription1: $('#txtDescription1').val(),
                        drpdownlistState: $('#drpdownlistState').val(),
                        txtVatPercent1: $('#txtVatPercent1').val(),
                        txtSno1: $('#txtSno1').val(),
                        txtcustomername: $('#txtcustomername').val(),
                        }",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    $("#txtPrice1").val(data.price);
                    $("#DropDownListUOM1").val(data.uom);
                },
                failure:function(data){
                           alert("failed");
                         }
            });

});

Here is your server side code
Add this method in your aspx file
[WebMethod]
public static string DescriptionChange(string txtDescription1, string drpdownlistState,string 
 txtVatPercent1, string txtSno1,string txtcustomername)
{
       var chk;
            string desname = txtDescription1.Text.ToString();
            qpdataset1 = getqtyandprice(desname);
            DataSet dsCustomerChecking = GetRequiredDataTable("SELECT * FROM TAXINVOICE where CUSTOMERNAME = '" + txtcustomername.Trim() + "'");
            if (dsCustomerChecking.Tables[0].Rows.Count > 0)
            {
 
                if (qpdataset1.Rows.Count > 0)
                {
 chk = new 
  {
    price= qpdataset1.Rows[0]["UnitPrice"].ToString() ,
    uom= qpdataset1.Rows[0]["UOM"].ToString();
  };
 
                }
            }

 return JsonConvert.SerializeObject(chk);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900