|
Subject:
|
Email Form - Question from a Newbie
|
|
Posted By:
|
morgan270
|
Post Date:
|
9/8/2006 9:58:13 PM
|
I'm really, really new to programming in ASP.NET 2.0 (just got the book last night). I have a form page built in ASP.NET 2.0 with validators and am working on making the form collect the data and email it.
I've found a tutorial that explains it: http://aspnet101.com/aspnet101/tutorials.aspx?id=14
But I'm not sure where to put the sub doEmail code. When I put it below the label it just appears like text and not like code.
Can anyone out there help explain?
I need to get my form to email it's results. Thank you.
~ Morgan Mann http://www.1designsource.com
|
|
Reply By:
|
vincentt
|
Reply Date:
|
9/13/2006 8:09:50 AM
|
Hi Morgan let me help you with this. Assuming you are using Visual Studio or atleast the express edition for editing the .aspx pages. When you add the button in the aspx page, you will find that Visual Studio (VS) will show two tabs down, Design and Source tabs. What you need to do is be in the design mode and double click on the button.
when you do this, you will get the code file .aspx.vb or .aspx.cs (if C#) with the button_click event ie using the sample's button name you would get btnEmail_click. The confusion is in the name, what the user has done is named the button_click as doEmail instead of btnEmail_click. So what you can do is copy the code from the doEmail function and dump it in the btnEmail_click function body.
Now run the form and am sure your form will work 
|
|
Reply By:
|
morgan270
|
Reply Date:
|
9/13/2006 8:58:50 AM
|
Thanks for the help!!
I put in the things like you said and I changed my ID to match the IDs in the new code, but I still come up with an error, and I don't know how to redirect the page to another page once it is submitted.
|
|
Reply By:
|
dparsons
|
Reply Date:
|
9/13/2006 10:52:18 AM
|
For these lines to work:
Line 23: SmtpMail.SmtpServer = "mail.goquestrealty.com" Line 24: SmtpMail.Send(objEmail)
At the top of your page you have to do: (I assume you are using Visual Studio)
Imports System.Web.Mail
Then everything should execute just fine. After you call SmtpMail.Send(objEmail) you can do Response.Redirect("./somepage.aspx") to send the user to a new page.
"The one language all programmers understand is profanity."
|
|
Reply By:
|
morgan270
|
Reply Date:
|
9/13/2006 12:48:35 PM
|
I'm not sure where to put the code: Imports System.Web.Mail
Here's my page from the top to the Title tag.
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim sMsg As String sMsg += "Hi there - here's the information I entered in the form." & vbCrLf sMsg += "Name : " & txtName.Text & vbCrLf sMsg += "Phone : " & txtPhone.Text & vbCrLf sMsg += "Email : " & txtEmail.Text & vbCrLf sMsg += "Comments : " & txtComments.Text & vbCrLf Dim objEmail As New Mail.MailMessage objEmail.To = txtEmail.text objEmail.BCC = "" '<--- this would be where you can send it to yourself at the same time. objEmail.FROM = "" objEmail.SUBJECT = "Here's the subject of the email" objEmail.BODY = sMsg SmtpMail.SmtpServer = "" SmtpMail.Send(objEmail) Response.Redirect("") End Sub </script>
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Quest Realty - Contact Us</title>
|
|
Reply By:
|
dparsons
|
Reply Date:
|
9/13/2006 12:50:50 PM
|
Oh you are using a text editor, underneath <%@ Page Language="VB" %> add this line:
<%@Import Namespace="System.Web.Mail"%>
"The one language all programmers understand is profanity."
|
|
Reply By:
|
morgan270
|
Reply Date:
|
9/13/2006 1:31:20 PM
|
YES!!!!! It works!
Thank you all for your amazing help!
When I'm under less stress I'll have to learn more about ASP.NET 2.0. It's a very handy programming language. Glad I found this forum!
|
|
Reply By:
|
dparsons
|
Reply Date:
|
9/13/2006 2:00:03 PM
|
Glad it worked out for you.
"The one language all programmers understand is profanity."
|
|
Reply By:
|
morgan270
|
Reply Date:
|
9/13/2006 3:58:55 PM
|
Okay. One victory, one defeat.
I tried doing the same code for another page I'm working on for the same site and I'm getting errors whether I put in the Checkbox info at the top or not. Can you guys help?!
Here's a link to the page without any of the stuff in the JavaScript tag up top and it works, once I put the Dim info it cuts out.
|