Alex Rivera | Logout

Passing Eval from ASPX to Javascript function as Parameter

Asked 2008-10-30T11:54:18.323
20
<a id="lblShowTimings"
     runat="server"
     title='<%# Eval("SHOW_Name") %>'
     onclick='PopulateTicketDiv(<%#Eval("SHOW_ID") %>)'>  <-- this is the problem
  %#Eval("SHOW_Time") %>
</a>

Can Eval be passed as an argument to a javascript function? If so whats the syntax?

Edit
Report

2 Answers

44

Yes. What you want to do is this, though:

onclick='<%# "PopulateTicketDiv(" +Eval("SHOW_ID") + " );" %>'
answered 2008-10-30T12:22:38.513
3

Try

<script type="javascript">
     //Pollute the global namespace
     var ticketDivID = <%= SHOW_ID %>
</script>

<a id="lblShowTimings" runat="server" title='<%# Eval("SHOW_Name") %>' onclick='PopulateTicketDiv(ticketDivID)'> <%#Eval("SHOW_Time") %></a>

On a side note because you've got runat="server" you can set the onclick from the backend in OnRowDataBound if this is in a grid/repeater or on page_load if not.

answered 2008-10-30T12:30:35.863

Your Answer