title: Display label after page postback
body: <p>I have a form with textboxes and 2 buttons ‘Save’ and ‘Cancel’.</p>
  
  <p>Save - stores the data to the database and clears all the fields.
  Cancel - clears all the fields.
  (I am clearing all the fields by doing a server.transfer to the same page).</p>
  
  <p>I want the label to display “Course Added” after I click the Save Button and clear the form.</p>
  
  <p>I have looked into View State and Session Variables but havn’t found a concrete solution to my problem as yet. Any help or advice is much appreciated.</p>
  
  <p>Below is the code for my aspx and code behind. Thanks.</p>
  
  <p><strong>Admin_Course_Add.aspx</strong></p>
  
  <pre><code>&lt;asp:Content ID="Content3" ContentPlaceHolderID="rightNavigation" runat="server"&gt;
  
  &lt;script type="text/javascript"&gt;
  `/`/JS for validations
    `enter code here`      $(document).ready(function () {
              $("#form1").validate({
  
                  rules: { '&lt;%=tbCourseName.UniqueID %&gt;': { required: true, maxlength: 25 },
                      '&lt;%=tbShortName.UniqueID %&gt;': { maxlength: 10 },
                      '&lt;%=tbPointScale.UniqueID %&gt;': { required: true, digits: true },
                      '&lt;%=tbDescription.UniqueID %&gt;': { maxlength: 50 }
                  },
                  messages: {}
              });
  
  
  
  
              $("#imgBtn_A_add").click(function (evt) {
                  // Validate the form and retain the result.
                  var isValid = $("#form1").valid();
  
                  // If the form didn't validate, prevent the
                  //  form submission.
  
                  // If the form didn't validate, prevent the
                  //  form submission.
                  if (!isValid)
                      evt.preventDefault();
              });
  
              $("#imgBtn_A_cancel").click(function () {
                  $("#form1").validate().cancelSubmit = true;
                  $("#form1").submit();
                  return false;
  
                  });
  
  
      &lt;/script&gt;
  
  
      &lt;div class="Admin_rightNavtop"&gt;
  
  
          &lt;table style="margin: 0 auto"&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;asp:TextBox ID="tbCourseName" runat="server" class="tbSize_large"  /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;asp:TextBox ID="tbShortName" runat="server" class="tbSize_large" /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
  
          &lt;/table&gt;
      &lt;/div&gt;
  
      &lt;center&gt;
          &lt;div class="Admin_action"&gt;
              &lt;asp:ImageButton ID="imgBtn_A_add" ImageUrl="../Images/Add.png" runat="server" class="Admin_action_imgSize_small"
                  OnClick="add_Click"  /&gt;
              &lt;asp:ImageButton ID="imgBtn_A_cancel" ImageUrl="../Images/Cancel.png" OnClick="cancel_Click"
                   runat="server" class="Admin_action_imgSize_small"/&gt;
          &lt;/div&gt;
      &lt;/center&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p><strong>Admin_Course_Add.aspx.cs (Code Behind)</strong></p>
  
  <p>protected void Page_Load(object sender, EventArgs e)
              {
                  if (!Page.IsPostBack)
                  {
                      dbConnection dbConn = new dbConnection();
                      DataTable dt = new DataTable();
                      SqlConnection connection = new SqlConnection("Data Source = VC-SQL2008; Integrated Security=True; database = CORP");</p>
  
  <pre><code>                dt = Admin_Course_WebService.PopulateCourseLevel();
  
                  ddlCourseLevel.DataSource = dt;
                  ddlCourseLevel.DataTextField = "Name";
                  ddlCourseLevel.DataValueField = "Id";
                  ddlCourseLevel.DataBind();
              }
  
  
          }
  
      protected void add_Click(object sender, ImageClickEventArgs e)
      {
  
          DataTable dt = new DataTable();
          string name = tbCourseName.Text;
          string short_name = tbShortName.Text;
  
          int id = Convert.ToInt32(ddlCourseLevel.SelectedItem.Value);
          bool isDeleted = false;
          Admin_Course_WebService.AddCourse(name, short_name, graded, point_scale, id, description, isDeleted);
  
          Server.Transfer("Admin_Course_Add.aspx");
  
  
      }
  
      protected void cancel_Click(object sender, ImageClickEventArgs e)
      {
          Server.Transfer("Admin_Course_Add.aspx");
      }
  </code></pre>