0

I just want to ask how to fix this code so that the second page is redirecting to the entered in the TextBox. Here's my code in the second page.

This code is located at the .aspx page

 <body>
        <form id="form1" runat="server">
        <div>
            <script type ="text/javascript">
                var gotoURL = document.getElementById('<%=siteURL2%>').value;
                window.location.href = 'http://www.' & gotoURL;
            </script>
        </div>
        </form>
    </body>

While this one is located at the .aspx.vb.

Protected siteURL As String = PreviousPage.currenctCity()

    Protected Property siteURL2 As String
        Get
            Return siteURL
        End Get
        Set(value As String)
            siteURL = value
        End Set
    End Property

I'm getting the error: **Object reference not set to an instance of an object.** at This Line: **Protected siteURL As String = PreviousPage.currenctCity()**

I have this code at the second page so that I can call the declared variable at the First page to the Second One.

Code: **<%@ PreviousPageType VirtualPath="~/Default.aspx" %>**

1
  • I updated the answer. check it Commented Nov 21, 2013 at 12:18

3 Answers 3

1

I have no idea about the VB part, but in Javascript the string concatenation operator is + rather than &

window.location.href = 'http://www.' + gotoURL;
Sign up to request clarification or add additional context in comments.

1 Comment

I have tried it and I'm sorry to say but it didn't fix the error.
0

Protected siteURL As String

Private Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

siteURL = PreviousPage.currenctCity() end sub

Protected Property siteURL2 As String
    Get
        Return siteURL
    End Get
    Set(value As String)
        siteURL = value
    End Set
End Property

1 Comment

previouspage property will only work if u redirect using server.transfer
0

As long as you use PreviousPage property you can't do with GET request.

When you request a page using window.location.href actually it fires GET request and not POST.

Please try getting the data other than using PreviousPage or POST the page by submitting the form and using Server.Transfer to actually call the page

Check Redirect To other page in asp.net

Cross page posting in asp.net

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.