Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 20th, 2004, 09:43 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default Super Easy Ques Response.Redirect

I am trying to post back to same page after user enters data.
When I used Response.Redirect it doesn't run.

I wanted to post back to same page to show label that were not visible in the first time view. When I use Response.Write it works fine, so I know everything works.

Can I use Response.Redirect to post to same page???
Any suggestions.

 
Old August 20th, 2004, 09:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You don't need to. ASP.NET automatically posts to the same page.

 
Old August 20th, 2004, 03:44 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is my code for Register.aspx.

How can I make this postback at a specific point in the code???????without using Response.Redirect("Register.aspx") -- which is posting back to itself.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblDupEmail.Text = "This Email Address already exists. <br> Please enter another or <a href='login.aspx' class='Orange'>go to Sign In page.</a>"
        lblError.Text = "An unexpected error occurred. Please try again."

        If IsPostBack Then
            If Not Session("Duplicate") Is Nothing Then
                lblDupEmail.Visible = True
            End If

            If Not Session("Error") Is Nothing Then
                lblError.Visible = True

            End If
        End If
    End Sub

    Public Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click
        If IsValid Then
            Dim myCONN As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))

            Dim sSql As String = "SELECT Email FROM Member WHERE Email = @Email"
            Dim selectCmd As New SqlCommand(sSql, myCONN)

            selectCmd.CommandType = CommandType.Text
            selectCmd.Connection = myCONN

            selectCmd.Parameters.Add("@Email", SqlDbType.NVarChar, 100)
            selectCmd.Parameters("@Email").Value = txtEmail.Text

            Dim bDuplicate As Boolean
            bDuplicate = False



            Dim da As SqlDataReader
            Try
                myCONN.Open()

                da = selectCmd.ExecuteReader(CommandBehavior.SingleRow)
                da.Read()
                sEmail = da.Item("Email")
                myCONN.Close()
                bDuplicate = True
                'This Response.Redirect doesn't work
                'When I put Response.Write("Duplicate Email") it works
                Response.Redirect("Register.aspx")

            Catch ex As Exception
                Me.Insert()

            Finally
                If myCONN.State = ConnectionState.Open Then
                    myCONN.Close()
                End If


            End Try

        End If

    End Sub







    Private Sub Insert()
        Dim myCONN As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))

        Dim sSql As String = "INSERT INTO OCVBUG_Member (FName, LName, Email, Password ) VALUES(@FName, @LName, @Email, @Password)"
        Dim insertCmd As New SqlCommand(sSql, myCONN)

        insertCmd.CommandType = CommandType.Text
        insertCmd.Connection = myCONN

        insertCmd.Parameters.Add("@FName", SqlDbType.NVarChar, 50)
        insertCmd.Parameters.Add("@LName", SqlDbType.NVarChar, 50)
        insertCmd.Parameters.Add("@Email", SqlDbType.NVarChar, 50)
        insertCmd.Parameters.Add("@Password", SqlDbType.NVarChar, 100)



        insertCmd.Parameters("@FName").Value = Replace(txtFName.Text, "'", "''")
        insertCmd.Parameters("@LName").Value = Replace(txtLName.Text, "'", "''")
        insertCmd.Parameters("@Email").Value = Replace(txtEmail.Text, "'", "''")

        Dim sPassword = txtPassword.Text
        sPassword = sPassword
        insertCmd.Parameters("@Password").Value = FormsAuthentication.HashPasswordForStoringInConfig File(sPassword, "SHA1")



        bSuccess = True

        Try
            myCONN.Open()
            insertCmd.ExecuteScalar()
            myCONN.Close()

        Catch ex As Exception
            bSuccess = False
            Session("Error") = bSuccess.ToString
            Response.Redirect("Register.aspx")
            Response.End()

        Finally
            If myCONN.State = ConnectionState.Open Then
                myCONN.Close()
            End If
        End Try
        If bSuccess = True Then
            Response.Redirect("Regconfirm.aspx")
        End If



    End Sub
End Class

 
Old August 20th, 2004, 03:55 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Remove the Response.redirect("register.aspx")s and the response.end()s and see what happens

 
Old August 20th, 2004, 07:39 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My original question was why Response.Redirect("Register.aspx") doesn't work here. I want the code at that exact point to post back to itself.

Another member told me ASP.NET post back automatically but how do you do that without using Response.Redirect("Register.aspx").

The last suggestion tells me to take out Response.Redirect("Register.aspx"), well then how does it know where and when to post back to itself.

Can someone please answer my original question?
It doesn't matter if I take out or leave in Response.End.




 
Old August 23rd, 2004, 08:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

If you are going to use Response.Redirect("") you will have to use querystring values.

Response.Redirect("page.aspx?value1=32234&value2=2 3423")

If you have a form with 800 possible values it can become very long therefore ASP.NET is set up to allow pages to post back to themselves without any code needed... that's the defaut behavior of a page.

Unlearn what you've learned with 'classic' ASP.

 
Old August 25th, 2004, 12:45 PM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to caveman_dick
Default

I have have had this problem before and a work around is to write javascript to the page...

Response.Write("<script language=""JavaScript"">window.document.refresh(); </script>")

This will basically just reload the page for you!

Hope this Helps :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy hyperlink ques with iframe bekim Javascript How-To 4 September 21st, 2005 02:45 AM
Easy Ques -- Datetime validation for Access bekim Access 2 June 16th, 2005 01:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.