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)文章
如何使用Python實(shí)現(xiàn)阿拉伯?dāng)?shù)字轉(zhuǎn)換成中國漢字
本文提供了一個Python代碼示例,用于將阿拉伯?dāng)?shù)字轉(zhuǎn)換為中文漢字表示,代碼定義了數(shù)字到漢字的映射表,并實(shí)現(xiàn)了處理不同位數(shù)(如個、十、百、千、萬等)的函數(shù),特別地,處理方式包括對大數(shù)字的分解和轉(zhuǎn)換,以及對連續(xù)零的特殊處理,感興趣的朋友跟隨小編一起看看吧2024-09-09
ASP.NET MVC5+EF6+EasyUI后臺管理系統(tǒng) 微信公眾平臺開發(fā)之資源環(huán)境準(zhǔn)備
這篇文章主要介紹了ASP.NET MVC5+EF6+EasyUI后臺管理系統(tǒng),微信公眾平臺開發(fā)之資源環(huán)境準(zhǔn)備,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09
ASP.NET Core WebApi中使用FluentValidation驗(yàn)證數(shù)據(jù)模型的方法
這篇文章主要介紹了ASP.NET Core WebApi中使用FluentValidation驗(yàn)證數(shù)據(jù)模型的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-01-01
自動類型安全的REST.NET標(biāo)準(zhǔn)庫refit
這篇文章介紹了自動類型安全的REST.NET標(biāo)準(zhǔn)庫refit,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-04-04
網(wǎng)頁(aspx)與用戶控件(ascx)交互邏輯處理實(shí)現(xiàn)
為了以后好維護(hù),把幾個頁面(ASPX)相同的部分抽取放在一個用戶控件(ASCX)上,現(xiàn)在把邏輯分享下,感興趣的各位可以參考下哈2013-03-03
asp.net gridview的Rowcommand命令中獲取行索引的方法總結(jié)
asp.net gridview的Rowcommand命令中獲取行索引的方法總結(jié),需要的朋友可以參考下。2010-05-05

