#1
  1. No Profile Picture
    Devshed Gringo
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Location
    Toronto, Ontario
    Posts
    448
    Rep Power
    62

    Hard time inserting a simple redirect inside a class


    I'm new to ASP (not a big fan lol) and I have the fantastic job of updating a form that does NOT send a user to a thank you page... I could have wrote this all in PHP within an hour but I have to stick to asp for this one... If anyone can let me know where to place a redriect (and what? Response.Redirect("thanks.aspx")

    Many thanks

    Code:
    Imports System
    Imports System.Data
    Imports System.Data.OleDb
    Imports System.Data.SqlClient
    Imports System.Web.UI.Page
    Imports System.Web.UI.WebControls
    Imports System.IO
    Imports System.Net.Mail
    
    
    Partial Class NominationAppForm
        Inherits System.Web.UI.Page
    
    
        Function GetReader() As System.Data.IDataReader
            Dim connectionString As String = ConfigurationManager.AppSettings("Roster")
            Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
    
            Dim m_id As String
            Dim queryString As String
            m_id = Request.QueryString("id")
            queryString = "SELECT * FROM InfoSessions WHERE ID = " + m_id
    
    
            Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
            dbCommand.CommandText = queryString
            dbCommand.Connection = dbConnection
    
            dbConnection.Open()
            Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
    
            While dataReader.Read
    			' not used anywhere?
    		
                ' Literal1.Text = "CMA Ontario Information Session"
                ' Literal2.text = dataReader.GetValue(2)
                'Literal3.Text = dataReader.GetValue(3)
                'Literal5.Text = dataReader.GetValue(5)
                ' Literal6.Text = dataReader.GetValue(6)
                'Literal7.Text = dataReader.GetValue(7)
                ' Literal8.Text = dataReader.GetValue(8)
                'Literal9.Text = dataReader.GetValue(9)
                'Literal10.Text = dataReader.GetValue(10)
    
            End While
            Return dataReader
            dbConnection.Close()
        End Function
    
    
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load
            panel1.Visible = True
            panel2.Visible = False
            panel3.Visible = False
            'Prefix.Focus()
            'Page.SetFocus(Prefix)
            'GetReader()
        End Sub
    
    
        Protected Sub bnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bnNext.Click
    
            FileUpload1.SaveAs(Path.Combine(Server.MapPath("filesBOG2010"), ui_cmanum.Text & "_" & Strings.Replace(Strings.FormatDateTime(Now(), DateFormat.LongTime), ":", "-") & "_" & FileUpload1.FileName))
    
            panel1.Visible = False
            Panel3.Visible = False
            panel2.Visible = True
    		
    		'user infomation (ui_)
            Lab_ui_cmanum.Text = ui_cmanum.Text
    		Lab_ui_lname.Text = ui_lname.Text
    
    
    
    
            Message.Text = "<BR>" & "<b>By clicking 'Submit', I hereby certify that the information provided is true and accurate.</b>" & "<BR>"
    
        End Sub
    
        Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click
            ' If (FileUpload1.HasFile) Then
            'FileUpload1.SaveAs(Path.Combine(Server.MapPath("Files"), CMAnumber.Text & "_" & Strings.Replace(Strings.FormatDateTime(Now(), DateFormat.LongTime), ":", "-") & "_" & FileUpload1.FileName))
            Insert()
            ' Else
            ' Message.Text = Firstname.Text & ", please go back and choose the file(s) to upload!"
            ' End If
        End Sub
    
        Protected Sub Insert()
            Dim m_id As String
            m_id = Request.QueryString("id")
            Dim connectionString As String = System.Configuration.ConfigurationManager.AppSettings("mith")
            Dim connection As SqlConnection = New SqlConnection(connectionString)
            connection.Open()
            Try
                Dim command As SqlCommand = _
                New SqlCommand("SPInsertNaf", connection)
                command.CommandType = CommandType.StoredProcedure
                
    			
    			command.Parameters.Add("@ui_cmanum", ui_cmanum.Text)
    
    
    
    
    
                command.Parameters.Add("@RegDate", Now())
                command.ExecuteNonQuery()
                'Message.Text = "Thank You!"
    
    
                '************* Email confimations *****************
                Dim ToAddress As String = ui_email.Text
                Dim Fromaddress As String = "eee"
                Dim mm As New MailMessage(Fromaddress, ToAddress)
                mm.Subject = "eee"
                mm.Body = "eee"
                mm.IsBodyHtml = True
                Try
                    Dim smtp As New SmtpClient
                    smtp.Host = "mail.etechhosting.ca"
                    smtp.Send(mm)
                Catch ex As Exception
                    Dim smail As New StreamWriter(Server.MapPath("common/Errormail.txt"), True)
                    smail.WriteLine(DateTime.Now.ToShortDateString.ToString & "--> " & ex.ToString)
                    smail.Flush()
                    smail.Close()
                End Try
                mm.Dispose()
    'put this email back to agull@
                Dim ToAddress2 As String = "eee"
                Dim Fromaddress2 As String = "eee"
                Dim mm2 As New MailMessage(Fromaddress2, ToAddress2)
                mm2.Subject = "eeee"
                mm2.Body = ui_fname.Text + " " + ui_lname.Text + " " + ui_cmanum.Text & _
                "email"
                mm2.IsBodyHtml = True
                Try
                    Dim smtp As New SmtpClient
                    smtp.Host = "mail.server.ca"
                    smtp.Send(mm2)
                Catch ex As Exception
                    Dim smail As New StreamWriter(Server.MapPath("common/Errormail.txt"), True)
                    smail.WriteLine(DateTime.Now.ToShortDateString.ToString & "--> " & ex.ToString)
                    smail.Flush()
                    smail.Close()
                End Try
                mm2.Dispose()
    
                
                panel1.Visible = False
                Panel3.Visible = True
                panel2.Visible = False
    
                Label221.Text = "email"
    
            Catch ex As Exception
                Console.WriteLine(ex.Message)
                'Throw
    			'need to find database and fix tables
            Finally
                connection.Close()
            End Try
        'redirect to thanks page
    	Response.Redirect("thanks.aspx", true)
    	
    	End Sub
    End Class
    Still don't know how to do a "Hello World"?
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,453
    Rep Power
    4539
    I see you're using asp.NET. I don't know how response.redirect works in NET, if it's like classic asp no more code on the asp page gets executed after response.redirect. The response.redirect is the same as header('location) in php.

    If you need more you might try the NET forum, this forum is mostly for classic ASP.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester

IMN logo majestic logo threadwatch logo seochat tools logo