Solved

request querystring problems with symbols?

Posted on 2008-10-30
10
199 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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 …
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.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

724 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