Solved

request querystring problems with symbols?

Posted on 2008-10-30
10
198 Views
Last Modified: 2010-04-23
Hello Experts

I'm trying to get a string passed through a url.  Here is the code I currently use:
Public Property myStr() As String
        Get
            myStr = CStr(Request.QueryString("ctrlnum"))
        End Get
        Set(ByVal Value As String)
            myStr = Value
        End Set
    End Property

This works fine for most strings.  For some reason though when a value like "J&J INC" is passed it ignores the '&' symbol and just stops so my value ends up being "J" and that's it.  How do I fix this so I get the full querystring that is passed?  I know the program that is sending the query is right because I can see the actual "J&J INC" in my URL.  How do I fix this in vb?
0
Comment
Question by:jay-are
  • 6
  • 4
10 Comments
 
LVL 13

Expert Comment

by:sm394
ID: 22845988
try

Server.UrlEncode( QueryparamHere)
0
 
LVL 13

Expert Comment

by:sm394
ID: 22846012
something like this

string url="/Home.aspx?ctrlnum=" + Server.UrlEncode(values));
0
 

Author Comment

by:jay-are
ID: 22846027
You want me to change the actual link instead of fixing my querystring?

The link that sends me the value is a javascript.  It passes it to the URL properly, its just that my VB code doesn't query it correctly.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 13

Expert Comment

by:sm394
ID: 22846119
in that case i can only suggest
use     Request.RawUrl  
with substring to get the desired part of url

hope that helps
0
 

Author Comment

by:jay-are
ID: 22846491
Ok that pulls most of the URL.  Is there a way to trim that string down and grab just what's after "?ctrlnum=" ??

Then remove the space characters (%20)?
0
 
LVL 13

Expert Comment

by:sm394
ID: 22846513
post your url
0
 

Author Comment

by:jay-are
ID: 22846545
/arparentnotes/webform1.aspx?ctrlnum=A&R%20BODY%20SHOP

That's one of the few that have the '&' symbol.  Most just have spaces in their names.
0
 
LVL 13

Expert Comment

by:sm394
ID: 22846577

  string s = Request.RawUrl
            int i = s.LastIndexOf("=")
            string param = s.Substring(i+1, s.Length - i-1)
            param = param.Replace("%20", "")
0
 
LVL 13

Accepted Solution

by:
sm394 earned 500 total points
ID: 22846606
OR

          string s = Request.RawUrl
            int i = s.LastIndexOf("=")
            string param = s.Substring(i+1, s.Length - i-1)
             param = Server.UrlDecode(param);
0
 

Author Closing Comment

by:jay-are
ID: 31511881
That worked perfectly.  Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question