Asp.net下用JQuery找出哪一個元素引起PostBack
更新時間:2010年06月12日 21:25:15 作者:
在Asp.net webform中,如何找出哪一個按鈕觸發(fā)Button PostBack事件。
先看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對您有幫助。
復(fù)制代碼 代碼如下:
<!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端這么寫:
復(fù)制代碼 代碼如下:
/// <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對您有幫助。
相關(guān)文章
ASP.NET之Response.Cookies.Remove 無法刪除COOKIE的原因
在web開發(fā)中Cookie是必不可少的,.NET自然也有一個強大的Cookie操作類,我們用起來也非常方便,不過在使用中我們會發(fā)現(xiàn)一個坑爹的事情Response.Cookies.Remove刪除不了Cookie。2013-06-06asp.net實現(xiàn)在XmlTextWriter中寫入一個CDATA的方法
這篇文章主要介紹了asp.net實現(xiàn)在XmlTextWriter中寫入一個CDATA的方法,結(jié)合實例形式分析了XmlTextWriter寫入CDATA的步驟與相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2016-04-04在ASP.NET中用MSDNURLRewriting實現(xiàn)Url Rewriting
在ASP.NET中用MSDNURLRewriting實現(xiàn)Url Rewriting...2007-03-03.net core使用FastHttpApi構(gòu)建web聊天室實例代碼
這篇文章主要給大家介紹了關(guān)于.net core使用FastHttpApi構(gòu)建web聊天室的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-10-10ASP.NET Core 2.0 本地文件操作問題及解決方案
這篇文章主要介紹了ASP.NET Core 2.0 本地文件操作問題及解決方案,需要的朋友可以參考下2017-10-10