Email form with feedback

Discussion in 'ASP.NET / ASP.NET Core' started by Merv Norton, Jan 17, 2010.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I have created a simple email form using the code from Jim Cheshire’s tutorial (www.JimCoBooks.com) and it works fine. Jim provided the code for the basic form. I then followed his tutorial for adding feed back to the email form. There was no code provided so I had to follow the tutorial as best as I could. When I try to execute the form the form does not display and I get no error message.
    Can anyone help me solve this problem? Here is my code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@ Page Language="C#" %>

    <!-- Start of server Code -->

    <%@ Import Namespace="System.Net.Mail" %>
    <%@ Import Namespace="System.Text" %>

    <script runat="server">

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
    SmtpClient sc = new SmtpClient("localhost");
    StringBuilder sb = new StringBuilder();
    MailMessage msg = null;

    sb.Append("Email from: " + txtEmail.Text + "\n");
    sb.Append("Message : " + txtMessage.Text + "\n");

    try
    {
    msg = new MailMessage(txtEmail.Text,
    "[email protected]", "Message from Web Site",
    sb.ToString());

    sc.Send(msg);
    MultiView1.SetActiveView(ViewConfirm);
    }
    catch(Exception ex)
    {

    // send Error message
    Response.Write(ex.Message);


    }
    finally
    {

    if (msg != null)
    {
    msg.Dispose();
    }

    }

    }
    protected void Page_Load(object sender, EventArgs e)
    {

    if (IsPostBack)
    {
    MultiView1.SetActiveView(ViewForm);
    }

    }

    </script>

    <!-- End of Server Code -->


    <!-- Start of Screen Code -->

    <html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">

    <meta http-equiv="Content-Language" content="en-us" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>Enter your e-mail address</title>

    </head>

    <body>

    <form id="form1" runat="server">

    <asp:MultiView runat="server" id="MultiView1">
    <asp:View runat="server" id="ViewForm">
    Enter your e-mail address:<br />
    <asp:TextBox runat="server" id="txtEmail" Width="203px">
    </asp:TextBox>
    <asp:RequiredFieldValidator runat="server" ErrorMessage="E-mail is required." id="RequiredFieldValidator1" ControlToValidate="txtEmail" Display="Dynamic">
    </asp:RequiredFieldValidator>
    <asp:RegularExpressionValidator runat="server" ErrorMessage="E-mail address invalid." id="RegularExpressionValidator1" ControlToValidate="txtEmail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
    </asp:RegularExpressionValidator>
    <br />
    <br />
    Enter your message:<br />
    <asp:TextBox runat="server" id="txtMessage" Width="244px" Height="125px" TextMode="MultiLine">
    </asp:TextBox>
    <br />
    <asp:RequiredFieldValidator runat="server" ErrorMessage="Message is required." id="RequiredFieldValidator2" ControlToValidate="txtMessage">
    </asp:RequiredFieldValidator>
    <br />
    <br />
    <asp:Button runat="server" Text="Submit" OnClick=btnSubmit_Click ID="btnSubmit" Width="116px" />
    </asp:View>

    <asp:View runat="server" id="ViewConfirm">
    <p>Thank you for Registering with the 1st Signal Brigade Association.</p>
    </asp:View>
    </asp:MultiView>



    </form>

    </body>

    </html>

    <!-- End of Screen Code -->
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    does the page refresh at all when you hit the submit button?
     
  3. No, the screen is completely white.
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    hmmm.. it is pretty difficult to troubleshoot w/o any error. are other asp.net pages running?
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page