• ASP.NET GetPostBackEventReference


      1.__doPostBack("id","")方法
      2.GetPostBackEventReference方法作用
      3.客户端如何触发服务器端控件的事件
      右边提供程序用此方法实现在客户端单击按钮后,禁用此按钮,直到程序运行完毕再开启按钮。(单击右边下载)
      下面再举个小例子.
      前台页面
      有个服务器控件 <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
      一个客户端控件用来触发服务器端
      <a href="#" onclick="document.getElementById('Button1').click()">触发服务器端按钮事件</a>
      (2)
      利用GetPostBackEventReference给客户端生成__doPostBack()
      前台
      <a href="#" onclick="<%=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>");
      }
      }
  • 相关阅读:
    2277 爱吃皮蛋的小明
    zoj2314 经典 无源汇有上下界最大流 并输出可行流
    [置顶] css3 befor after 简单使用 制作时尚焦点图相框
    [置顶] 程序员的奋斗史(二十八)——寒门再难出贵子?
    TaintDroid:智能手机监控实时隐私信息流跟踪系统(四)
    Activity切换效果(overridePendingTransition)
    Activity生命周期,状态保存恢复(经典)
    大二实习使用的技术汇总(上)
    Struts2配置RESULT中TYPE的参数说明
    关于程序动态库链接和运行时搜索路径设置的个人理解
  • 原文地址:https://www.cnblogs.com/soundcode/p/2009838.html
Copyright © 2020-2023  润新知