日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

ASP.NET GetPostBackEventReference

發布時間:2024/9/20 asp.net 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ASP.NET GetPostBackEventReference 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.__doPostBack("id","")方法
  2.GetPostBackEventReference方法作用
  3.客戶端如何觸發服務器端控件的事件
  右邊提供程序用此方法實現在客戶端單擊按鈕后,禁用此按鈕,直到程序運行完畢再開啟按鈕。(單擊右邊下載)
  下面再舉個小例子.
  前臺頁面
  有個服務器控件 <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
  一個客戶端控件用來觸發服務器端
  <a href="#" οnclick="document.getElementById('Button1').click()">觸發服務器端按鈕事件</a>
  (2)
  利用GetPostBackEventReference給客戶端生成__doPostBack()
  前臺
  <a href="#" οnclick="<%=PostBack()%>">觸發服務器端按鈕事件</a>
  后臺
  protected string PostBack()
  {
  return this.Page.GetPostBackEventReference(this.Button1,"haha");
  }
  通過__EVENTARGUMENT="haha"可以判斷是不是點了那個鏈接的PostBack
  把Button1的按鈕事件這么寫:
  if(Request["__EVENTARGUMENT" ]=="haha")
  {
  Response.Write("這個是鏈接的PostBack");
  }
  else
  {
  Response.Write("這個不是鏈接的PostBack");
  }
  以下這個是微軟MSDN上的例子:
  public class MyControl : Control, IPostBackEventHandler
  {
  // Create an integer property that is displayed when
  // the page that contains this control is requested
  // and save it to the control's ViewState property.
  public int Number
  {
  get
  {
  if ( ViewState["Number"] !=null )
  return (int) ViewState["Number"];
  return 50;
  }
  set
  {
  ViewState["Number"] = value;
  }
  }
  // Implement the RaisePostBackEvent method from the
  // IPostBackEventHandler interface. If 'inc' is passed
  // to this method, it increases the Number property by one.
  // If 'dec' is passed to this method, it decreases the
  // Number property by one.
  public void RaisePostBackEvent(string eventArgument)
  {
  if ( eventArgument == "inc" )
  Number = Number + 1;
  if ( eventArgument == "dec" )
  Number = Number - 1;
  }
  [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
  protected override void Render(HtmlTextWriter writer)
  {
  // Converts the Number property to a string and
  // writes it to the containing page.
  writer.Write("The Number is " + Number.ToString() + " (" );
  // Uses the GetPostBackEventReference method to pass
  // 'inc' to the RaisePostBackEvent method when the link
  // this code creates is clicked.
  writer.Write("<a href=\"javascript:" + Page.GetPostBackEventReference(this,"inc") + "\">Increase Number</a>");
  writer.Write(" or ");
  // Uses the GetPostBackEventReference method to pass
  // 'dec' to the RaisePostBackEvent method when the link
  // this code creates is clicked.
  writer.Write("<a href=\"javascript:" + Page.GetPostBackEventReference(this,"dec") + "\">Decrease Number</a>");
  }
  }

總結

以上是生活随笔為你收集整理的ASP.NET GetPostBackEventReference的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。