Melursus
Melursus

Reputation: 10628

Asp.Net 3.5 Button OnClientClick Argument

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.

Upvotes: 0

Views: 2470

Answers (3)

M Ali
M Ali

Reputation: 21

This is when you are doin in listview or data grid

<asp:button id="ButtonDownload" runat="server" Text="Download"
    OnClientClick='<%# String.Format("return downloadFile(\"{0}\")",Eval("QueryID")) %>' />

Upvotes: 2

Dan Diplo
Dan Diplo

Reputation: 25369

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.

Upvotes: 0

Tarik
Tarik

Reputation: 81831

Could you write this method in your Page_Load event

Page.Databind();

and this button is under another data control ?

Upvotes: 0

Related Questions