循环包含在ajax选项卡中的文本框

时间:2016-02-16 22:02:05

标签: c# asp.net ajax

我有20个文本框,我想在每个文本框中循环获取它们的值, 问题是所有文本框都包含在Ajax选项卡容器中,所以当我使用下面的代码时它会给我错误:

  

对象引用未设置为对象的实例

它无法找到控件,因为它位于标签enter image description here

如果我尝试使用以下代码远离标签容器,它可以正常工作

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

0 个答案:

没有答案