Latest Web News

Doc Searls Produces Conference Wrapup
The close of the Syndicate Conference in New York came with Searls' keynote address, where he touched on the issue of "The Return to Producerism."

Amanda Congdon Talks Syndicating Videoblogs At Syndicate NY
Video blogs shouldn't be called "Internet TV"; Congdon said that completely devalues them. "They are a totally unique video experience, usually more casual."

Yahoo! Finance Badges Detailed
Another component in Yahoo's syndication strategy will enable publishers to embed financial information into their sites and blogs. Mani Kulasooriya from Yahoo said the toughest part of creating Yahoo! Finance Badges was not the technical side.

Google Notebook Goes Live
As promised at Google's Press Day event last week, its Notebook service from Google Labs has been turned on in beta for users to try. Firefox users will have an easy time of adding...

Justice Unworried About IE7 Search
Google had complained to US and European antitrust regulators about Microsoft including a search box with MSN Search as the default in Internet Explorer 7, but the Department of Justice had no problems with the feature.

Microsoft Targeting Google, Maybe
Frequent media stories that aim at pushing Microsoft and Google into an all-out battle royale don't really hit the mark according to Microsoft's CEO.

Can The FCC Save Net Neutrality?
The chief complaints of the telecommunications industry regarding the heated Network Neutrality debate are that regulation limits their ability to compete...

Schmidt: Google Has Just Begun
Google's CEO Eric Schmidt told media attendees at Press Day that search is the inevitable outcome of what is and will happen on the Internet.

Google Fills California Tax Coffers
All of that insider selling by Google insiders like Eric Schmidt, Larry Page, and Sergey Brin helped boost the state's take in personal income tax.

Microsoft Mapping The Real-Time World
Google may want to organize the world's information, but Microsoft wants to let you know how long you're going to have to wait for a table at Red Lobster on Friday evening.

Windows Live Messenger Offers VoIP
Microsoft will partner with Verizon to deliver PC to phone calling services as part of Live Messenger's new features being made available in the public beta release.

Google Threatens Wireless Market
A mixture of free wireless broadband connections and voice over Internet protocol applications will leave the mobile network market in the United States a smoldering unmourned wreck consigned to the scrapheap, but only in major cities.

Ballmer Emphasizes RSS Importance
Internet Explorer 7 and the Windows Vista operating system will support RSS, and Microsoft CEO Steve Ballmer thinks RSS feeds will grow in importance to Internet users.

Microsoft May Delay Vista Again
A two-sentence post from research firm Gartner has caused some uproar in the technology world, as Gartner researchers claim Microsoft will miss its release of Vista by three months, pushing it back into 2007.

Amazing Race Feeds Into E-Commerce
Reality show contestants don't vanish into fictional poofs at the show's conclusion. They're not the cast of Friends; there is life after the show. Chip Arndt, half of the winning duo of Amazing Race 4...

PreFound Hosting Social Network Roundtable
The PreFound.com social search engine plans to hold a Kentucky Derby Roundtable with several notable guests venturing to the Bluegrass State to discuss social communities and search.

Google Complains To Feds About IE7
Google has given its new lobbyists in Washington DC something to do, as the company expressed concern to both the Justice Department and the European Commission about Microsoft's Internet Explorer 7 having MSN Search as its default search engine.



Recent Articles

Doing The Walkthrough With ASP
Online options exist for learning how to work with ASP.Net and Microsoft's Visual Studio, with free and fee choices available.

ASP.Net: Great Products, Great Caching
Fans of ASP.Net products can vote for their choice in the asp.netPro Readers' Choice Awards online; also, Gadgetopia's Deane Barker praises...

ASP.NET “How Do I” Video Series
Microsoft put together a video series called "How Do I." The purpose behind the series is to help educate developers by answering common questions...

Migrating A Web Site To ASP.NET
Do you want to encourage repeat site visits? Capture and easily process visitor information? Do you want to make information more findable?

ASP Leads JSP In Job Openings
It would not be a bad idea to be skilled in both ASP and JSP, as a number of open positions found in a recent...

IIS and ASP: Microsoft's Server
Despite Microsoft's dominance of everything to do with computers, their web server software sits on...

05.19.06


ASP.NET - Emailing Form Content

By John Wooton

One of the problems that I first encountered when I was learning the ropes was that a book can never tell you everything.

So as I was struggling to learn the development techniques that I apply, I had to frequently rely on online resources or forums to get the job done. This was not easy, especially when you are trying to solve a problem and all you get is errors.

So, one of my goals with my blog was to help all of you out there who are struggling to get on your feet with new technologies. It's kind of like repayment for all those out there who have helped me and still continue to help me learn.

So today, I want to show you how it is possible to email form content to yourself or another person using the asp.net postback feature and a little creativity.

