本文共 1552 字,大约阅读时间需要 5 分钟。
webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="work015.WebForm1" %>回调技术
webform1.aspx.cs
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace work015{ public partial class WebForm1 : System.Web.UI.Page, ICallbackEventHandler { string result = ""; protected void Page_Load(object sender, EventArgs e) { ClientScriptManager csm = Page.ClientScript; //参数5,true表示异步,false表示同步 string reference = csm.GetCallbackEventReference(this, "args", "Success", "", "Error", false); string callbackScript = "function CallServerMethod(args,context) {\n" + reference + ";\n}"; csm.RegisterClientScriptBlock(this.GetType(), "CallServerMethod", callbackScript, true); } public void RaiseCallbackEvent(string eventArgs) { if (eventArgs.ToLower().IndexOf("admin") != -1) { result = string.Format("{0}已被注册", eventArgs); } else { result = eventArgs + "可以注册"; } } public string GetCallbackResult() { return result; } }}
转载地址:http://yirm.baihongyu.com/