在takako_mu 的基礎上補充我自己知道的另外兩種方法
http://topic.csdn.net/u/20090519/09/c14682c9-b3ec-45f7-a1bb-86872e28f942.html是第一種第二種:利用ICallbackEventHandler
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UseICallbackEventHandler.aspx.cs" Inherits="UseICallbackEventHandler" %>
<!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>
<%--
該類繼承自 System.Web.UI.ICallbackEventHandler
定義一個公用變量 rotected string returnValue;
Server呼叫RaiseCallbackEvent方法進行事件處理
GetCallbackResult方法將結果返回到Client
--%>
<script type="text/ecmascript">
function PostValue()
{
CallServer(document.getElementById("TextBox1").value, "");
}
function ReceiveServerData(rValue)
{
document.getElementById("TextBox2").value = rValue;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<input type="button" onclick="PostValue();" value="......" />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class UseICallbackEventHandler : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
protected string returnValue;
protected void Page_Load(object sender, EventArgs e)
{
string cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
string callbackScript;
callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + ";}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
}
public void RaiseCallbackEvent(string eventArgument)
{
returnValue = "Hello: " + eventArgument;
}
public string GetCallbackResult()
{
return returnValue;
}
}
http://topic.csdn.net/u/20090519/09/c14682c9-b3ec-45f7-a1bb-86872e28f942.html是第一種第二種:利用ICallbackEventHandler
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UseICallbackEventHandler.aspx.cs" Inherits="UseICallbackEventHandler" %>
<!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>
<%--
該類繼承自 System.Web.UI.ICallbackEventHandler
定義一個公用變量 rotected string returnValue;
Server呼叫RaiseCallbackEvent方法進行事件處理
GetCallbackResult方法將結果返回到Client
--%>
<script type="text/ecmascript">
function PostValue()
{
CallServer(document.getElementById("TextBox1").value, "");
}
function ReceiveServerData(rValue)
{
document.getElementById("TextBox2").value = rValue;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<input type="button" onclick="PostValue();" value="......" />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class UseICallbackEventHandler : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
protected string returnValue;
protected void Page_Load(object sender, EventArgs e)
{
string cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
string callbackScript;
callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + ";}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);
}
public void RaiseCallbackEvent(string eventArgument)
{
returnValue = "Hello: " + eventArgument;
}
public string GetCallbackResult()
{
return returnValue;
}
}
解决方案 »
- 谁能帮检查一下这个搜索页哪里出错啊
- 关于NHibernate双向一对多关系问题
- Session的一个问题
- ~~分不多了~~请高手合路过的近来看看~~关于在一个aspx页面里关闭另外一个页面的困惑~~~
- 学习Enterprise Library中,遇到了问题,请求帮助。
- 请问asp.net的数据连接池问题
- 100分求够DotNetTextBox服务器控件的序列号!
- 急:继承的Web页面中有关Session的问题
- 请教大家一个简单问题:假如有一个字符型编号是12位字长,每条记录的编号有长有短,哪么我是采用char(12)还是varchar(12)类型更节省资源
- 请问如何将页面过期
- 终于升3星了,低调散分。
- 奇怪的问题 错误 运算符“+”无法应用于“string”和“方法组”类型的操作数
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UseUpdatePanel.aspx.cs" Inherits="UseUpdatePanel" EnableEventValidation="false" %>
<!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>
<%--
在用Button2調用Button1的事件的時候在Page中加上 EnableEventValidation="false"
利用UpdatePanel實現頁面局部刷新
--%>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button1" />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<input type="button" id="Button2" name="Button2" onclick="Fun()" value="Do Button1" />
</div>
</form>
<script language="javascript" type="text/javascript">
function Fun()
{
__doPostBack(form1.Button1.id, form1.Button1.value);
}
</script>
</body>
</html>using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;public partial class UseUpdatePanel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
this.TextBox2.Text = this.TextBox1.Text;
}
}
其实.你应该更注意更多一层js ->post/get url request->server ->response ->解析,显示而你上面的解决方法均封装了这些步骤
每个封装你称之为一个方法.呵呵.
用的是VS2008自帶的ajax