代码之家  ›  专栏  ›  技术社区  ›  Dustin Getz sunsations

ASP按钮上的JS回调

  •  0
  • Dustin Getz sunsations  · 技术社区  · 15 年前

    嗯,我有个家伙:

    <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 回复  |  直到 15 年前
        1
  •  2
  •   Canavar    15 年前

    将客户端代码添加到 Onclipse点击 财产:

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