62,074
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "函数", "function testfunc(){" +
this.ClientScript.GetPostBackEventReference(this.Button1, string.Empty) +
"};", true);
}
protected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "提示", "window.alert('按了!');", true);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</form>
<input type="button" value="JS测试按钮" onclick="testfunc();" />
</body>
</html>
其实我在 csdn 论坛从 2008 年就反复说过 asp.net 应用编程方式“过时”了。对于 asp.net 服务器端编程,我现在很少回,因为你真正要花2年时间学 asp.net 服务器控件开发入门之后,有可能会有一点点后悔。不过作为一种曾经的伟大的技术,偶尔解释一下,可以锻炼一下逻辑知识。