【问题标题】:how to call function in code behind with javascript?如何使用javascript在代码中调用函数?
【发布时间】:2020-11-19 10:41:34
【问题描述】:

我想从 javascript 调用位于代码后面的函数

按钮:

<button class = "btn btn-outline btn-danger dim" type = "button" onclick = "confirmDelete ()"> <i class = "fa fa-trash"> </i> Delete </button>

Javascript 函数:

<script>
     function confirmDelete () {
         if (confirm ('Are you sure you want to delete this?')) {
             // call function Delete_Click ();
         }
         return false; // cancel the click event always
     }
 </script>

我要调用的函数:

protected void Delete_Click (object sender, EventArgs e)
     {
         try
         {
             Delete item
         }
         catch (Exception ex)
         {
             SetError (ex.Message);
         }
     }

如果我使用

的原因

【问题讨论】:

标签: javascript c# asp.net button onclick


【解决方案1】:

首先更改你按钮并添加runat,Id,OnClientClickOnClick 事件:

   <button Id="MyBtn" runat="server" 
    class = "btn btn-outline btn-danger dim" type ="button" 
    OnClientClick="return confirmDelete()" 
    OnClick="Delete_Click"> 
      <i class = "fa fa-trash"> </i> Delete 
    </button>

然后改变你的 js 函数:

 function confirmDelete () {
     return confirm ('Are you sure you want to delete this?');
 }

【讨论】:

    猜你喜欢
    • 2013-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    • 2012-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多