Forums

ASP

This topic is locked

ASP.Net form problem

Posted 15 Sep 2005 18:21:46
1
has voted
15 Sep 2005 18:21:46 neoz 123 posted:
Can anyone tell me why this form does not capture the users input from the drop down when it is emailed? I get all the other info from the text boxes. Just not the drop down.

##############CODE ########################
Imports RFI.DBConnection
Imports System.Data.OleDb
Imports System.Web.Mail

Public Class RequestAccess
Inherits System.Web.UI.Page

Dim dbPath As String = "database/RFI_SYSTEM.mdb"
Dim db As New DBConnection(dbPath)
Dim strSQL, strSQL2, strSQL3 As String
Dim MyMail As MailMessage = New MailMessage
Dim myMailConnection As SmtpMail
Dim RFIManager_email_address As String
Dim User_rank As String

Protected WithEvents ddlRanks As System.Web.UI.WebControls.DropDownList
Protected WithEvents btnSave As System.Web.UI.WebControls.Button
Protected WithEvents btnReset As System.Web.UI.WebControls.Button
Protected WithEvents txtFName As System.Web.UI.WebControls.TextBox
Protected WithEvents txtLName As System.Web.UI.WebControls.TextBox
Protected WithEvents txtEmail As System.Web.UI.WebControls.TextBox
Protected WithEvents txtPhone As System.Web.UI.WebControls.TextBox
Protected WithEvents txtUnit As System.Web.UI.WebControls.TextBox
Protected WithEvents txtReason As System.Web.UI.WebControls.TextBox
Protected WithEvents txtLogin As System.Web.UI.WebControls.TextBox
Protected WithEvents txtPassword As System.Web.UI.WebControls.TextBox
Protected WithEvents rfvFName As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents rfvLName As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents rfvRank As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents rfvEmail As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents rfvPhone As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents rfvUnit As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents rfvReason As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents rfvLogin As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents rfvPassword As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents lblErrorMessage As System.Web.UI.WebControls.Label
' Dim myReader As OleDbDataReader

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
lblErrorMessage.Visible = False
db.dbOpen()
strSQL = "SELECT * FROM rank order by rank_id ASC"

Dim myReader As OleDbDataReader
myReader = db.recorsdet(strSQL)

ddlRanks.DataSource = myReader
ddlRanks.DataTextField = "rank_desc"
ddlRanks.DataBind()



'ddlRanks.DataSource = myReader
'ddlRanks.DataTextField = "rank_desc"
'ddlRanks.DataBind()
'ddlRanks.Items.Insert(0, New ListItem("-- Choose a Your Rank --")
myReader.Close()
db.dbClose()
db = Nothing
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim db As New DBConnection(dbPath)
Dim myReader As OleDbDataReader
Dim emailBody As String

strSQL2 = "INSERT INTO RFI_RQA (rank, fname, lname, phone_number, email_address, user_password, login, reason, unit) VALUES ('" & ddlRanks.SelectedItem.ToString & "','" & txtFName.Text & "','" & txtLName.Text & "','" & txtPhone.Text & "','" & txtEmail.Text & "','" & txtPassword.Text & "','" & txtLogin.Text & "','" & txtReason.Text & "','" & txtUnit.Text & "')"



Try
db.dbOpen()
db.executeQuery(strSQL2)
Catch ex As Exception
lblErrorMessage.Text = "Error connecting to the database.<br> " & ex.Message.ToString
lblErrorMessage.Visible = True
db.dbClose()
db = Nothing
Finally
db = Nothing
db.dbClose()
End Try

db.dbClose()

'If Not ddlRanks.SelectedItem.ToString = "-- Choose a Rank --" Then
User_rank = ddlRanks.SelectedItem.ToString
'If User_rank = "-- Choose a Rank --" Then
' Response.Redirect("login.aspx"
'Else
' Response.Write(User_rank)
'End If

Try
strSQL3 = "SELECT * FROM RFI_Users WHERE sec_level='RFI Manager'"
db.dbOpen()

myReader = db.recorsdet(strSQL3)
myReader.Read()
RFIManager_email_address = myReader("email_address"

Catch ex As Exception
lblErrorMessage.Text = "Error connecting to the database.<br> " & ex.Message.ToString
lblErrorMessage.Visible = True
db.dbClose()
db = Nothing
Finally
db = Nothing
db.dbClose()
End Try

If Not User_rank = "-- Choose a Rank --" Then

emailBody = emailBody & "First Name: " & txtFName.Text & vbCrLf
emailBody = emailBody & "Last Name: " & txtLName.Text & vbCrLf
emailBody = emailBody & "Rank: " & User_rank & vbCrLf
'emailBody = emailBody & "Rank: " & ddlRanks.SelectedItem.ToString & vbCrLf
emailBody = emailBody & "Email address: " & txtEmail.Text & vbCrLf
emailBody = emailBody & "Requested Login: " & txtLogin.Text & vbCrLf
emailBody = emailBody & "Requested Password: " & txtPassword.Text & vbCrLf
emailBody = emailBody & "Reason for access: " & txtReason.Text & vbCrLf


MyMail.From = txtEmail.Text

MyMail.To = " " 'RFIManager_email_address
MyMail.Subject = "Request Access to RFI System"
MyMail.Body = emailBody

Try
myMailConnection.SmtpServer = "MSTP03E"
myMailConnection.Send(MyMail)

myReader.Close()
db = Nothing

Catch ex As Exception
lblErrorMessage.Text = "Error trying to send the request email. <br>" & ex.Message.ToString
lblErrorMessage.Visible = True
db.dbClose()
db = Nothing
Finally
db = Nothing
db.dbClose()
End Try
Else
lblErrorMessage.Text = "Please Select a Rank"
lblErrorMessage.Visible = True
End If

End Sub

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click

End Sub

Private Sub ddlRanks_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlRanks.SelectedIndexChanged

End Sub
End Class

Reply to this topic