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 / September 2007

Tip: Looking for answers? Try searching our database.

Approstrophie Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LKNewsGroups - 20 Sep 2007 20:18 GMT
Hi I have a list which pulls out items from a stored procedure. Unfortunately
some of the items it pulls out have apostrophes.  This info need to be placed
in a URL but it keeps truncating at the apostrophe. When there is no
apostrophe all is well.

Example

With no apostrophe  String = accessories  No problem

subcategory.aspx?strSubCategory=Accessories&CategoryID=5

when string = Men's Slippers  Truncated URL

http://localhost/dougboys-12-15/subcategory.aspx?strSubCategory=Men

I know the obvious would have been to use keys that were numbers but it was
not done this way for some reason.  I realize that with apostrophes a double
quote would be needed but since they are being pulled from the database I can
not do that.

Suggestions?

Hear is the code
______________________________________________________
<ItemTemplate>

    <a href='subcategory.aspx?strSubCategory=<%#
Server.UrlEncode(DataBinder.Eval(Container.DataItem,
"strSubCategory"))%>&CategoryID=<%#
request.querystring(Server.UrlEncode("categoryID")) %>'  ><%#
DataBinder.Eval(Container.DataItem, "strSubCategory") %></a>

</ItemTemplate>
LKNewsGroups - 20 Sep 2007 20:22 GMT
OOOPs I meant apostrophe problem

> Hi I have a list which pulls out items from a stored procedure. Unfortunately
> some of the items it pulls out have apostrophes.  This info need to be placed
[quoted text clipped - 29 lines]
>
> </ItemTemplate>
Mark Fitzpatrick - 20 Sep 2007 21:02 GMT
Have you tried using the UrlEncode to encode the ' into a valid querystring,
then use UrlDecode to return it to it's normal format?

Signature

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

> Hi I have a list which pulls out items from a stored procedure.
> Unfortunately
[quoted text clipped - 34 lines]
>
> </ItemTemplate>
LKNewsGroups - 20 Sep 2007 21:22 GMT
I did not know about URL Decode. I have Encode in my code but how would I put
the decode into the code.  Where would it need to be placed.

<a href='subcategory.aspx?strSubCategory=<%#
Server.UrlEncode(DataBinder.Eval(Container.DataItem,
"strSubCategory"))%>&CategoryID=<%#
request.querystring(Server.UrlEncode("categoryID")) %>'  ><%#
DataBinder.Eval(Container.DataItem, "strSubCategory") %></a>

> Have you tried using the UrlEncode to encode the ' into a valid querystring,
> then use UrlDecode to return it to it's normal format?
[quoted text clipped - 37 lines]
> >
> > </ItemTemplate>
bruce barker - 20 Sep 2007 23:55 GMT
standard URLEncode only xlates ", not ' as html uses " as quote. you
will need to do it yourself. also you need to urlencode all your values,
nor do I understanf the urlencode for the request item lookup.

<script runat="server">
string UrlEncode(string s)
{
    return HttpUtility.UrlEncode(s).Replace("'","%27");
}
</script>

<a href='<%#
"subcategory.aspx?strSubCategory=" +
   UrlEncode(DataBinder.Eval(Container.DataItem,"strSubCategory"))+
  "&CategoryID=" +
    UrlEncode(Request.QueryString["categoryID"])%>'
 />

-- bruce (sqlwork.com)

> Hi I have a list which pulls out items from a stored procedure. Unfortunately
> some of the items it pulls out have apostrophes.  This info need to be placed
[quoted text clipped - 29 lines]
>
> </ItemTemplate>
LKNewsGroups - 21 Sep 2007 06:48 GMT
Bruce

You are great!

This did the trick

<a href='subcategory.aspx?strSubCategory=<%#
HttpUtility.UrlEncode(DataBinder.Eval(Container.DataItem,
"strSubCategory")).Replace("'","%27")%>

Thanks!

> standard URLEncode only xlates ", not ' as html uses " as quote. you
> will need to do it yourself. also you need to urlencode all your values,
[quoted text clipped - 49 lines]
> >
> > </ItemTemplate>

Rate this thread:







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.