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

Henry Stock

Usenet Archive
Joined
Feb 23, 2008
Messages
15
Reaction score
0
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

Usenet Archive
Joined
Apr 25, 2001
Messages
5,721
Reaction score
0
re:
!> Note: Since I wrote this I learned that System.Web.Mail is deppricated

Not for ASP.NET 1.1 apps.
 

Mark Rae MVP

Usenet Archive
Joined
Jul 3, 2007
Messages
4,107
Reaction score
0
"Henry Stock" wrote:

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?sourceid=navclient&hl=en-GB&ie=UTF-8&rlz=1T4GZEZ_en-GBGB252GB252&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...
 

Henry Stock

Usenet Archive
Joined
Feb 23, 2008
Messages
15
Reaction score
0
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

Usenet Archive
Joined
Jul 3, 2007
Messages
4,107
Reaction score
0
"Henry Stock" wrote:

[top-posting corrected]

>> 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...

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

That is completely incorrect.

> There are - that's why you need to find out which version your ISP is
> running...

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

System.Net.Mail, then...
http://www.systemnetmail.com/
http://msdn.microsoft.com/en-us/library/swas0fwc(VS.80).aspx
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top