Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
02-10-2011, 02:22 PM #1
- Join Date
- Mar 2010
- Thanked 0 Times in 0 Posts
Contact Form w/ Confirmation Page (missing something small)
I am new to ASP.NET, and reading through online materials such as this forum has really helped me gather a broad scope about what this language is and does. It's a great forum here, and I have referenced it many times.
I am working on a basic contact form in ASPX with VB with four easy textboxes. On submit, I want the form to be sent to an e-mail address and have the sender be sent to a confirmation page. For the life of me, I cannot find the mistake that is causing my confirmation redirect to be unread. On submit, it always goes to my error page.
I have already completed a form like this and have even tried working from this file; however, I cannot manage to find the solution. I am on a deadline of 24 hours to complete this, and I have already been pulling my hair for a few days. I know it's something so simple, yet my eyes are missing it from too much view probably. May someone lend me your eyes and review my code below? I would truly appreciate your time and help.
I have the full page code attached, but the problem seems to only be in the scripting tags. For quick view, this is pasted below:
<%@ Page language="VB" masterpagefile="orientation.master" title="New Student Orientation Request" %>
<%@ MasterType VirtualPath="orientation.master" %>
<%@ Import Namespace="System.Net.Mail" %>
<asp:Content id="Content1" runat="server" contentplaceholderid="ContentPlaceHolder1">
<script runat="server" type="text/vb">
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Page.IsPostBack Then
Dim currentDate As DateTime = DateTime.Now
Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If Page.IsValid Then
Dim strFirstName, strLastName, strStudentNumber As String
Dim strEmailAddress As String
Dim mpContentPlaceHolder As ContentPlaceHolder
Dim strFrom, strTo, strSubject, strBody As String
Dim msgBody As String
mpContentPlaceHolder = CType(Master.FindControl("ContentPlaceHolder1"), ContentPlaceHolder)
strFirstName = Left(CType(mpContentPlaceHolder.FindControl("FirstName"), TextBox).Text, 25)
strLastName = Left(CType(mpContentPlaceHolder.FindControl("LastName"), TextBox).Text, 25)
strStudentNumber = Left(CType(mpContentPlaceHolder.FindControl("StudentNumber"), TextBox).Text, 7)
strEmailAddress = Left(CType(mpContentPlaceHolder.FindControl("EmailAddress"), TextBox).Text, 50)
msgBody = "First: " & strFirstName & vbCrLf & "Last: " & strLastName & vbCrLf & "Number: " & strStudentNumber & vbCrLf & "Email: " & strEmailAddress & vbCrLf &
Dim fromAddress As New MailAddress(strEmailAddress)
Dim toAddress As New MailAddress("firstname.lastname@example.org")
Dim msg As New MailMessage(fromAddress, toAddress)
msg.Subject = "Orientation Cancellation Request"
msg.Body = msgBody
Dim mailSender As New SmtpClient()
mailSender.Host = "www.host.com"
Catch ex As Exception
Thank you again for any help you may have to offer. I would also like to help self-teach myself ASP.NET. If you have recommendations of books, that would be wonderful as well.
All the best,