62,243
社区成员




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;
using System.Threading;
public partial class ICallbackEventHandlerTest : System.Web.UI.Page, ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
Page.ClientScript.GetCallbackEventReference(this, "ShowReceipt", "ShowReceiptList", "context");
}
#region 异步调用btn
public string strCallback;
public string GetCallbackResult()
{
return this.Button1.ID;
}
public void RaiseCallbackEvent(string eventArgument)
{
Button1_Click(null, null);
}
protected void Button1_Click(object sender, EventArgs e)
{
DoIt(Server.MapPath("/"));
Thread.Sleep(2000);
//ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('后台方法');</script>");
}
#endregion
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ICallbackEventHandlerTest.aspx.cs" Inherits="ICallbackEventHandlerTest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
//失效时间
var nTime=2000;
function SetBtnDisabled(s_id)
{
var btn = document.getElementById(s_id);
if(btn)
{
btn.disabled=true;
// setTimeout("SetBtnEnabled('" + s_id + "')",nTime);
}
}
function SetBtnEnabled(ch_id)
{
var btn = document.getElementById(ch_id);
if(btn)
{
btn.disabled=false;
btn.value= "操作执行完毕....";
}
}
function buttonClick()
{
var bt = event.srcElement;
if(bt)
{
bt.value = "正在执行操作...."; alert(bt.value);
SetBtnDisabled(bt.id)
GetServerReceipt(bt.id);
}
}
//调用后台方法
function GetServerReceipt(receiptID)
{
var context = '';
WebForm_DoCallback('__Page',receiptID,ShowReceiptList,context,null,false);
}
//后台回调方法
function ShowReceiptList(ShowReceipt, context)
{
SetBtnEnabled(ShowReceipt);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="点我" OnClientClick="return buttonClick()"/></div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>无标题页</title>
<script type="text/javascript">
//失效时间
var nTime=2000;
function SetBtnDisabled(s_id)
{
var btn = document.getElementById(s_id);
if(btn)
{
btn.disabled=true;
setTimeout("SetBtnEnabled('" + s_id + "')",nTime);
}
}
function SetBtnEnabled(ch_id)
{
var btn = document.getElementById(ch_id);
if(btn)
{
btn.disabled=false;
btn.value= "操作执行完毕....";
}
}
function buttonClick()
{
if(!confirm("是否回发服务器?"))
return false;
else
{
var bt = event.srcElement;
if(bt)
{
bt.value = "正在执行操作...."; alert(bt.value);
SetBtnDisabled(bt.id)
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="divToolbar" runat="server">
<asp:Button ID="Button1" runat="server" Text="点我" OnClientClick="return buttonClick()" OnClick="Button1_Click" /></div>
</form>
</body>
</html>
protected void Button1_Click(object sender, EventArgs e)
{
DoIt(Server.MapPath("/"));
}