OnTextChanged事件很奇怪

时间:2012-07-05 08:58:11

标签: c# asp.net

我正在开发一个在asp.net中有很多文本框和一些下拉列表的表单,目前我试图在特定文本形式的textchange事件中从数据库中动态填充这些textBox

,即名为jobId的特定文本框(作业ID是数据库表的主键),因此,如果有人输入10,它将使用主键为10的值填充该字段的其余部分,

这是第一次有效,但最终会出现像

这样的错误
The state information is invalid for this page and might be corrupted.

并且没有更改任何值。

为什么会发生这种情况,我尝试了很多但是无法解决这个错误,是因为我使用AJAX在另一个中加载HTML文档?

进一步澄清这里是我的代码,

触发器:

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

功能:

  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);
        }
    }

1 个答案:

答案 0 :(得分:1)

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