views:

60

answers:

3

I'm trying to generate this html

<a href="#" class="button" onclick="
    $('#someControl').toggle('blind',
    { easing: 'easeInOutSine'}); return false;">

With my databinding expression I have

<a href="#" class="button" onclick='<%# string.Format(
    "$('#{0}').{1}",
     Eval("Key"),
    ".toggle('blind', { easing: 'easeInOutSine'}); return false"
)%>'>

Which doesn't raise any errors or anything however when it renders out the html when I inspect it with Firebug this is what it's showing from the browser

<a false="" return="" });="" easeinoutsine="" easing:="" {=""
,="" blind="" )..toggle(="" #plan1="" 
onclick="$(" class="button" href="#">

I've tried a few attempts at inlining this with and without the string.Format, using a function inside the codebehind that I call during my databinding all seems to produce this garbled output. Am I missing an escape or something similar somewhere?

+1  A: 

When it's parsing the aspx file it's tripping over the apostrophes in your attribute declaration. This='"something isn**'**t right here"' sort of thing... You'll need to work around that.

You could try something like this:

<%#String.Format("<a href=\"#\" class=\"button\" onclick=\"$('#{0}').toggle('blind',{easing: 'easeInOutSine'}); return false;\">", Eval("Key"))%>
blesh
Generating the entire line of html for the link was the only way i could get it to work, thanks for the idea!
Chris Marisic
A: 

try:

<a href="#" class="button" onclick='<%# string.Format(
    "$(&apos;#{0}&apos;).toggle(&apos;blind&apos;, { easing: &aposeaseInOutSine&aposbv}); return false",
     Eval("Key"))%>'>
Rune FS
A: 

In the top code, onclick is surrounded by double quotes. in the bottom code, it's surrounded by single quotes; as Blesh mentions, that's the source of your angst.

DDaviesBrackett