views:

786

answers:

2

I'm trying to call the MyJavascriptFunction(arg1) from an asp button and it's doesn't work...

<asp:Button ID="btnMyButton" runat="server"
            OnClientClick='<%# Eval("Id", "MyJavascriptFunction({0})") %>' />

The html generated contains no OnClick event at all.

A: 

Could you write this method in your Page_Load event

Page.Databind();

and this button is under another data control ?

Braveyard
Yes, it is under another data control. Add this help me to find my problem. I was misspell the field in Eval...
Melursus
A: 

This is untested, and might not work or it will need more escaping. but try something like:

<asp:Button ID="btnMyButton" runat="server"
            OnClientClick='<%# String.Format("MyJavascriptFunction(\"{0}\"", this.ClientID) %>' />

Note you need to use ClientID (rather than ID) to get the actual ID rendered in the HTML for your button.

Dan Diplo