I am assuming that your reading this post because you have a form with the runat="server" attribute and well formed server controls already ready to go. Server controls take quite a long time to explain so if you don't already have your form ready to go, I suggest you read up on the many tutorials available that can teach you about server controls.

So how is it possible to do this on the page. Well once you understand how it works, you'll never forget how simple it is.

First you have to make sure your button server control has the attribute OnClick. The value for OnClick will be equal to the value of the Sub control that will send the email. The value I selected for the OnClick attribute is "SendEmail". Here's what it looks like: In the code section at the top of the page, make sure you import the right Namespace so that the right classes will load with the page. The only one for this task that you have to worry about is the System.Web.Mail Namespace. For vb users, the correct usage just below the page attribute at the top of the page is this:

For the Sub which should follow the OnClick selection and have the same name should start like this:

Sub SendEmail(Sender As Object, e As EventArgs)

Then we define the entire message as one variable Dim:

Dim msg as String

Use proven SEO tools to get high search engine rankings.

And for each line in the message you start it off with the name of the variable and followed by the "+=" sign to add it to the variable. Then for text that you want to display like a label or header or something, you make sure that it is enclosed in quotation marks and for variables that you are bringing into the massage (ie: for the text from a taxtbox in the form that you want mail, you make sure that you include the technical name for that selection. For instance, let me write out a couple lines of code so you can see how it all works and then I'll describe the details so you can understand:

Dim msg as String

msg+="Form mailer header" & vbcrlf

msg+="Contact Name : " & contactname.Text & vbcrlf

msg+="Contact Email : " & email.Text & vbcrlf

msg+="Agree To Terms : " & terms.SelectedValue & vbcrlf


Now I've included a couple of different items here so you can understand. First, I made sure I included the call on the variable:

Dim msg as String

This is so you can begin to put the pieces together. Then I included one line that I want as full text and include no values from the form.

msg+="Form mailer header" & vbcrlf


Notice I included something new: vbcrlf. This tells the parser to create a new line in the email. Everything that is text is fully enclosed in the quotation marks and there is a space between that and the character &, then there is another space and the vbcrlf code. This would make one complete line in your email message.

msg+="Contact Name : " & contactname.Text & vbcrlf

The next line is a mix of two different items. First we have some text that we want to display, then the value of one of the items from the form. This is separated by spaces and the & character and the item from the form is now listed as contactname.Text. The text portion help the server identify that the text that was in the server control with the id of "contactname" is what is needed to be placed there. The next line is also similar to this.

msg+="Agree To Terms? " & terms.SelectedValue & vbcrlf

The final value that I've listed in this example is similar, but has a different suffix for the id information that you want to pass along. Instead of .Text, it has .SelectedValue. This takes the place of the .Text suffix when you have a drop-down server control or multiple choice selection, as in the case of a group of radio buttons. This would identify the selected value from that group. There is also another one for this specific case and that is .SelectedIndex. This gives a number instead of the value. It's the number of the value in the order they are presented in the list. So if I have a list of three possible answers or selection, and they choose the second one down, the .SelectedIndex would return the number 2 instead of the text for that selection. This is especially helpful if you are querying a database, but that'll be saved for another lesson.

So once you have your entire message laid out line by line we'll create another variable which will actually help to pull everything together and define the direction of the message variable "msg".

Dim MailObj as New MailMessage

This actually puts all the various pieces together. Under that, you need to add a few variables. The System.Web.Mail class that we imported into the file will be able to identify these and utilize them properly.

MailObj.To=johnpwooton@gmail.com <-put your email address, I added mine to give you an example.

MailObj.FROM=email.text <- specify an email address in quotes or include the declaration for the server control that is passing along the address.

MailObj.SUBJECT="Form Mail"

MailObj.BODY=msg

MailObj.BodyFormat = MailFormat.Text

SmtpMail.SmtpServer ="your.smtpserver.com" <- your smtp server address. You must have this to send the message.

SmtpMail.Send(MailObj) <-tells the Sub to send the message.


You can also add an optional redirect to another page that tells them the form mailer was a success by using this before you end the Sub:

Response.Redirect("thankyou.aspx")

and of course, you have to end the Sub properly: End Sub

So that's it. Pure and simple. Of course if you have any questions, post a comment and I'll do what I can to help you out. I have used this particular script on other pages on my sites and it has worked very well.


About the Author:
David Utter is a staff writer for WebProNews covering technology and business.

About WebProASP
WebProASP is a collection of up to date tutorials and insightful articles designed to help ASP users of any skill level implement successful ASP systems and practices. ASP Strategies and Tactics for Business

WebProASP is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQlProNews.com
ITcertificationNews.com SysAdminNews.com
WebProASP.com WirelessProNews.com
CProgrammingTrends.com ITManagementNews.com




-- WebProAsp is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2006 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article



ASP Strategies and Tactics for Business WebProASP News Archives About Us Feedback WebProASP Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact