OWES - Resources


Click here - Request-a-Quote

Click here - Web development partner

Creating a simple email form content using Asp.net

The article is about asp.net postback feature for email form content. You should have a form with the runat="server" attribute and server controls.

Initially your button server control should have the attribute OnClick. The OnClick value will be alike to the Sub control that sends the email. The value selected for OnClick attribute is is "SendEmail". In coding part at the top of the page import the right Namespace in order that the right classes will load with the page.

The Sub must follow the OnClick selection and have the same name be supposed to start in this way:

After that we define the total message as one variable Dim:

Also in support of all line the message start should be named with the variables followed by "+=" sign for adding the variable. Next is the display text can be a label / Header, it should be enclosed in quotation marks and the variables so as to bring into the massage.
Here is the code that works and its description for your clear and perfect understanding.

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


Here the call on variable is included for your understanding.

Now you can start to put the codes together.

vbcrlf is to create a new line in the email. Text should be added inside the quotation marks and a space between the text and & and also space at the start of vbcrlf code.This makes as one absolute line in your email message.

Next line of code is to display the text and the value of the item from the form. It should be separated by spaces and the item is listed in “contactname” Text from the form.

In the place of Text, it has .SelectedValue code. This takes the place of the .Text as soon as you have a multiple choice or drop-down server control selection, in the case of a group of radio buttons. This helps in identifying the selected value from that group.

Additional Tip: We have another case and it has .SelectedIndex. It gives a number as a replacement for value. If we have a list of four possible selection, and chosen the second one, the .SelectedIndex will return the number 2 instead of the text for that selection. This will be helpful if you are querying a database.

This piece of code adds few more variables. The System.Web.Mail class imported into the file should be proficient to identify them correctly.

MailObj.To=youremail@yourdomain.com « add your email address, I have added an example.

MailObj.FROM=email.text « email address can be specified in quotes or can be included with the declaration for the server control which passes along the address.

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

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

A redirect can be done to another page, which tells the form mailer was a success before you end the Sub:

Response.Redirect("thankyou.aspx") and of course, you have to end the Sub properly:

Now you can send a email form content using asp.net. Hope this article would have given a better idea.

Write us about your comments and feedback.

Creating a simple email form content using Asp.net