[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") + " );" %>'

0

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

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 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.

<asp:ImageButton  
 ID="Imagebutton1" runat="server"
 ImageUrl="../../common/images/pencil.gif"                
 OnClientClick='<%# String.Format("EditBankAccount(\"{0}\");", Eval("BankAccountID")) %>'
 OnClick="ImgBankAccountsDGEdit_Click"/>

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}\")") %>'

0

Score: 0

Basically you need to escape the quote

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

0

More Related questions