Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7739967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:39:20+00:00 2026-06-01T08:39:20+00:00

I have the code below on form so that the user submits the form

  • 0

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.

<script runat="server">

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

            }

        }

    }







</script>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">



<div id="title"><p>Contact Us...</p></div>



<div id="titletext"><p>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.</p></div>

<div id="contactform">



    <asp:Label ID="lblName" runat="server" Text="Name:"></asp:Label>
    &nbsp;
    <asp:TextBox ID="txtName" runat="server" Width="189px"></asp:TextBox>
    <br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
        ControlToValidate="txtName" ErrorMessage="Please enter your name" 
        ForeColor="Red" Display="Dynamic"></asp:RequiredFieldValidator>
    <br /><br />
    <asp:Label ID="lblEmail" runat="server" Text="Email:"></asp:Label>
    &nbsp;
    <asp:TextBox ID="txtEmail" runat="server" Width="189px"></asp:TextBox>
    <br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
        ControlToValidate="txtEmail" Display="Dynamic" ErrorMessage="Please enter an email address" 
        ForeColor="Red"></asp:RequiredFieldValidator>
    <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"></asp:RegularExpressionValidator>
    <br />
    <br />

    <asp:Label ID="lblPhone" runat="server" Text="Phone:"></asp:Label>
    &nbsp;
    <asp:TextBox ID="txtPhone" runat="server" Width="189px"></asp:TextBox>
    <br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
        ControlToValidate="txtPhone" 
        ErrorMessage="Please enter a contact telephone number" ForeColor="Red" 
        Display="Dynamic"></asp:RequiredFieldValidator>

    <br />

    <asp:Label ID="lblQuestion" runat="server" Text="Question:"></asp:Label>
    <asp:TextBox ID="txtQuestion" runat="server" Height="103px" TextMode="MultiLine" 
        Width="189px"></asp:TextBox>
    <br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
        ControlToValidate="txtQuestion" ErrorMessage="Please enter a message" 
        ForeColor="Red"></asp:RequiredFieldValidator>


    <asp:Label ID="lblSubmit" runat="server"></asp:Label>


<asp:Button ID="cmdSubmit" runat="server" Text="Submit" CssClass="cmdSubmit" 
        onclick="cmdSubmit_Click" PostBackUrl="~/Contact Us.aspx" />


</div>
</asp:Content>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T08:39:22+00:00Added an answer on June 1, 2026 at 8:39 am

    To set the text of a Label control you’d just set a value in its .Text property. So instead of this:

    Response.Write("some string");
    

    you’d have this:

    lblSomeLabel.Text = "some string";
    

    This is vastly preferred over Response.Write because the label control allows you to specify a location on the page as a placeholder. Response.Write just blindly writes the string to the response, probably either appending it after the rest of the HTML or in some undefined place in the middle.

    Note that a Label control wraps the text in a span element. If you want to output raw data over which you have complete markup control, consider using a Literal control.

    On a side note, a few words of advice for your code…

    Look into the using statement in C#. It handles the try/finally construct of anything that implements IDisposable (anything on which you’d need to call .Dispose()) in a more elegant way. Essentially it saves you the need to write the disposal code yourself and results in cleaner and safer code in general.

    In your catch statement you’re currently completely ignoring the exception that you actually catch. Is this intentional? Or is fixing this part of your plan with this code? As a general rule, never throw away the exception data. It contains the actual error message of what happened (as opposed to “something bad happened”) as well as where it happened.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that is validated by js when the user submits it.
I have a real basic form (code below) with a bunch of back-panel PhP.
I have below html code in one of the opensource project. <form action=/wiki/bin/view/Main/Search> <div
I have code below: <select id=testSelect> <option value=1>One</option> <option value=2>Two</option> </select> <asp:Button ID=btnTest runat=server
I have the code below that hides and shows the navigational bar. It is
I have a form that is generated when a user clicks a button, and
I have a form that submits through Ajax, which works perfectly at the moment.
I have a php script that displays a web form to the user. When
I have code as below: var s : String = hello world var xml
I have the code below : public class Anything { public int Data {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.