Question : What datatype should a rul string be in to pass from code behind into URL via response.redirect

I am getting the error;

Input string was not in a correct format.

when I try and use the sport() function from my page.

It breaks down the query string and removes the sport parameter.  Then I want to redirect the page back to it's self without the sport parameter.  It works (I can see it in the URL) but I get this error.

a)  do i need to convert the url string to another datatype before I do response.redirect?
b)  is there a better way to do this?

PS - there is some junk in there from copied code and checking the string i was building.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
Private Sub sport()

        Dim currurl As String = HttpContext.Current.Request.RawUrl
        Dim querystring As String = Nothing

        ' Check to make sure some query string variables
        ' exist and if not add some and redirect.
        Dim iqs As Int32 = currurl.IndexOf("?".ToCharArray())
        If (iqs = -1) Then

            Dim redirecturl As String = currurl
            Response.Redirect(redirecturl, True)

            ' If query string variables exist, put them in
            ' a string.
        ElseIf (iqs >= 0) Then

            If (iqs < currurl.Length - 1) Then
                querystring = currurl.Substring(iqs + 1)
            End If

        End If

        ' Parse the query string variables into a NameValueCollection.
        Dim qscoll As NameValueCollection = HttpUtility.ParseQueryString(querystring)

        ' Iterate through the collection.



        Dim sb As New StringBuilder("?")
        Dim newQuery As String = "?"

        For Each s As String In qscoll.AllKeys

            sb.Append(s & "=" & qscoll(s))

            If s = "sport" Then
                newQuery = newQuery
            End If

            If s = "brand" Then
                newQuery = newQuery & s & "=" & qscoll(s)
            End If

            If s = "product" Then
                newQuery = newQuery & s & "=" & qscoll(s)
            End If

            If s = "season" Then
                newQuery = newQuery & s & "=" & qscoll(s)
            End If

            If s = "gender" Then
                newQuery = newQuery & s & "=" & qscoll(s)
            End If


            If s = "age" Then
                newQuery = newQuery & s & "=" & qscoll(s)
            End If


        Next s

        'Response.Write(newQuery.ToString)

        Dim newURL As String
        newURL = Request.Url.LocalPath

        newURL = newURL & newQuery
        'Response.Write(newURL)

        ' Write the result to a label
        'ParseOutput.Text = sb.ToString()

        Response.Redirect(newURL)

    End Sub




    Protected Sub ImageButtonSport_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles X.Click
        sport()
    End Sub

Answer : What datatype should a rul string be in to pass from code behind into URL via response.redirect

i tried replicating it but don't get any errors....though I converted your code to C#. really nothing changed...
just wondering if you are trying something else....coz "product=1brand=1" is missing '&' (in case if it is not intentional) after new format.
when are you getting this error if postback was successful?
Random Solutions  
 
programming4us programming4us