Solved

request querystring problems with symbols?

Posted on 2008-10-30
10
197 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 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