Reputation: 466
On my webpage I need to pass a variable called deskname to a popup. My problem is that many of the desknames have a & in the middle (ex: Laundry & Tobacco). So when I try to include this variable, it cuts off the second half because the URL takes anything after the & to be a new variable.
Here is my code:
onmouseover="javascript:openPopup('TCW_BannerIPGChart.aspx?IPG_assigned=<%# Eval("IPG_assigned")%>&banner=Southern California Division&enterprise_zone=1&deskname=<%# Eval("deskname")%>')"
Any suggestions on how to get the variable to pass unhindered? I've read some suggestions of using encodeURIcomponent but couldn't find a good explanation of how to employ it in this case. Ideally I'd be able to handle the javascript in this line, rather than writing the javascript separately but if that's the only way to do that please let me know.
Thanks, Tucker
Upvotes: 1
Views: 151
Reputation: 499002
You can URL Encode an &
as %26
.
So, "Laundry & Tobacco" will turn to "Laundry%20%26%20Tobacco" or "Laundry+%26+Tobacco".
See HttpUtility.UrlEncode
on MSDN.
Upvotes: 1