<!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>
</head>
<script type="text/javascript">
//由button调用
function CallServer(inputcontrol, context)
{
context.innerHTML = "Loading";
arg = inputcontrol.value;
//注册回调方法
<%= ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context")%>;
}
//在回调方法中注册的接收返回结果的函数
function ReceiveServerData(result, context)
{
context.innerHTML = result;
}
</script>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" EnableViewState = "true" EnableTheming = "true" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<input id="Button1" type="button" value="提交到Label1" onclick="CallServer(TextBox1, Label1)"/>
<asp:Label ID="Label1" runat="server" Text="Label1:"></asp:Label>
</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 Default5 : System.Web.UI.Page, ICallbackEventHandler
{
private string str;
protected void Page_Load(object sender, EventArgs e)
{
}
public void RaiseCallbackEvent(string eventArgument)
{
//可以根据传递的参数不同,调用不同的处理逻辑
str = "从服务器端返回的内容:" + eventArgument;
}
public string GetCallbackResult()
{
return str;
}
}