?
Solved

how to escape single quotes in a DataBinder on the client - side

Posted on 2006-05-05
5
Medium Priority
?
575 Views
Last Modified: 2010-08-05
I have a link in a dataList like so:

<a href="javascript:openMap('showRoomLocation.aspx?room=<%# DataBinder.Eval(Container.DataItem, "vchrSRRoomNum") %>');" class="RedBold"><%# DataBinder.Eval(Container.DataItem, "vchrSRRoomNum") %></a>


Is there a way to escape single quotes in the room number in the href?
0
Comment
Question by:Paul Kahl
  • 3
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16618333
you have to duplicate them.

0
 
LVL 3

Author Comment

by:Paul Kahl
ID: 16618420
what i'm looking for is this:

if
<a href="javascript:openMap('showRoomLocation.aspx?room=<%# DataBinder.Eval(Container.DataItem, "vchrSRRoomNum") %>');" class="RedBold"><%# DataBinder.Eval(Container.DataItem, "vchrSRRoomNum") %></a>

would print out

<a href="javascript:openMap('showRoomLocation.aspx?room=men's restroom');" class="RedBold">men's restroom</a>

then I want it to print out

<a href="javascript:openMap('showRoomLocation.aspx?room=men\'s restroom');" class="RedBold">men's restroom</a>

how do I do that, on the fly?
0
 
LVL 3

Accepted Solution

by:
rundkaas earned 2000 total points
ID: 16618591
How about this:
<a href="javascript:openMap('showRoomLocation.aspx?room=<%# DataBinder.Eval(Container.DataItem, "vchrSRRoomNum").ToString().Replace("'","\\'") %>');" class="RedBold"><%# DataBinder.Eval(Container.DataItem, "vchrSRRoomNum") %></a>
0
 
LVL 3

Author Comment

by:Paul Kahl
ID: 16618647
That's it exactly! Thank you!
0
 
LVL 3

Author Comment

by:Paul Kahl
ID: 16618653
well - almost it: one small change:

<a href="javascript:openMap('showRoomLocation.aspx?room=<%# DataBinder.Eval(Container.DataItem, "vchrSRRoomNum").ToString().Replace("'","\'") %>');" class="RedBold"><%# DataBinder.Eval(Container.DataItem, "vchrSRRoomNum") %></a>


replaced \\ with \ in the replace command.

Thank you a ton!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

809 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