zoukankan      html  css  js  c++  java
  • asp.net 2.0 中ICallbackEventHandler的使用(无刷新页面)




    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        
    <title>Untitled Page</title>
        
    <script>
         
    function callToServer()
    {
        
    var param = document.getElementById("txtMessage").value;
        
    var context = "";
    <% = blientScript %>  
    }


    function handleResultFromServer(result, context)
    {
        document.getElementById(
    "txtResult").value = result;
    }

        
    </script>
    </head>
    <body>
        
    <form id="form1" runat="server">
        
    <div>
        
    <INPUT id="txtMessage" />
    <INPUT onclick="callToServer();" type="button" value="Call to Server" id="Button1" />
    Result : 
    <INPUT id="txtResult" />
        
    </div>
        
    </form>
    </body>
    </html>


    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class _Default : System .Web.UI .Page , System.Web.UI.ICallbackEventHandler
    {
        
    protected void Page_Load(object sender, EventArgs e)
        
    {
           

        }

       
    protected  String blientScript
        
    {
            
    get
            

                
    return this.ClientScript.GetCallbackEventReference(this"param""handleResultFromServer""context");
            }

        }


        
    public string RaiseCallbackEvent(string eventArgument)
        
    {
            
    return "客户端在[" + DateTime.Now.ToString() + "]传送来 [" + eventArgument + "].";
        }



    }


    原来作者那个无法通过调试....应当这样...
     
    return this.ClientScript.GetCallbackEventReference(this"param""handleResultFromServer""context"); //应当这样 在 (asp.net beta2 中)


    //参考

    http://blog.joycode.com/kaneboy/archive/2004/07/07/26914.aspx

  • 相关阅读:
    AngularJS Insert Update Delete Using PHP MySQL
    Simple task manager application using AngularJS PHP MySQL
    AngularJS MySQL and Bootstrap Shopping List Tutorial
    Starting out with Node.js and AngularJS
    AngularJS CRUD Example with PHP, MySQL and Material Design
    How to install KVM on Fedora 22
    Fake_AP模式下的Easy-Creds浅析
    河南公务员写古文辞职信
    AI
    政协委员:最大愿望是让小学生步行上学
  • 原文地址:https://www.cnblogs.com/gwazy/p/207477.html
Copyright © 2011-2022 走看看