?
Solved

request querystring problems with symbols?

Posted on 2008-10-30
10
Medium Priority
?
200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

765 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