zoukankan      html  css  js  c++  java
  • <>使用 ICallbackEventHandler 接口 实现 AJAX 功能

    KP:
    ReceiveServerData    ReceiveServerData()
    CallServer           CallServer

    ==============================================================
    = at .aspx.cs:
    ==============================================================
    protected Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string cbRef = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
            string cbScript = "function CallServer(arg, context) { " + cbRef + "; }";
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServerScriptKey", cbScript, true);
        }
    }

    #region ICallbackEventHandler Methods
    private string callbackResult = "";
    public string GetCallbackResult()
    {
        // 服务器处理完RaiseCallbackEvent事件后
        // 返回给客户端一个值 callbackResult;
    }

    public void RaiseCallbackEvent(string eventArgument)
    {
        // eventArgument 是客户端通过调用 CallServer(arg, context)
        // 时的arg参数传过来到server的值
        // 此时应根据 arg的值生成 callbackResult的值
    }
    #endregion


    ==============================================================
    = at .aspx:
    ==============================================================
    <script language='javascript'>
    <!--
    function ReceiveServerData(arg, context)
    {
        // 服务器GetCallbackResult()返回的值
        // 客户端在这里处理
    }

    function onchange()
    {
        // 客户端在这里生成发送到服务器的参数arg
        // 服务器会以参数arg为eventArgument执行RaiseCallbackEvent(eventArgument)
       
        //var list = document.getElementById("listParentClass");
        //var selectedId = list.options[list.options.selectedIndex].value;
        //CallServer(selectedId, null);
    }
    </script>

  • 相关阅读:
    CS231n笔记 Lecture 4 Introduction to Neural Networks
    CS231n笔记 Lecture 3 Loss Functions and Optimization
    CS231n笔记 Lecture 1 Introduction
    LeetCode
    Python备忘录
    Celery简介
    SaltStack error: No module named 'salt'
    IO模型
    TCP协议的三次握手和四次分手
    第一章:正则表达式
  • 原文地址:https://www.cnblogs.com/hcfalan/p/581526.html
Copyright © 2011-2022 走看看