Solved

request querystring problems with symbols?

Posted on 2008-10-30
10
194 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now