2

I have an Eval function in my aspx as below.

<asp:LinkButton ID="LinkButton1" runat="server" 
    OnClientClick='<%# "javascript:MyJSFunction(" + Eval("ObjectIdList") + ");return false;" %>'>
</asp:LinkButton>

The ObjectIdList is a list comma seperated ids as below from the server end

234,333,444,555

My javascript is as below

function MyJSFunction(Ids){
    alert(Ids)
}

My javascript function only displays the first id of 234. I have tried putting single quotes as below but I get an error 'Server tag is not well formed'

<asp:LinkButton ID="LinkButton2" runat="server" 
    OnClientClick='<%# "javascript:MyJSFunction('" + Eval("ObjectIdList") + "');return false;" %>'>
</asp:LinkButton>

Please Help

2
  • Only put the Eval(...) part in <%# %> and then fix the quotes. Commented Nov 8, 2019 at 12:11
  • Could you please give an example? Commented Nov 8, 2019 at 12:20

1 Answer 1

1

Escape the single javascript quotes in the string with &#39;

<asp:LinkButton ID="LinkButton1" runat="server"
    OnClientClick='<%# "javascript:MyJSFunction(&#39;" + Eval("ObjectIdList") + "&#39;);return false;" %>'>
</asp:LinkButton>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.