我正在处理一个在 asp.net 中有许多文本框和一些下拉列表的表单,目前我试图在特定文本表单的 textchange 事件上从数据库中动态填充这些文本框
即名为jobId的特定文本框(job 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);
}
}