用__doPostBack()方法调用后台方法的方式中,页面没有__doPostBack()函数的解决
发布日期:2021-07-17 20:20:32 浏览次数:2 分类:技术文章

本文共 2018 字,大约阅读时间需要 6 分钟。

用ClientScriptManager.GetPostBackEventReference 方法产生__doPostBack()函数

 

  1. <%@ Page Language="C#"  %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <script runat="server">
  4.   public class MyControl : Label, IPostBackEventHandler
  5.   {
  6.     // Use the constructor to defined default label text.
  7.     public MyControl()
  8.     {
  9.       base.Text = "No postback raised.";
  10.     }
  11.     
  12.     // Implement the RaisePostBackEvent method from the
  13.     // IPostBackEventHandler interface. 
  14.     public void RaisePostBackEvent(string eventArgument)
  15.     {
  16.       base.Text = "Postback handled by " + this.ID.ToString() + ". <br/>" +
  17.                   "Postback caused by " + eventArgument.ToString() + ".";
  18.       
  19.     }
  20.   }
  21.   protected void Page_Load(object sender, EventArgs e)
  22.   {
  23.     // Get a ClientScriptManager reference from the Page class.
  24.     ClientScriptManager cs = Page.ClientScript;
  25.     // Create an instance of the custom label control and 
  26.     // add it to the page.
  27.     MyControl mycontrol = new MyControl();
  28.     mycontrol.ID = "mycontrol1";
  29.     PlaceHolder1.Controls.Add(mycontrol);
  30.     PlaceHolder1.Controls.Add(new LiteralControl("<br/>"));
  31.     
  32.     // Create a button element with its onClick attribute defined
  33.     // to create a postback event reference to the custom label control.
  34.     HtmlInputButton b = new HtmlInputButton();
  35.     b.ID = "mybutton1";
  36.     b.Value = "Click";
  37.     b.Attributes.Add("onclick", cs.GetPostBackEventReference(mycontrol, b.ID.ToString()));
  38.     PlaceHolder1.Controls.Add(b);
  39.     PlaceHolder1.Controls.Add(new LiteralControl("<br/>"));
  40.     
  41.     // Create a link element with its href attribute defined
  42.     // to create a postback event reference to the custom label control.
  43.     HtmlAnchor a = new HtmlAnchor();
  44.     a.ID = "myanchor1";
  45.     a.InnerText = "link";
  46.     a.HRef = cs.GetPostBackClientHyperlink(mycontrol, a.ID.ToString());
  47.     PlaceHolder1.Controls.Add(a);
  48.   }
  49. </script>
  50. <html  >
  51. <head id="Head1" runat="server">
  52.     <title>ClientScriptManager Example</title>
  53. </head>
  54. <body>
  55.     <form id="form1" runat="server">
  56.     <div>
  57.       <asp:PlaceHolder id="PlaceHolder1" 
  58.                        runat="server">
  59.       </asp:PlaceHolder>
  60.     </div>
  61.     </form>
  62. </body>
  63. </html>

参考:

转载地址:https://blog.csdn.net/ikmb/article/details/3575842 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Asp.net页面出现“Internet Explorer无法打开站点,已终止操作”的解决
下一篇:gridview动态绑定dropdownlist

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月20日 05时18分15秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

基于SnowFlake算法如何让分库分表中不同的ID落在同一个库的算法的实现 2019-04-27
基于springboot的ShardingSphere5.X的分库分表的解决方案之分库解决方案(二) 2019-04-27
基于springboot的ShardingSphere5.X的分库分表的解决方案之分表解决方案(一) 2019-04-27
基于springboot的ShardingSphere5.X的分库分表的解决方案之关联查询解决方案(三) 2019-04-27
基于springboot的ShardingSphere5.X的分库分表的解决方案之基于seata的分布式事务的解决方案(十五) 2019-04-27
Linux文件管理参考 2019-04-27
FTP文件管理项目(本地云)项目日报(一) 2019-04-27
FTP文件管理项目(本地云)项目日报(二) 2019-04-27
FTP文件管理项目(本地云)项目日报(三) 2019-04-27
FTP文件管理项目(本地云)项目日报(四) 2019-04-27
【C++】勉强能看的线程池详解 2019-04-27
FTP文件管理项目(本地云)项目日报(五) 2019-04-27
FTP文件管理项目(本地云)项目日报(关于不定长包的测试) 2019-04-27
FTP文件管理项目(本地云)项目日报(六) 2019-04-27
FTP文件管理项目(本地云)项目日报(七) 2019-04-27
FTP文件管理项目(本地云)项目日报(八) 2019-04-27
【Linux】血泪教训 -- 动态链接库配置方法 2019-04-27
FTP文件管理项目(本地云)项目日报(九) 2019-04-27
以练代学设计模式 -- FTP文件管理项目 2019-04-27
FTP文件管理项目(本地云)项目日报(十) 2019-04-27