关于asp按钮的JS回调

时间:2009-09-21 20:49:02

标签: asp.net javascript

嗯,我有这个人:

<div class="buttonRight"><asp:Button ID="btnOK" runat="server" Text="OK" Width="68px"/></div>

向下呈现

<div class="buttonRight"> <input type="submit" name="_$_$pc$pc$tabTO$_$uc0$popupSelectCompetition$btnOK" value="OK" id="____pc_pc_tabTO___uc0_popupSelectCompetition_btnOK" style="width:68px;" /></div>

我需要在该按钮上调用一些javascript而不改变其行为。我尝试使用OnClick asp属性,但这似乎是用于回调调用服务器代码,而不是通过javascript钩子传递给渲染的html。

我也不明白input type='submit'对我的影响。

1 个答案:

答案 0 :(得分:2)

将您的客户端代码添加到 OnClientClick 属性:

<div class="buttonRight">
    <asp:Button ID="btnOK" runat="server" Text="OK" Width="68px" 
       OnClientClick="alert('client side scripts here');"/>
</div>

用于服务器端事件的OnClick属性。

或者将onclick属性添加到您的控件中,就像代码背后的那样:

btnOK.Attributes.Add("onclick", "alert('client side scripts here');");