title: Response.Write to label
body: <p>I have the code below on form so that the user submits the form and it sends and email. I have two response.write statements and I am wanting to change these so that a it writes these to a label (lblSubmit). Any help would be appreciated.</p>
  
   
          
          
  
  <pre><code>&lt;script runat="server"&gt;
  
      protected void Page_Load(object sender, EventArgs e)
      {
  
  
          if (IsPostBack)
          {
  
  
  
              SmtpClient sc = new SmtpClient("smtp.talktalk.net");
              StringBuilder sb = new StringBuilder();
              MailMessage msg = null;
  
              sb.Append("Email from: " + txtEmail.Text + "\n");
              sb.Append("Message   : " + txtQuestion.Text + "\n");
  
              try
              {
                  msg = new MailMessage(txtEmail.Text,
                      "myemail@talktalk.net", "Message from Web Site",
                      sb.ToString());
  
                  sc.Send(msg);
  
  
  
  
                  Response.Write("Message sent!");
  
              }
              catch (Exception ex)
              {
  
                  // something bad happened
                  Response.Write("Something bad happened!");
  
              }
              finally
              {
  
                  if (msg != null)
                  {
                      msg.Dispose();
                  }
  
              }
  
          }
  
      }
  
  
  
  
  
  
  
  &lt;/script&gt;
  &lt;asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"&gt;
  
  
  
  &lt;div id="title"&gt;&lt;p&gt;Contact Us...&lt;/p&gt;&lt;/div&gt;
  
  
  
  &lt;div id="titletext"&gt;&lt;p&gt;Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.&lt;/p&gt;&lt;/div&gt;
  
  &lt;div id="contactform"&gt;
  
  
  
      &lt;asp:Label ID="lblName" runat="server" Text="Name:"&gt;&lt;/asp:Label&gt;
      &amp;nbsp;
      &lt;asp:TextBox ID="txtName" runat="server" Width="189px"&gt;&lt;/asp:TextBox&gt;
      &lt;br /&gt;
      &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
          ControlToValidate="txtName" ErrorMessage="Please enter your name" 
          ForeColor="Red" Display="Dynamic"&gt;&lt;/asp:RequiredFieldValidator&gt;
      &lt;br /&gt;&lt;br /&gt;
      &lt;asp:Label ID="lblEmail" runat="server" Text="Email:"&gt;&lt;/asp:Label&gt;
      &amp;nbsp;
      &lt;asp:TextBox ID="txtEmail" runat="server" Width="189px"&gt;&lt;/asp:TextBox&gt;
      &lt;br /&gt;
      &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
          ControlToValidate="txtEmail" Display="Dynamic" ErrorMessage="Please enter an email address" 
          ForeColor="Red"&gt;&lt;/asp:RequiredFieldValidator&gt;
      &lt;asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
          ControlToValidate="txtEmail" ErrorMessage="Please enter a valid Email address" 
          ForeColor="Red" 
          ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" 
          Display="Dynamic"&gt;&lt;/asp:RegularExpressionValidator&gt;
      &lt;br /&gt;
      &lt;br /&gt;
  
      &lt;asp:Label ID="lblPhone" runat="server" Text="Phone:"&gt;&lt;/asp:Label&gt;
      &amp;nbsp;
      &lt;asp:TextBox ID="txtPhone" runat="server" Width="189px"&gt;&lt;/asp:TextBox&gt;
      &lt;br /&gt;
      &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
          ControlToValidate="txtPhone" 
          ErrorMessage="Please enter a contact telephone number" ForeColor="Red" 
          Display="Dynamic"&gt;&lt;/asp:RequiredFieldValidator&gt;
  
      &lt;br /&gt;
  
      &lt;asp:Label ID="lblQuestion" runat="server" Text="Question:"&gt;&lt;/asp:Label&gt;
      &lt;asp:TextBox ID="txtQuestion" runat="server" Height="103px" TextMode="MultiLine" 
          Width="189px"&gt;&lt;/asp:TextBox&gt;
      &lt;br /&gt;
      &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
          ControlToValidate="txtQuestion" ErrorMessage="Please enter a message" 
          ForeColor="Red"&gt;&lt;/asp:RequiredFieldValidator&gt;
  
  
      &lt;asp:Label ID="lblSubmit" runat="server"&gt;&lt;/asp:Label&gt;
  
  
  &lt;asp:Button ID="cmdSubmit" runat="server" Text="Submit" CssClass="cmdSubmit" 
          onclick="cmdSubmit_Click" PostBackUrl="~/Contact Us.aspx" /&gt;
  
  
  &lt;/div&gt;
  &lt;/asp:Content&gt;
  </code></pre>