我有20个文本框,我想在每个文本框中循环获取它们的值, 问题是所有文本框都包含在Ajax选项卡容器中,所以当我使用下面的代码时它会给我错误:
上对象引用未设置为对象的实例
如果我尝试使用以下代码远离标签容器,它可以正常工作
string TicketIDLoop = "";
for (int MutiVar = 1; MutiVar <= 20; MutiVar++)
{
ContentPlaceHolder mpContentPlaceHolder;
TextBox mpTextBox;
mpContentPlaceHolder =
(ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
if (mpContentPlaceHolder != null)
{
mpTextBox =
(TextBox)mpContentPlaceHolder.FindControl("TTIDTextBox" + MutiVar.ToString());
if (string.IsNullOrEmpty(mpTextBox.Text) == false)
{
TicketIDLoop = mpTextBox.Text;
//MessageBox.Show(mpTextBox.Text.ToString());
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ZainJTAConnectionString_96"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "[JTA_Schema].[SP_WFM_Update]";
cmd.Parameters.Add("@UpdateID", SqlDbType.Int).Value = TicketIDLoop;
cmd.Parameters.Add("@Specialist", SqlDbType.VarChar).Value = Session["Session_UserName"];
cmd.Parameters.Add("@resoultion", SqlDbType.VarChar).Value = ClosingResolutionDropDownList.SelectedValue.Trim();
cmd.Parameters.Add("@WFMComment", SqlDbType.VarChar).Value = CommentVar;
cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
}
}
}