我问的原因是因为我有一个填充了文本框,标签等的更新面板,我根据用户点击的内容使其可见/不可见。后来,我运行一个循环来清除所有文本框。它曾经工作得很好,但现在我已经添加了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);
}
}
正如旁注,申请人在调试时需要10010(需要一致性)。
此外,我在某处读到当您尝试将数据重新绑定到网格时出现此问题。每次重新加载页面时都会运行LoadGrid()方法。我应该将数据绑定到其他地方吗?如果是这样,怎么样?
答案 0 :(得分:0)
如果您想要一种简单的方法来清除所有文本框,请使用类似这样的内容
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错误...
答案 1 :(得分:0)
添加UpdatePanel不应该导致该错误。
UpdatePanels封装了页面的一部分,并导致部分刷新到该部分。
您是否正在更新控件集合?根据某些用户输入动态添加控件或用户控件?
检查ViewState的添加内容或控件上的控件集合。