• ICallbackEventHandler asp.net页面异步回发


    ICallbackEventHandler 接口:用于指示控件可以作为服务器的回调事件的目标。

    asp.net页面通实现该接口可以实现无刷新回发。

    后台:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public partial class Default2 : System.Web.UI.Page, ICallbackEventHandler
    {
        private string ttt;
        protected void Page_Load(object sender, EventArgs e)
        {
            ClientScriptManager csm = this.ClientScript;
            string t = csm.GetCallbackEventReference(this"arg""test""context");//生成客户端的回发函数,注意此处的arg,context.要与下行中的注册js函数的参数相同
            csm.RegisterStartupScript(this.GetType(), "x""function gml(arg,context){" + t + "}"true);
        }

        public string GetCallbackResult()
        {
            return ttt;
        }

        public void RaiseCallbackEvent(string eventArgument)
        {
            ttt = "OK" + eventArgument;
        }
    }

    前台代码:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
         
    function test(re,context) {
             alert(re);
           alert(context);
         }
         
    function clicktest() {
             gml(
    "txt","x");
         }

        
    </script>
        <style type="text/css">
         #t    
         
    {
             position
    :absolute;
             width
    :500px;
             height
    :300px;
             background-color
    :blue;
             
    }
        
    </style>
    </head>
    <body>
        <form id="form1" runat="server">
        
        </form>
        <div id="t">
            <a  onclick="clicktest()">about</a>
        </div>
    </body>
    </html>
  • 相关阅读:
    Python-爬虫-解析库(pyquery)的使用
    Python-爬虫-解析库(Beautiful Soup)的使用
    Python-爬虫-基本库(requests)使用-抓取猫眼电影Too100榜
    Python-爬虫-基本库(requests)使用
    Go基础及语法(五)
    Go基础及语法(四)
    Go基础及语法(三)
    Go基础及语法(二)
    Go基础及语法(一)
    MySQL8.0随笔整理
  • 原文地址:https://www.cnblogs.com/guolihao/p/2615312.html
Copyright © 2020-2023  润新知