Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

Use of % as wildcard messing up my QueryString

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arch Stanton - 21 Apr 2008 23:27 GMT
I have an aspx page with a text box. My user enters text to search for
and presses a button; the text is passed via a QueryString to another
aspx page and used in a SQL search. The wildcard character is a percent
sign.

This works great if I place the % at the end of a search string, but I'm
getting peculiar errors if I start the search string with the wildcard
character. My search string seems to be altered at the front, and I
can't figure out a pattern.

The passed string looks fine in the address bar. For instance, if I
enter "%500", the address bar on the destination page looks like this:

"http://localhost/Results.aspx?QueryString=(SerialNumber%20LIKE%20'%500');"

But the destination page sees the string " %500 " as " 'P0' " (without
the outside quotes). As I said, if I use the % at the end of the string,
everything works fine.

I'd be happy to post my code, but I'm guessing that anyone who knows why
this is happening will be able to tell me without it. I'm also guessing
that this has something to do with the percent signs that ASP uses to
pass strings with spaces, but I can't figure out what to do about it.

As usual, thanks so much for any help.
Mark Fitzpatrick - 22 Apr 2008 01:24 GMT
There's a good reason, the % is reserved for another purpose and it's not
reserved by ASP, it's actually part of the URL specification. Nothing to do
with Microsoft, but the engineering committees that set the standards for
handling URL's. For example, %20 is a the code for a space in a URL as
you've noticed, but there are lots of others (unfortunately I can't find my
link to their definitions). Try using the Server.UrlEncode method to get a
safe string that you can then pass into the querystring and on the other end
use the Server.UrlDecode method to get the data back out like so: string
query = Server.UrlDecode(Request.QueryString["QueryString"]);

You have to pay careful attention to what you put into a querystring because
a lot of things are not allowed.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression

>I have an aspx page with a text box. My user enters text to search for and
>presses a button; the text is passed via a QueryString to another aspx page
[quoted text clipped - 20 lines]
>
> As usual, thanks so much for any help.
Arch Stanton - 22 Apr 2008 15:04 GMT
Helps a whole bunch. Thanks, Mark.

Fitzpatrick wrote:
> There's a good reason, the % is reserved for another purpose and it's
> not reserved by ASP, it's actually part of the URL specification.
[quoted text clipped - 40 lines]
>>
>> As usual, thanks so much for any help.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.