![](/img/trans.png)
[英]C# Added Ajax Update Panel but Anchor will not run server-side code once placeholder is populated
[英]Does an AJAX Update Panel affect C# code?
我问的原因是因为我有一个填充有文本框,标签等的“更新面板”,根据用户单击的内容,它们可以显示/隐藏。 稍后,我运行循环以清除所有文本框。 它曾经可以正常工作,但是现在我添加了AJAX更新面板,它给了我一个“无效的回发或回调参数”错误。
这是因为该AJAX更新面板吗? 还是我自己做了完全错误的事情?
谢谢,艾莉
[编辑]:好的,我要添加一堆代码,因为我不知道它的来源:
这是写记录的方法:
protected void AddEmployerRecord()
{
connection = new SqlConnection();
connection.ConnectionString = "****";
connection.Open();
newEmployer = new EmployerCRUD(connection);
employerRow.employerName = tb_employer.Text;
employerRow.empPhone = tb_phone.Text;
employerRow.empFax = tb_fax.Text;
employerRow.empEmail = tb_email.Text;
employerRow.empAddress = tb_address.Text;
employerRow.empCity = tb_city.Text;
employerRow.empState = ddl_state.SelectedValue.ToString();
employerRow.empZIP = tb_ZIP.Text;
employerRow.startDate = Convert.ToDateTime(tb_fromDate.Text);
employerRow.endDate = Convert.ToDateTime(tb_toDate.Text);
employerRow.startPay = Convert.ToDecimal(tb_startPay.Text);
employerRow.endPay = Convert.ToDecimal(tb_endPay.Text);
employerRow.leaveReason = tb_leaveReason.Text;
employerRow.supervisorFName = tb_superFName.Text;
employerRow.supervisorLName = tb_superLName.Text;
employerRow.contactForRef = rbl_contact.SelectedValue.ToString();
employerRow.jobDesc = tb_jobDesc.Text;
employerRow.applicantID = 10010;
//employerRow.applicantID = Convert.ToInt32(Session["ApplicantNum"]);
employerRow.supervisorTitle = tb_superTitle.Text;
employerRow.jobTitle = tb_jobTitle.Text;
employerRow.startPayType = ddl_startPayType.SelectedValue.ToString();
employerRow.endPayType = ddl_endPayType.SelectedValue.ToString();
ct_emp = newEmployer.Add(employerRow);
// *************** Error Message *************** //
//if (ct_emp.Message != "OK")
// Error message
//else
//
connection.Close();
}
这是加载网格的方法:
protected void LoadGrid()
{
try
{
SqlConnection pConnection = new SqlConnection();
pConnection.ConnectionString = "**";
pConnection.Open();
string sqlstatement = "SELECT EmployerID, EmployerName FROM dbo.EMPLOYER WHERE ApplicantID = @applicantID";
command = new SqlCommand(sqlstatement, pConnection);
command.Parameters.AddWithValue("@applicantID", 10010);
//command.Parameters.AddWithValue("@applicantID", Session["ApplicantNum"].ToString().Trim());
ds = new DataSet();
adapter = new SqlDataAdapter(command);
builder = new SqlCommandBuilder(adapter);
adapter.Fill(ds);
gv_employers.DataSource = ds.Tables[0];
gv_employers.DataBind();
pConnection.Close();
}
catch (Exception error)
{
Response.Write(error.Message);
}
}
就像一个旁注一样,在我调试内容时(需要一致性),ApplicantID仅为10010。
另外,我在某处读到,当您尝试将数据重新绑定到网格时,会出现此问题。 每次重新加载页面时,我都会运行该LoadGrid()方法。 我应该将数据绑定到其他地方吗? 如果是这样,怎么办?
如果要清除所有文本框的简单方法,请使用类似以下内容
public void ClearTextItems(ControlCollection controls)
{
foreach (Control c in controls)
{
if (c is System.Web.UI.WebControls.TextBox)
{
TextBox t = c as TextBox;
t.Text = string.Empty;
}
}
}
将需要查看其他代码,您将在其中获取PostBack错误...
仅添加UpdatePanel不会导致该错误。
UpdatePanels包围页面的一部分,并导致对该部分进行部分刷新。
您要更新控件集合吗? 根据某些用户输入动态添加控件或用户控件?
检查是否添加了ViewState或控件上的控件集合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.