zoukankan      html  css  js  c++  java
  • ASP.NET 2.0中实现客户端回调的简化版

           上面总结的这么多,也许看起来有些晕,我下面给出一个简化版的实现无动态刷新的例子:
             可以在客户端无动态刷新的取服务器端的时间

    新建一个页面:
    后台代码:
    public partial class Test : System.Web.UI.Page, ICallbackEventHandler
    {
        public string strVal = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            ClientScriptManager cs = Page.ClientScript;
            string callback = cs.GetCallbackEventReference(this, "this.value", "FunTest", "this.value");
            txt.Attributes.Add("onclick", callback);
        }


        public void RaiseCallbackEvent(string eventArgument)
        {
            //char[] chars = eventArgument.ToCharArray();
            //Array.Reverse(chars);
            //strVal =  new string(chars);
            strVal =  DateTime.Now.ToString();
        }

        public string GetCallbackResult()
        {
            return strVal;
        }
    }

    页面代码
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
        <script language="javascript">
            function FunTest(result,context)
            {
                document.getElementById("txt").value = result + "      " + context;
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="txt" runat="server"></asp:TextBox>
        </div>
        </form>
    </body>
    </html>

  • 相关阅读:
    macOS免费的NTFS读写软件
    Python模块和模块引用(一)
    Python Class (一)
    Ubuntu系统管理systemd
    Case Closed?
    The 'with' and 'as' Keywords
    Buffering Data
    rstrip
    堆排序
    堆 续9
  • 原文地址:https://www.cnblogs.com/weiweictgu/p/356511.html
Copyright © 2011-2022 走看看