skip to Main Content

How to send multi-values under 1 variable in URL? this variable can have comma, single quote etc…

I have a messy made-up values inside a DropDownList(could be more). I want to pass these 3 values in URL under 1 variable. I am using ASCII to encode &’,/ symbols in url

  • New York City / Buffalo
  • Doctor’s, Nurse’s, hospital
  • Red & Green

How can i indicate in URL that new value is about to start? i can’t use comma becuase single value can have multi commas. and I cant use & symbol bc url think its a new variable

I tried this but ^ symbol not allowed in url

 test.com/Value=New York City / Buffalo^Doctor's, Nurse's, hospital^Red & Green 

2

Answers


  1. Assuming you have access to both form and destination pages, build a custom encoder to replace any invalid character in url (or query string) with something else and also a custom decoder at the destination page:

    function encode(s as string) as string
        s= s.replace("&" , "@@@ampersand@@@")
        s= s.replace("^" , "@@@caret@@@")
        s= s.replace("/" , "@@@slash@@@")
        s= s.replace("|" , "@@@bar@@@")
        return s
    end function
    
    function decode(s as string) as string
        s= s.replace("@@@ampersand@@@" , "&")
        s= s.replace("@@@caret@@@" , "^")
        s= s.replace("@@@slash@@@" , "/")
        s= s.replace("@@@bar@@@" , "|")
        return s
    end function
    

    In your form page:

    dim s as string= $"{string1}|{string2}|{string3}"
    response.redirect("testcom/somepage.aspx/?value=" & encode(s))
    

    In somepage.aspx :

    dim k as string= decode(request.querystring("value"))
    dim a = k.split("|")
    string1= a(0)
    string2= a(1)
    string3= a(2)
    
    Login or Signup to reply.
  2. Just shove the 3 (or however many) into an array.
    Use encoding, and then convert to JSON array.

    So, say this markup:

        <h3>Source page</h3>
        one:
        <asp:TextBox ID="txtOne" runat="server" ClientIDMode="Static"></asp:TextBox>
        <br />
        two:
        <asp:TextBox ID="txtTwo" runat="server" ClientIDMode="Static"></asp:TextBox>
        <br />
        one:
        <asp:TextBox ID="txtThree" runat="server" ClientIDMode="Static"></asp:TextBox>
        <br />
    
        <br />
        <br />
        <input id="cmdJS" type="button" value="client  side click"
            onclick="mytest();return false" />
    
        </div>
    
        <script>
            function mytest() {
                var mythings = []
                mythings.push($('#txtOne').val())
                mythings.push($('#txtTwo').val())
                mythings.push($('#txtThree').val())
    
                var sParms = encodeURIComponent(JSON.stringify(mythings))
                window.location.href = "MyTest.aspx?myvalues=" + sParms
    
            }
        </script>
    

    And our target page has this:

        <h3>Target page</h3>
        one:
        <asp:TextBox ID="txtOne" runat="server" ClientIDMode="Static"></asp:TextBox>
        <br />
        two:
        <asp:TextBox ID="txtTwo" runat="server" ClientIDMode="Static"></asp:TextBox>
        <br />
        one:
        <asp:TextBox ID="txtThree" runat="server" ClientIDMode="Static"></asp:TextBox>
        <br />
    

    So, say then this:

    enter image description here

    Code behind on target page is this:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        If Not IsPostBack Then
    
            Dim s = Request.QueryString(0)
            Dim jsSZ = New JavaScriptSerializer()
            Dim mylist As New List(Of String)
            Dim myarray = jsSZ.Deserialize(Of List(Of String))(s)
    
            txtOne.Text = myarray(0)
            txtTwo.Text = myarray(1)
            txtThree.Text = myarray(2)
    
        End If
    
    End Sub
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search