title: Need to clear values of textboxes placed in update panel after button click
body: <p>I have few textboxes in an update panel. On button click the values of textboxes is inserted into the database. I want the values to get cleared once the data has been inserted into the database.</p>
  
  <p>PS: I tried to clear the values using a function after calling it once the data has been inserted. It doesn't work.</p>
  
  <p>ASP </p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeBehind="CalenderTest.aspx.cs" Inherits="DynamicCalender.CalenderTest"  %&gt;
  
  &lt;%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %&gt;
  
   &lt;!DOCTYPE html&gt;
  
   &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
   &lt;head runat="server"&gt;
    &lt;title&gt;&lt;/title&gt;
  
  &lt;style type="text/css"&gt;
      .auto-style1 {
          width: 363px;
      }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;form id="form1" runat="server"&gt;
      &lt;asp:ToolkitScriptManager ID="ToolkitScriptManager1"runat="server"&gt;&lt;/asp:ToolkitScriptManager&gt;
  
  &lt;div&gt;
     &lt;div&gt;
  
         &lt;asp:Label ID="lbl_year" runat="server" Text="Year"&gt;&lt;/asp:Label&gt;&amp;nbsp;&amp;nbsp;
         &lt;asp:DropDownList ID="ddl_year" runat="server"&gt;&lt;/asp:DropDownList&gt;&amp;nbsp;&amp;nbsp;
  
         &lt;asp:Label ID="lbl_train" runat="server" Text="Training"&gt;&lt;/asp:Label&gt;&amp;nbsp;&amp;nbsp;
         &lt;asp:DropDownList ID="dd1_training" runat="server"&gt;&lt;/asp:DropDownList&gt;&amp;nbsp;&amp;nbsp;
  
          &lt;asp:Button ID="btnsave" runat="server" Text="Create Batches" OnClick="btnsave_Click"/&gt;
         &lt;br /&gt;
         &lt;br /&gt;
  
         &lt;asp:UpdatePanel ID="pnl1" runat="server" UpdateMode="Conditional"&gt; 
             &lt;ContentTemplate&gt;
  
                 &lt;asp:Label ID="ss" runat="server" Text="session"&gt;&lt;/asp:Label&gt; 
  
                      &lt;asp:Label runat="server" Text="Venue"&gt;&lt;/asp:Label&gt;
  
                     &lt;asp:TextBox ID="venue" runat="server" CausesValidation="false"&gt;&lt;/asp:TextBox&gt;
  
                     &lt;asp:Label ID="Label1" runat="server" Text="Time"&gt;&lt;/asp:Label&gt;
  
                     &lt;asp:DropDownList ID="ddltime" runat="server" &gt;&lt;/asp:DropDownList&gt;
  
                     &lt;asp:Label ID="Label2" runat="server" Text="Faculty"&gt;&lt;/asp:Label&gt;
  
                      &lt;asp:TextBox ID="faculty" runat="server"  CausesValidation="false"&gt;&lt;/asp:TextBox&gt;
  
                     &lt;asp:Label ID="Label3" runat="server" Text="Module Details"&gt;&lt;/asp:Label&gt;
  
                     &lt;asp:TextBox TextMode="MultiLine" id="module_det" runat="server"  CausesValidation="false"&gt;&lt;/asp:TextBox&gt;
  
                &lt;asp:Button id="Button1"  runat="server" Text="Add" OnClick="Button1_Click" /&gt;
                &lt;asp:Button id="Button2"  runat="server" Text="Next" OnClick="Button2_Click"/&gt;
  
                     &lt;asp:TextBox ID="caldt" runat="server"  CausesValidation="false"&gt;&lt;/asp:TextBox&gt;
  
                     &lt;asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="caldt"&gt;&lt;/asp:CalendarExtender&gt;
  
                 &lt;/ContentTemplate&gt;
             &lt;Triggers&gt;
                 &lt;asp:AsyncPostBackTrigger ControlID="Button1" /&gt;
  
             &lt;/Triggers&gt;
              &lt;/asp:UpdatePanel&gt;
  
  
         &lt;asp:HiddenField ID="hd01" runat="server" /&gt;
         &lt;asp:HiddenField ID="hd02" runat="server" /&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>C#</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
  {
      sess_datetime = caldt.Text + " " + ddltime.SelectedItem.Value.ToString();
      str1 = "Insert into sessDetail (tid,bid,sid,dt,faculty,venue,status) values(@tid,@bid,@sid,@dt,@faculty,@venue,@status)";
  
      cmd = new SqlCommand(str1, con);
      cmd.Parameters.Clear();
      cmd.Parameters.AddWithValue("@tid", dd1_training.SelectedItem.Value);
      cmd.Parameters.AddWithValue("@bid",Session["bid"]);
      cmd.Parameters.AddWithValue("@sid",Session["sid"]);
      cmd.Parameters.AddWithValue("@dt", sess_datetime);
      cmd.Parameters.AddWithValue("@faculty", faculty.Text);
      cmd.Parameters.AddWithValue("@venue", venue.Text);
      cmd.Parameters.AddWithValue("@status", "0");
      cmd.ExecuteNonQuery();            
      con.Close();
      clear();        
  }            
  
  protected void clear
  {
      try
      {
          foreach (var pnl in pnl1.Controls)
          {
              var tb = pnl as TextBox;
              if (tb != null)
              {
                  tb.Text = "";
              }
          }
          ddltime.ClearSelection();
      }
      catch(Exception x)
      {
          Response.Write(x.Message);
      }
  } 
  </code></pre>