Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2011
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.83 KB | None | 0 0
  1.     <script runat="server">
  2.         Protected Sub SubmitForm_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  3.             If Not Page.IsValid Then Exit Sub
  4.  
  5.             Dim SendResultsTo As String = "aj@jtnetinc.com"
  6.             Dim smtpMailServer As String = "mail.ajtroxell.com"
  7.             Dim smtpUsername As String = "aj+ajtroxell.com"
  8.             Dim smtpPassword As String = "ajax67"
  9.             Dim MailSubject As String = "Form Results"
  10.  
  11.             Try
  12.                 Dim txtQ As TextBox = Me.FormContent.FindControl("TextBoxQ")
  13.                 If txtQ IsNot Nothing Then
  14.                     Dim ans As String = ViewState("hf1")
  15.                     If ans.ToLower <> txtQ.Text.ToLower Or ans.ToUpper <> txtQ.Text.ToUpper Then
  16.                         Me.YourForm.ActiveViewIndex = 3
  17.                         Exit Sub
  18.                     End If
  19.                 End If
  20.  
  21.                 Dim FromEmail As String = SendResultsTo
  22.                 Dim msgBody As StringBuilder = New StringBuilder()
  23.                 Dim sendCC As Boolean = False
  24.  
  25.            
  26.                 For Each c As Control In Me.FormContent.Controls
  27.                     Select Case c.GetType.ToString
  28.                         Case "System.Web.UI.WebControls.TextBox"
  29.                             Dim txt As TextBox = CType(c, TextBox)
  30.                             If txt.ID.ToLower <> "textboxq" Then
  31.                                 msgBody.Append(txt.ID & ": " & txt.Text & vbCrLf & vbCrLf)
  32.                             End If
  33.                             If txt.ID.ToLower = "email" Then
  34.                                 FromEmail = txt.Text
  35.                             End If
  36.                             If txt.ID.ToLower = "subject" Then
  37.                                 MailSubject = txt.Text
  38.                             End If
  39.                         Case "System.Web.UI.WebControls.CheckBox"
  40.                             Dim chk As CheckBox = CType(c, CheckBox)
  41.                             If chk.ID.ToLower = "checkboxcc" Then
  42.                                 If chk.Checked Then sendCC = True
  43.                             Else
  44.                                 msgBody.Append(chk.ID & ": " & chk.Checked & vbCrLf & vbCrLf)
  45.                             End If
  46.                            
  47.                         Case "System.Web.UI.WebControls.RadioButton"
  48.                             Dim rad As RadioButton = CType(c, RadioButton)
  49.                             msgBody.Append(rad.ID & ": " & rad.Checked & vbCrLf & vbCrLf)
  50.                         Case "System.Web.UI.WebControls.DropDownList"
  51.                             Dim ddl As DropDownList = CType(c, DropDownList)
  52.                             msgBody.Append(ddl.ID & ": " & ddl.SelectedValue & vbCrLf & vbCrLf)
  53.                     End Select
  54.                 Next
  55.                 msgBody.AppendLine()
  56.                
  57.                 msgBody.Append("Browser: " & Request.UserAgent & vbCrLf & vbCrLf)
  58.                 msgBody.Append("IP Address: " & Request.UserHostAddress & vbCrLf & vbCrLf)
  59.                 msgBody.Append("Server Date & Time: " & DateTime.Now & vbCrLf & vbCrLf)
  60.  
  61.                 Dim myMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
  62.                 myMessage.To.Add(SendResultsTo)
  63.                 myMessage.From = New System.Net.Mail.MailAddress(FromEmail)
  64.                 myMessage.Subject = MailSubject
  65.                 myMessage.Body = msgBody.ToString
  66.                 myMessage.IsBodyHtml = False
  67.                 If sendCC Then myMessage.CC.Add(FromEmail)
  68.  
  69.                
  70.                 Dim basicAuthenticationInfo As New System.Net.NetworkCredential(smtpUsername, smtpPassword)
  71.                 Dim MailObj As New System.Net.Mail.SmtpClient(smtpMailServer)
  72.                 MailObj.Credentials = basicAuthenticationInfo
  73.                 MailObj.Send(myMessage)
  74.  
  75.                 Me.YourForm.ActiveViewIndex = 1
  76.             Catch
  77.                 Me.YourForm.ActiveViewIndex = 2
  78.             End Try
  79.         End Sub
  80.  
  81.         Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
  82.             If Not Page.IsPostBack Then
  83.                 Dim lbl As Label = Me.FormContent.FindControl("labelq")
  84.                 If lbl IsNot Nothing Then
  85.                     Dim rq(3) As String
  86.                     rq(0) = "Is fire hot or cold?"
  87.                     rq(1) = "Is ice hot or cold?"
  88.                     rq(2) = "Is water wet or dry?"
  89.  
  90.                     Dim ra(3) As String
  91.                     ra(0) = "hot"
  92.                     ra(1) = "cold"
  93.                     ra(2) = "wet"
  94.                    
  95.                     Dim rnd As New Random
  96.                     Dim rn As Integer = rnd.Next(0, 3)
  97.                     lbl.Text = rq(rn)
  98.                     ViewState("hf1") = ra(rn)
  99.                 End If
  100.             End If
  101.         End Sub
  102.     </script>
  103.  
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement