Okay, i think i've tried 3-4 methods here from stackoverflow, but none seems to work.
I've got:
OnClientClick='<%# Eval("albumName", "doConfirm(\"delete\", \"{0}\");").ToString() %>'
but in html it renders as:
onclick="doConfirm("delete", "Test");"
Also tried making a method to call:
public string CreateConfirmation(String action, String item) {
return String.Format(@"return confirm('Sikker på du vil {0}: {1}');", action, item);
}
With this:
OnClientClick='<%# CreateConfirmation("delete", (string)Eval(albumName)) %>'
But gives me exact same problem.... So im pretty lost?
I apologize in advance for such a long answer, but I wanted to be thorough.
This is apparently a "security" feature in .Net 4.0 (and higher). You can read more about it at:
All of the above links also recommend declaring a public class to override the behavior:
and then adding this to the
<system.web>
element in your web.config:This definitely fixes the rendering problem, so that quotes and apostrophes render as
"
and'
(as expected).That said, I tested your problem with the following:
and in the code-behind:
I was able to duplicate your rendering problem:
When any of the buttons were clicked, the JavaScript function ignored the HTML encoding, alerting me to:
so while it looks funky in the source, having quotes and apostrophes render as
"
and'
doesn't really appear to affect anything.