Miscellaneous ASP.NET question on a mail form...

Discussion in 'ASP .Net' started by Henry Stock, Aug 16, 2008.

  1. Henry Stock

    Henry Stock Guest

    My ISP provides this sample for an ASP.NET capable email form.

    If you have any idea about how to do the following, I would greatly
    appreciate your help.

    I have a few alterations that I would like to implement, but I am not sure
    where to begin.

    First:

    I want to implement the code in a codebehind page instead of in the
    mailform.aspx page. I am not sure where I would put the code. I also know
    that there are differences in background operations between ASP.NET 1.1 and
    ASP.NET 2.0, but I don't know if the code would differ much. In other stuff
    I found on the internet, the SMTP server was identified in a <mailsettings>
    section in the web.config file. That seems cleaner to me, but I don't know
    how the code would change. I probably would skip the code identifying the
    server.

    Second:

    I already have an old mail form that was implemented using a CGI. I also
    used a javascript based CAPTCHA function in that form to cut down on
    automated spam.
    In that instance the old form tag included and action attribute that pointed
    to the cgi and an onsubmit="return jcap()" function that invoked the
    javascript; elsewhere in the page there was a call to another javascript
    that implemented the image that needed to be verified. I would still like
    to use that script to prevent autospammers. I am not sure how to call the
    javascript function jcap() before the contactUS_Click event handler.

    The event handler is server based, so I am hoping that I can just leave the
    call in the form onsubmit attribute because I think that should fire first.

    As for the email based script I am guessing that I should check the
    page.IsPostback variable and excute it only when that is true.

    Third:
    I want to add some additional validation on form fields. Specifically I
    would like to test for a valid email address if nothing else. I am planning
    a form that has more data elements such as name, address, phone number, etc
    that I expect to concatenate into the message body.

    Fourth:
    I want to convert the script from VB.NET to C#


    ' ============================================
    <% @Import Namespace="System.Web.Mail" %>
    <script language="vb" runat="server">

    Sub contactUS_Click(sender as Object, e as EventArgs)

    'Create an instance of the MailMessage class
    Dim objMM as New MailMessage()

    objMM.To = ""
    objMM.From = email.Text

    'If you want to CC this e-mail to someone else
    'objMM.Cc = ""

    'e-mail format. Can be Text or Html
    objMM.BodyFormat = MailFormat.Text

    'Set the priority - options are High, Low, and Normal
    objMM.Priority = MailPriority.Normal

    'Set the subject
    objMM.Subject = "1&1 Contact US"

    'Set the body
    objMM.Body = message.Text

    'Smtp Server
    SmtpMail.SmtpServer = "mrelay.perfora.net"

    'Send the message
    SmtpMail.Send(objMM)

    panelSendEmail.Visible = false
    panelMailSent.Visible = true

    End Sub

    </script>

    <html>
    <body>
    <asp:panel id="panelSendEmail" runat="server">
    <form runat="server">
    <h2>CONTACT US FORM</h2>

    <b>Your Name:</b>
    <asp:textbox id="name" runat="server" />
    <br>

    <b>Your Email Address:</b>
    <asp:textbox id="email" runat="server" />
    <p>

    <b>Your Message:</b><br>
    <asp:textbox id="message" TextMode="MultiLine"
    Columns="40" Rows="10" runat="server" />
    <p>

    <asp:button runat="server" id="contact_us" Text="Contact"
    OnClick="contactUS_Click" />
    </form>
    </asp:panel>


    <asp:panel id="panelMailSent" runat="server" Visible="False">
    An e-mail has been sent. We will contact you soon!
    </asp:panel>
    </body>
    </html>
    Henry Stock, Aug 16, 2008
    #1
    1. Advertising

  2. Henry Stock

    Henry Stock Guest

    Note: Since I wrote this I learned that System.Web.Mail is deppricated
    "Henry Stock" <> wrote in message
    news:uz1vrL1$...
    > My ISP provides this sample for an ASP.NET capable email form.
    >
    > If you have any idea about how to do the following, I would greatly
    > appreciate your help.
    >
    > I have a few alterations that I would like to implement, but I am not sure
    > where to begin.
    >
    > First:
    >
    > I want to implement the code in a codebehind page instead of in the
    > mailform.aspx page. I am not sure where I would put the code. I also
    > know that there are differences in background operations between ASP.NET
    > 1.1 and ASP.NET 2.0, but I don't know if the code would differ much. In
    > other stuff I found on the internet, the SMTP server was identified in a
    > <mailsettings> section in the web.config file. That seems cleaner to me,
    > but I don't know how the code would change. I probably would skip the code
    > identifying the server.
    >
    > Second:
    >
    > I already have an old mail form that was implemented using a CGI. I also
    > used a javascript based CAPTCHA function in that form to cut down on
    > automated spam.
    > In that instance the old form tag included and action attribute that
    > pointed to the cgi and an onsubmit="return jcap()" function that invoked
    > the javascript; elsewhere in the page there was a call to another
    > javascript that implemented the image that needed to be verified. I
    > would still like to use that script to prevent autospammers. I am not sure
    > how to call the javascript function jcap() before the contactUS_Click
    > event handler.
    >
    > The event handler is server based, so I am hoping that I can just leave
    > the call in the form onsubmit attribute because I think that should fire
    > first.
    >
    > As for the email based script I am guessing that I should check the
    > page.IsPostback variable and excute it only when that is true.
    >
    > Third:
    > I want to add some additional validation on form fields. Specifically I
    > would like to test for a valid email address if nothing else. I am
    > planning a form that has more data elements such as name, address, phone
    > number, etc that I expect to concatenate into the message body.
    >
    > Fourth:
    > I want to convert the script from VB.NET to C#
    >
    >
    > ' ============================================
    > <% @Import Namespace="System.Web.Mail" %>
    > <script language="vb" runat="server">
    >
    > Sub contactUS_Click(sender as Object, e as EventArgs)
    >
    > 'Create an instance of the MailMessage class
    > Dim objMM as New MailMessage()
    >
    > objMM.To = ""
    > objMM.From = email.Text
    >
    > 'If you want to CC this e-mail to someone else
    > 'objMM.Cc = ""
    >
    > 'e-mail format. Can be Text or Html
    > objMM.BodyFormat = MailFormat.Text
    >
    > 'Set the priority - options are High, Low, and Normal
    > objMM.Priority = MailPriority.Normal
    >
    > 'Set the subject
    > objMM.Subject = "1&1 Contact US"
    >
    > 'Set the body
    > objMM.Body = message.Text
    >
    > 'Smtp Server
    > SmtpMail.SmtpServer = "mrelay.perfora.net"
    >
    > 'Send the message
    > SmtpMail.Send(objMM)
    >
    > panelSendEmail.Visible = false
    > panelMailSent.Visible = true
    >
    > End Sub
    >
    > </script>
    >
    > <html>
    > <body>
    > <asp:panel id="panelSendEmail" runat="server">
    > <form runat="server">
    > <h2>CONTACT US FORM</h2>
    >
    > <b>Your Name:</b>
    > <asp:textbox id="name" runat="server" />
    > <br>
    >
    > <b>Your Email Address:</b>
    > <asp:textbox id="email" runat="server" />
    > <p>
    >
    > <b>Your Message:</b><br>
    > <asp:textbox id="message" TextMode="MultiLine"
    > Columns="40" Rows="10" runat="server" />
    > <p>
    >
    > <asp:button runat="server" id="contact_us" Text="Contact"
    > OnClick="contactUS_Click" />
    > </form>
    > </asp:panel>
    >
    >
    > <asp:panel id="panelMailSent" runat="server" Visible="False">
    > An e-mail has been sent. We will contact you soon!
    > </asp:panel>
    > </body>
    > </html>
    >
    Henry Stock, Aug 16, 2008
    #2
    1. Advertising

  3. re:
    !> Note: Since I wrote this I learned that System.Web.Mail is deppricated

    Not for ASP.NET 1.1 apps.



    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en espaƱol : http://asp.net.do/foros/
    ======================================
    "Henry Stock" <> wrote in message news:%23JXAX52$...
    > Note: Since I wrote this I learned that System.Web.Mail is deppricated
    > "Henry Stock" <> wrote in message
    > news:uz1vrL1$...
    >> My ISP provides this sample for an ASP.NET capable email form.
    >>
    >> If you have any idea about how to do the following, I would greatly
    >> appreciate your help.
    >>
    >> I have a few alterations that I would like to implement, but I am not sure
    >> where to begin.
    >>
    >> First:
    >>
    >> I want to implement the code in a codebehind page instead of in the
    >> mailform.aspx page. I am not sure where I would put the code. I also
    >> know that there are differences in background operations between ASP.NET
    >> 1.1 and ASP.NET 2.0, but I don't know if the code would differ much. In
    >> other stuff I found on the internet, the SMTP server was identified in a
    >> <mailsettings> section in the web.config file. That seems cleaner to me,
    >> but I don't know how the code would change. I probably would skip the code
    >> identifying the server.
    >>
    >> Second:
    >>
    >> I already have an old mail form that was implemented using a CGI. I also
    >> used a javascript based CAPTCHA function in that form to cut down on
    >> automated spam.
    >> In that instance the old form tag included and action attribute that
    >> pointed to the cgi and an onsubmit="return jcap()" function that invoked
    >> the javascript; elsewhere in the page there was a call to another
    >> javascript that implemented the image that needed to be verified. I
    >> would still like to use that script to prevent autospammers. I am not sure
    >> how to call the javascript function jcap() before the contactUS_Click
    >> event handler.
    >>
    >> The event handler is server based, so I am hoping that I can just leave
    >> the call in the form onsubmit attribute because I think that should fire
    >> first.
    >>
    >> As for the email based script I am guessing that I should check the
    >> page.IsPostback variable and excute it only when that is true.
    >>
    >> Third:
    >> I want to add some additional validation on form fields. Specifically I
    >> would like to test for a valid email address if nothing else. I am
    >> planning a form that has more data elements such as name, address, phone
    >> number, etc that I expect to concatenate into the message body.
    >>
    >> Fourth:
    >> I want to convert the script from VB.NET to C#
    >>
    >>
    >> ' ============================================
    >> <% @Import Namespace="System.Web.Mail" %>
    >> <script language="vb" runat="server">
    >>
    >> Sub contactUS_Click(sender as Object, e as EventArgs)
    >>
    >> 'Create an instance of the MailMessage class
    >> Dim objMM as New MailMessage()
    >>
    >> objMM.To = ""
    >> objMM.From = email.Text
    >>
    >> 'If you want to CC this e-mail to someone else
    >> 'objMM.Cc = ""
    >>
    >> 'e-mail format. Can be Text or Html
    >> objMM.BodyFormat = MailFormat.Text
    >>
    >> 'Set the priority - options are High, Low, and Normal
    >> objMM.Priority = MailPriority.Normal
    >>
    >> 'Set the subject
    >> objMM.Subject = "1&1 Contact US"
    >>
    >> 'Set the body
    >> objMM.Body = message.Text
    >>
    >> 'Smtp Server
    >> SmtpMail.SmtpServer = "mrelay.perfora.net"
    >>
    >> 'Send the message
    >> SmtpMail.Send(objMM)
    >>
    >> panelSendEmail.Visible = false
    >> panelMailSent.Visible = true
    >>
    >> End Sub
    >>
    >> </script>
    >>
    >> <html>
    >> <body>
    >> <asp:panel id="panelSendEmail" runat="server">
    >> <form runat="server">
    >> <h2>CONTACT US FORM</h2>
    >>
    >> <b>Your Name:</b>
    >> <asp:textbox id="name" runat="server" />
    >> <br>
    >>
    >> <b>Your Email Address:</b>
    >> <asp:textbox id="email" runat="server" />
    >> <p>
    >>
    >> <b>Your Message:</b><br>
    >> <asp:textbox id="message" TextMode="MultiLine"
    >> Columns="40" Rows="10" runat="server" />
    >> <p>
    >>
    >> <asp:button runat="server" id="contact_us" Text="Contact"
    >> OnClick="contactUS_Click" />
    >> </form>
    >> </asp:panel>
    >>
    >>
    >> <asp:panel id="panelMailSent" runat="server" Visible="False">
    >> An e-mail has been sent. We will contact you soon!
    >> </asp:panel>
    >> </body>
    >> </html>
    >>

    >
    >
    >
    Juan T. Llibre, Aug 16, 2008
    #3
  4. Henry Stock

    Henry Stock Guest

    In answer to why use code behind page:
    According to Microsoft it allows for cleaner separation of of code and
    design issues.



    I wasn't clear on that. Sorry. My ISP is running ASP.NET 2.0. which is
    good for me. I am trying to use the newsest stuff my tools will support and
    I have Visual Studio 2005

    "Mark Rae [MVP]" <> wrote in message
    news:%232H4iN4$...
    > "Henry Stock" <> wrote in message
    > news:uz1vrL1$...
    >
    >> My ISP provides this sample for an ASP.NET capable email form.

    >
    > What version of ASP.NET is running on your ISP's webserver?
    >
    >> I want to implement the code in a codebehind page instead of in the
    >> mailform.aspx page.

    >
    > Why? Despite what some people will tell you, there is absolutely no
    > benefit whatsoever in doing this. In fact, many well-respected developers
    > prefer this type of inline coding for aspx pages, and only use class pages
    > for common / shared functionality...
    >
    >> I also know that there are differences in background operations between
    >> ASP.NET 1.1 and ASP.NET 2.0

    >
    > There are - that's why you need to find out which version your ISP is
    > running...
    >
    >> Specifically I would like to test for a valid email address

    >
    > http://www.google.co.uk/search?sour...52GB252&q=JavaScript email address validation
    >
    >> I want to convert the script from VB.NET to C#

    >
    > There are dozens of online converters - GIYF...
    >
    > But the first thing is to find out what version of ASP.NET your ISP is
    > running...
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    Henry Stock, Aug 16, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    55,443
  2. Robert Brewer
    Replies:
    2
    Views:
    368
    Ville Vainio
    Oct 5, 2004
  3. Robert L. Smith, Jr.

    How to Link a Miscellaneous File

    Robert L. Smith, Jr., Apr 9, 2005, in forum: C Programming
    Replies:
    3
    Views:
    324
    Mark McIntyre
    Apr 9, 2005
  4. Robert L. Smith, Jr.

    Re: How to Link a Miscellaneous File

    Robert L. Smith, Jr., Apr 10, 2005, in forum: C Programming
    Replies:
    4
    Views:
    318
    Mark McIntyre
    Apr 11, 2005
  5. Geico Caveman
    Replies:
    0
    Views:
    521
    Geico Caveman
    Oct 2, 2008
Loading...

Share This Page