欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Asp.net下用JQuery找出哪一个元素引起PostBack

程序员文章站 2024-03-07 16:24:15
先看aspx: 复制代码 代码如下:
先看aspx:
复制代码 代码如下:

<!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>petter liu demo</title>
<script src="http://img.jb51.net/jslib/jquery/jquery14.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("input:submit").click(function() {
$("#hiddenfield1").val($(this).attr("id")
+ " 引起一个 postback");
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:button id="button1" runat="server" text="button1" />
<asp:button id="button2" runat="server" text="button2" />
<asp:button id="button3" runat="server" text="button3" />
<asp:hiddenfield id="hiddenfield1" runat="server" />
</div>
</form>
</body>
</html>

然后在sever端这么写:
复制代码 代码如下:

/// <summary>
/// handles the load event of the page control.
/// </summary>
/// <param name="sender">the source of the event.</param>
/// <param name="e">the <see cref="system.eventargs"/> instance containing the event data.</param>
/// <remarks>author petter liu http://wintersun.cnblogs.com </remarks>
protected void page_load(object sender, eventargs e)
{
response.write(hiddenfield1.value);
}

很简单的code.
希望这篇post对您有帮助。