如何在从C#文件单击按钮后从javascript调用bootbox.alert()

时间:2015-02-22 15:23:16

标签: c# asp.net bootbox

我想调用我在JavaScript函数myfunction()中编写的“bootstrap.alert”方法。

这是aspx代码: -

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="temp1.aspx.cs"    Inherits="temp1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="css/bootstrap.css" rel="stylesheet" />
<link href="css/font-awesome.min.css" rel="stylesheet" />

 <script type="text/javascript">

     function myfunction() {
         bootbox.alert("Hello world!", function () {
         });
     }
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Button runat="server" Text="Test" ID="btnTest"     OnClick="btnTest_Click"/>
</form>
<!-- JS dependencies -->
<script     src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>


<!-- bootbox code -->


<script src="Scripts/bootbox.js"></script>
<script src="Scripts/bootstrap.min.js"></script>
<script src="Scripts/jquery-1.9.1.min.js"></script>
<script type="text/javascript">    </script>



</body>
</html> 

这是我的Csharp代码: -

public partial class temp1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnTest_Click(object sender, EventArgs e)
{
   //What should i write here to call the javascript function "myfunction()" and that bootbox.alert() is executed.
}
}

我想在点击按钮时显示bootbox警告框。请帮我在按钮点击事件中编写代码。

1 个答案:

答案 0 :(得分:0)

使用onclientClick

属性
<asp:Button runat="server" Text="Test" ID="btnTest"     OnClick="btnTest_Click" OnClientClick="myFunction"/>