zoukankan      html  css  js  c++  java
  • Ajax技术三种实现方式之asp.net2.0 callback篇 (四)

    View Code
    1 一、 Asp.net2.0的形式:CallBack
    2 1、CallBack.aspx
    3 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CallBack.aspx.cs" Inherits="AJAX.CallBack" %>
    4
    5 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    6
    7 <html xmlns="http://www.w3.org/1999/xhtml" >
    8 <head runat="server">
    9 <title>Untitled Page</title>
    10 <mce:script language="javascript" type="text/javascript"><!--
    11 function ReceiveServerData(arg, context)
    12 {
    13 document.getElementById ("msg_display").innerHTML=arg;
    14 }
    15 function CallTheServer(arg,context)
    16 {
    17 <%=ClientScript.GetCallbackEventReference(this,"arg", "ReceiveServerData", "context") %>
    18 }
    19 // --></mce:script>
    20 </head>
    21 <body>
    22 <form id="form1" runat="server">
    23 <div>
    24 <input id="testmsg" type="text" value="Hello,World!" style=" 214px"><br />
    25 <input type="button" value="單擊這個" onclick="CallTheServer(document.getElementById('testmsg').value)" />
    26 提交给服务器的CallBack
    27
    28 <div id="msg_display" style="background: yellow; font-weight: bold; font-size: 13px" mce_style="background: yellow; font-weight: bold; font-size: 13px">
    29 从服务器返回的信息在这里显示...</div>
    30 </div>
    31 </form>
    32 </body>
    33 </html>
    34
    35 2、CallBack.aspx.cs
    36 using System;
    37 using System.Collections;
    38 using System.Configuration;
    39 using System.Data;
    40 using System.Linq;
    41 using System.Web;
    42 using System.Web.Security;
    43 using System.Web.UI;
    44 using System.Web.UI.HtmlControls;
    45 using System.Web.UI.WebControls;
    46 using System.Web.UI.WebControls.WebParts;
    47 using System.Xml.Linq;
    48 using System.Text;
    49 namespace AJAX
    50 {
    51 public partial class CallBack : System.Web.UI.Page,ICallbackEventHandler
    52 {
    53 protected void Page_Load(object sender, EventArgs e)
    54 {
    55
    56 }
    57 // Summary:
    58 // Returns the results of a callback event that targets a control.
    59 //
    60 // Returns:
    61 // The result of the callback.
    62 StringBuilder builder = new StringBuilder();
    63 public string GetCallbackResult()
    64 {
    65 return builder.ToString();
    66 }
    67 //
    68 // Summary:
    69 // Processes a callback event that targets a control.
    70 //
    71 // Parameters:
    72 // eventArgument:
    73 // A string that represents an event argument to pass to the event handler.
    74 public void RaiseCallbackEvent(string eventArgument)
    75 {
    76 builder.Append("服务器callback得到了您输入的信息:" + eventArgument + "<br/>您的IP地址是:");
    77 builder.Append(Request.UserHostAddress);
    78 builder.Append("<br/>当前服务器的时间:");
    79 builder.Append(DateTime.Now.ToLocalTime());
    80 }
    81 }
    82 }
  • 相关阅读:
    看板娘相关源码介绍
    Spring框架实体bean转json返回前端报错:Null key for a Map not allowed in JSON (use a converting NullKeySerializer?)
    Spring Data JPA介绍以及dao层(持久层)标准接口或自定义方法规则
    BeanNotOfRequiredTypeException:Bean named 'XXXX' is expected to be of type 'XXX' but was actually of type 'com.sun.proxy.$Proxy211'
    RedisDesktopManager的编译
    Spring-Boot中@Scheduled注解不生效
    @Async 注解不生效
    使用MongoTemplate,启动时候报错:org.springframework.beans.factory.BeanCreationException
    【个人经验之谈】计算机相关的就业、培训等问题解疑答惑
    简单java mail demo收发邮件例子,各种邮件类型
  • 原文地址:https://www.cnblogs.com/mahaisong/p/2016960.html
Copyright © 2011-2022 走看看