C#代码调用页面javascript函数

C#代码调用javascript函数

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function tk() {
alert("弹框");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

</div>
</form>
</body>
</html>




后台
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

}
protected void Button1_Click(object sender, EventArgs e)
{
//调用tk()
ClientScript.RegisterStartupScript(this.GetType(), "myscript", "<script type='text/javascript'>tk();</script>");
}
}
posted @ 2010-10-21 19:05  邓维  阅读(686)  评论(0编辑  收藏  举报