Search code examples
c#asp.netwebformsinline-code

Inline code not compiling inside an OnClientClick event


I'm trying this code inside a asp:hyppelink inside a repeater.

OnClientClick='openURL( "<%# Eval("UrlPagamento")%>", "<%# Eval("IdPedido")%>")'>

and the outcome after compilling is this:

<a class="btnPequeno" onclientclick="openURL( &quot;<%# Eval(&quot;UrlPagamento&quot;)%>&quot;, &quot;<%# Eval(&quot;IdPedido&quot;)%>&quot;)" href="#">Pagar</a>

I tried to change the symbols " and ' but then I just got a syntax error.

Any idea how to solve it?


Solution

  • You have to bind all the string elements inside the databinding expression and escape the ' with &#39;

    OnClientClick='<%# "openURL(&#39;" + Eval("UrlPagamento") + "&#39;, &#39;" + Eval("IdPedido") + "&#39;)" %>'