0

ASP.NET 4.0, webform site

There is a link in my site is to call another page and pass url parameters, it looks like below.

http://www.foo.com/foo.aspx?anotherURI?param1=aaa&26param2=bbb

However, I need to do url encode for "anotherURI?param1=aaa&26param2=bbb", so it turns into:

http://www.foo.com/foo.aspx?anotherURI?param1%3Daaa%26param2%3Dbbb

Now if I want to enclose this with javascript, it won't work. How do I encode the url again?

javascript:void(window.open('http://www.foo.com/foo.aspx?anotherURI?param1%3Daaa%26param2%3Dbbb', 'popup'))

2 Answers 2

3

Correct the URI:

WRONG: http://www.foo.com/foo.aspx?anotherURI?param1%3Daaa%26param2%3Dbbb

RIGHT: http://www.foo.com/foo.aspx?anotherURI=param1%3Daaa%26param2%3Dbbb

Example for multiple URIs: http://www.foo.com/foo.aspc?uri1=[encodedURI]&uri2=[encodedURI2]

To get a value from a queryString variable on asp.net:

Dim sUrl1 as String = request("VarName")
Dim sUrl2 as String = request("VarName")
Dim sUrl3 as String = request("VarName")

If you want to get the decoded URL from that variable:

Dim sDecodedUrl1 as String = Server.UrlDecode(sUrl1)
Dim sDecodedUrl2 as String = Server.UrlDecode(sUrl2)
Dim sDecodedUrl3 as String = Server.UrlDecode(sUrl3)
Sign up to request clarification or add additional context in comments.

4 Comments

However, param1 & param2 is for another URI. How does that work?
@Stan in foo.aspx page read the value of Request.QueryString["anotherURI"] - it will contain raw value like param1=aaa&26param2=bbb so you'll need to parse it yourself using Split. If you need further help and Flavio won't be available let me know and I'll pull quick example.
Sorry if i didn't complete the explaination to this level, letme exemplify: to get a encoded value from a queryString variable on asp.net:
Yes this works, you just have to encode the url before setting it to a variable value...
1

if you want to encode/decode it (the way php does it) use

function url_encode(str) {
    str = (str + '').toString();
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28'). replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}

function url_decode(str) {
    return decodeURIComponent((str + '').replace(/\+/g, '%20'));
}

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.