homepage Welcome to WebmasterWorld Guest from 54.242.231.109
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
Contact Form w/ Confirmation Page (missing something small)
ASP.NET / VB Contact Form
creativeedg10




msg:4265146
 2:08 pm on Feb 10, 2011 (gmt 0)

Hi everyone,

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, but the problem seems to only be in the scripting tags. For quick view, only 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
End If
End Sub

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 &

'Generate email
Dim fromAddress As New MailAddress(strEmailAddress)
Dim toAddress As New MailAddress("name@email.com")
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"
Try
mailSender.Send(msg)
Catch ex As Exception
End Try

Response.Redirect("confirmation_cancel.aspx")
End If
End Sub

</script>

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,

 

Ocean10000




msg:4265154
 2:41 pm on Feb 10, 2011 (gmt 0)

My best guess that it fails before the email gets sent or the redirect is even reached. And that it not finding one of the controls for some reason.

Fotiman




msg:4265162
 2:48 pm on Feb 10, 2011 (gmt 0)

If you comment out all the pieces relating to sending the mail, does it still error? If so, you might try uncommenting line by line to try and find the trouble spot.

hal12b




msg:4265862
 9:05 pm on Feb 11, 2011 (gmt 0)

I wouldn't use a redirect. That's more for classic ASP. Try using a view state.

creativeedg10




msg:4266771
 1:08 pm on Feb 14, 2011 (gmt 0)

Thank you all for your responses. I ended up using a different approach and got it to work somehow. I still want to jump back and play with this code a bit so I can resolve it. I have not heard of view state, but I will look into this. Yes, I have tried commenting out many areas to see if that was an issue as well, but I didn't get far with that unfortunately.

Thank you all for the help. I will look into it some more and keep you posted with what I find, if anything.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved