用__doPostBack()方法调用后台方法的方式中,页面没有__doPostBack()函数的解决
发布日期:2021-07-17 20:20:32
浏览次数:2
分类:技术文章
本文共 2018 字,大约阅读时间需要 6 分钟。
用ClientScriptManager.GetPostBackEventReference 方法产生__doPostBack()函数
- <%@ Page Language="C#" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <script runat="server">
- public class MyControl : Label, IPostBackEventHandler
- {
- // Use the constructor to defined default label text.
- public MyControl()
- {
- base.Text = "No postback raised.";
- }
- // Implement the RaisePostBackEvent method from the
- // IPostBackEventHandler interface.
- public void RaisePostBackEvent(string eventArgument)
- {
- base.Text = "Postback handled by " + this.ID.ToString() + ". <br/>" +
- "Postback caused by " + eventArgument.ToString() + ".";
- }
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- // Get a ClientScriptManager reference from the Page class.
- ClientScriptManager cs = Page.ClientScript;
- // Create an instance of the custom label control and
- // add it to the page.
- MyControl mycontrol = new MyControl();
- mycontrol.ID = "mycontrol1";
- PlaceHolder1.Controls.Add(mycontrol);
- PlaceHolder1.Controls.Add(new LiteralControl("<br/>"));
- // Create a button element with its onClick attribute defined
- // to create a postback event reference to the custom label control.
- HtmlInputButton b = new HtmlInputButton();
- b.ID = "mybutton1";
- b.Value = "Click";
- b.Attributes.Add("onclick", cs.GetPostBackEventReference(mycontrol, b.ID.ToString()));
- PlaceHolder1.Controls.Add(b);
- PlaceHolder1.Controls.Add(new LiteralControl("<br/>"));
- // Create a link element with its href attribute defined
- // to create a postback event reference to the custom label control.
- HtmlAnchor a = new HtmlAnchor();
- a.ID = "myanchor1";
- a.InnerText = "link";
- a.HRef = cs.GetPostBackClientHyperlink(mycontrol, a.ID.ToString());
- PlaceHolder1.Controls.Add(a);
- }
- </script>
- <html >
- <head id="Head1" runat="server">
- <title>ClientScriptManager Example</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:PlaceHolder id="PlaceHolder1"
- runat="server">
- </asp:PlaceHolder>
- </div>
- </form>
- </body>
- </html>
参考:
转载地址:https://blog.csdn.net/ikmb/article/details/3575842 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
感谢大佬
[***.8.128.20]2024年04月20日 05时18分15秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
基于SnowFlake算法如何让分库分表中不同的ID落在同一个库的算法的实现
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