Avatar of Paul Kahl
Paul KahlFlag for United States of America

asked on 

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

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?
ASP.NET

Avatar of undefined
Last Comment
Paul Kahl
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

you have to duplicate them.

Avatar of Paul Kahl
Paul Kahl
Flag of United States of America image

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of rundkaas
rundkaas

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Paul Kahl
Paul Kahl
Flag of United States of America image

ASKER

That's it exactly! Thank you!
Avatar of Paul Kahl
Paul Kahl
Flag of United States of America image

ASKER

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!
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo