Asp.Net 3.5按钮OnClientClick参数

时间:2009-09-04 18:46:21

标签: asp.net button onclientclick

我正在尝试从asp按钮调用MyJavascriptFunction(arg1)并且它不起作用...

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

生成的html根本不包含OnClick事件。

3 个答案:

答案 0 :(得分:2)

这是你在列表视图或数据网格中进行的操作

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

答案 1 :(得分:0)

您可以在Page_Load事件

中编写此方法吗?
Page.Databind();

并且此按钮位于另一个数据控件下?

答案 2 :(得分:0)

这是未经测试的,可能无效或需要更多转义。但尝试类似的事情:

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

请注意,您需要使用ClientID(而不是ID)来获取在按钮的HTML中呈现的实际ID。