[ACCEPTED]-Passing Eval from ASPX to Javascript function as Parameter-javascript

Accepted answer
Score: 43

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

onclick='<%# "PopulateTicketDiv(" +Eval("SHOW_ID") + " );" %>'


Score: 22

The above solution creates problem when 4 you want to pass the string as parameter, you 3 can use following syntax to get through:

OnClientClick='<%# String.Format("javascript:return displayDeleteWarning(\"{0}\")", Eval("ItemName").ToString()) %>' 

Above 2 line should work irrespective of parameter 1 data type

Score: 3


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

<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 3 can set the onclick from the backend in 2 OnRowDataBound if this is in a grid/repeater 1 or on page_load if not.

Score: 2

You can use this syntax within a gridview, repeater 1 or..etc.

 ID="Imagebutton1" runat="server"
 OnClientClick='<%# String.Format("EditBankAccount(\"{0}\");", Eval("BankAccountID")) %>'

Your JavaScript function would be:

 function EditBankAccount(bankaccountid) {
       // Your code goes here
       // return true OR false based on your requirement
Score: 1

Pls Check this code

onclick='<%#Eval("DocumentPath","Chk(\"{0}\")") %>'


Score: 0

Basically you need to escape the quote

<asp:CheckBox onclick='<%# "ToggleByPassValidationRules(" + "\"" + Eval("Name") + "\"" + ");" %>' ID="chkIsRuleActive" runat="server" Enabled="false" />


More Related questions