Approstrophie Problem

G

Guest

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>
 
M

Mark Fitzpatrick

Have you tried using the UrlEncode to encode the ' into a valid querystring,
then use UrlDecode to return it to it's normal format?
 
G

Guest

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>
 
B

bruce barker

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)
 
G

Guest

Bruce

You are great!

This did the trick

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

Thanks!

bruce barker said:
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
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top