简体   繁体   中英

OnTextChange event acts weird

I am working on a form having many text box and some drop down list in asp.net,currently I trying to populate these textBox dynamically from the database on the textchange event of a particular textform

ie the particular textbox named jobId(job id is the primary key of the database table) so if someone enters 10 ,it will populate rest of the field with values with the primary key as 10,

this works for the first time ,but eventually it will give a error like

The state information is invalid for this page and might be corrupted.

and no values are changed.

Why is this happening ,I tried a lot but just can't get past this error,is it because I am loading an HTML document within another using AJAX?

for further clarification here is my code,

the trigger:

<asp:TextBox ID="Job_No" runat="server" Text="New" 
            ontextchanged="Job_No_TextChanged" AutoPostBack="true"></asp:TextBox>

the function:

  protected void Job_No_TextChanged(object sender, EventArgs e)
    {
        //SqlCommand cmd2 = new SqlCommand("");
        SqlDataAdapter sda = new SqlDataAdapter("select job_no from job_mstr", con);
        DataTable dt = new DataTable();
        sda.Fill(dt);
       // check = 1;
        try
        {
            foreach (DataRow row in dt.Rows)
            {
                if (row["job_no"].ToString() == Job_No.Text)
                {

                   // check = 0;
                    int id = Convert.ToInt32(Job_No.Text);

                    Job_No.Text = id.ToString();
                    con.Open();
                    SqlCommand cmd1 = new SqlCommand("select JOB_MILESTONE_DT,start_dt,end_dt,CUST_REF,convert(varchar,CUST_REF_DT,103) ,convert(varchar,due_date,103) ,JOB_DESC,LINKED_JOB,CLIENT_CONTACT,CONTACT_EMAIL,APPROVAL_USER,convert(varchar,approval_DT,103) ,TOT_QTY,cost,job_type,JOB_CATEGORY from job_mstr where job_no=" + id, con);
                    SqlDataReader dr = cmd1.ExecuteReader();
                    if (dr.Read())
                    {
                        JobM_Dt.Text = dr[0].ToString();
                        StartTim.Text = dr[1].ToString();
                        EndTime.Text = dr[2].ToString();
                        Cust_refTxt.Text = dr[3].ToString();
                        Cust_Ref_DtTxt.Text = dr[4].ToString();
                        Due_DtTxt.Text = dr[5].ToString();
                        Job_DescTxt.Text = dr[6].ToString();
                        Linked_JobTxt.Text = dr[7].ToString();
                        Client_ContactTxt.Text = dr[8].ToString();
                        Client_EmailTxt.Text = dr[9].ToString();
                        Approval_UsrTxt.Text = dr[10].ToString();
                        Approval_DtTxt.Text = dr[11].ToString();
                        Tot_QtyTxt.Text = dr[12].ToString();
                        CostTxt.Text = dr[13].ToString();
                        Job_TypeTxt.Text = dr[14].ToString();
                        Job_CatogeryTxt.Text = dr[15].ToString();


                    }

                    dr.Close();
                    return;
                }
                else if (check == 1)
                {
                    // Job_No.Text = "New";
                    JobM_Dt.Text = "";
                    StartTim.Text = "";
                    EndTime.Text = "";
                    Cust_refTxt.Text = "";
                    Cust_Ref_DtTxt.Text = "";
                    Due_DtTxt.Text = "";
                    Job_DescTxt.Text = "";
                    Linked_JobTxt.Text = "";
                    Client_ContactTxt.Text = "";
                    Client_EmailTxt.Text = "";
                    Approval_UsrTxt.Text = "";
                    Approval_DtTxt.Text = "";
                    Tot_QtyTxt.Text = "";
                    CostTxt.Text = "";
                    Job_TypeTxt.Text = "";
                    Job_CatogeryTxt.Text = "";
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }

我建议您最好的方法是使用jquery ajax通过将必需的值传递给服务来调用Web服务,并使该服务返回一个JSON格式对象,您可以使用该JSON格式对象使用jquery填充文本框。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM