posts - 930,  comments - 588,  views - 402万
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

            在Asp.net webform中,如何找出哪一个按钮触发Button PostBack事件。先看ASPX:

   1:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   2:  <html xmlns="http://www.w3.org/1999/xhtml">
   3:  <head runat="server">
   4:      <title>Petter Liu demo</title>
   5:   
   6:      <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js" type="text/javascript"></script>
   7:   
   8:      <script type="text/javascript">
   9:          $(function() {
  10:              $("input:submit").click(function() {
  11:                  $("#HiddenField1").val($(this).attr("id")
  12:                          + " 引起一个 postback");
  13:              });
  14:          });  
  15:          </script>
  16:   
  17:  </head>
  18:  <body>
  19:      <form id="form1" runat="server">
  20:      <div>
  21:          <asp:Button ID="Button1" runat="server" Text="Button1" />
  22:          <asp:Button ID="Button2" runat="server" Text="Button2" />
  23:          <asp:Button ID="Button3" runat="server" Text="Button3" />
  24:          <asp:HiddenField ID="HiddenField1" runat="server" />
  25:      </div>
  26:      </form>
  27:  </body>
  28:  </html>

           然后在Sever端这么写:

   1:    /// <summary>
   2:          /// Handles the Load event of the Page control.
   3:          /// </summary>
   4:          /// <param name="sender">The source of the event.</param>
   5:          /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
   6:          /// <remarks>Author Petter Liu http://wintersun.cnblogs.com  </remarks>
   7:          protected void Page_Load(object sender, EventArgs e)
   8:          {
   9:              Response.Write(HiddenField1.Value);
  10:          }

          很简单的CODE.

          希望这篇POST对您有帮助。


作者:Petter Liu
出处:http://www.cnblogs.com/wintersun/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
该文章也同时发布在我的独立博客中-Petter Liu Blog

posted on   PetterLiu  阅读(644)  评论(1编辑  收藏  举报
编辑推荐:
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
阅读排行:
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 【.NET】调用本地 Deepseek 模型
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
点击右上角即可分享
微信分享提示