c# asp.net ajax 用法一例
2011-06-09 16:36
459 查看
c# asp.net ajax 用法一例
<%@ Page Language="C#" AutoEventWireup="true" ...%>
<script type="text/javascript">
//Ajax Asp.net 2.0方法
//---------------eg2 begin
function ReceiveServerData1(arg, context) {
document.form1.Text1.value = arg;
//document.getElementById('Text1').value=arg;
}
var tmp = 0;
function ReceiveServerData2(arg, context) {
Message1.innerText = arg;
tmp = arg;
}
function ProcessCallBackError(arg, context) {
}
//---------------eg2 end
</script>
<div>
输入:<input id="Text1" type="text" value="8" />
<input id="Button2" type="button" value="点击" onclick="CallTheServer1(Text1.value,null)"/>
</div>
<p></p>
<p></p>
<p>
演示:<span id="Message1">0 </span>
<input id="Button3" type="button" value="点击" onclick="CallTheServer2(tmp,null)" />
</p>
class Weather_WeatherComCn : System.Web.UI.Page, ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
//Ajax Asp.net 2.0方法
//---------------------
ClientScriptManager cs = Page.ClientScript;
StringBuilder context1 = new StringBuilder();
context1.Append("function ReceiveServerData1(arg, context)");
context1.Append("{");
context1.Append(" document.getElementById('Text1').value=arg;");
context1.Append("");
context1.Append("}");
String cbReference1 = cs.GetCallbackEventReference("'" + Page.UniqueID + "'", "arg", "ReceiveServerData1", "", "ProcessCallBackError", false);
String callbackScript1 = "function CallTheServer1(arg, context) {" +cbReference1 + "; }";
cs.RegisterClientScriptBlock(this.GetType(), "CallTheServer1", callbackScript1, true);
//function CallTheServer2(arg, context)
// {WebForm_DoCallback('__Page',arg,ReceiveServerData2,/"/",ProcessCallBackError,false);
String cbReference2 = cs.GetCallbackEventReference("'" +Page.UniqueID + "'", "arg", "ReceiveServerData2", "","ProcessCallBackError", false);
String callbackScript2 = "function CallTheServer2(arg, context) {" +cbReference2 + "; }";
cs.RegisterClientScriptBlock(this.GetType(), "CallTheServer2", callbackScript2, true);
//---------------------
if (!IsPostBack)
{
}
}
#region ICallbackEventHandler 成员
public int cbCount = 0;
public string GetCallbackResult()
{
//Response.Write(cbCount.ToString());
return cbCount.ToString();
}
public void RaiseCallbackEvent(String eventArgument)
{
cbCount = Convert.ToInt32(eventArgument) + 1;
}
#endregion
}
<%@ Page Language="C#" AutoEventWireup="true" ...%>
<script type="text/javascript">
//Ajax Asp.net 2.0方法
//---------------eg2 begin
function ReceiveServerData1(arg, context) {
document.form1.Text1.value = arg;
//document.getElementById('Text1').value=arg;
}
var tmp = 0;
function ReceiveServerData2(arg, context) {
Message1.innerText = arg;
tmp = arg;
}
function ProcessCallBackError(arg, context) {
}
//---------------eg2 end
</script>
<div>
输入:<input id="Text1" type="text" value="8" />
<input id="Button2" type="button" value="点击" onclick="CallTheServer1(Text1.value,null)"/>
</div>
<p></p>
<p></p>
<p>
演示:<span id="Message1">0 </span>
<input id="Button3" type="button" value="点击" onclick="CallTheServer2(tmp,null)" />
</p>
class Weather_WeatherComCn : System.Web.UI.Page, ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
//Ajax Asp.net 2.0方法
//---------------------
ClientScriptManager cs = Page.ClientScript;
StringBuilder context1 = new StringBuilder();
context1.Append("function ReceiveServerData1(arg, context)");
context1.Append("{");
context1.Append(" document.getElementById('Text1').value=arg;");
context1.Append("");
context1.Append("}");
String cbReference1 = cs.GetCallbackEventReference("'" + Page.UniqueID + "'", "arg", "ReceiveServerData1", "", "ProcessCallBackError", false);
String callbackScript1 = "function CallTheServer1(arg, context) {" +cbReference1 + "; }";
cs.RegisterClientScriptBlock(this.GetType(), "CallTheServer1", callbackScript1, true);
//function CallTheServer2(arg, context)
// {WebForm_DoCallback('__Page',arg,ReceiveServerData2,/"/",ProcessCallBackError,false);
String cbReference2 = cs.GetCallbackEventReference("'" +Page.UniqueID + "'", "arg", "ReceiveServerData2", "","ProcessCallBackError", false);
String callbackScript2 = "function CallTheServer2(arg, context) {" +cbReference2 + "; }";
cs.RegisterClientScriptBlock(this.GetType(), "CallTheServer2", callbackScript2, true);
//---------------------
if (!IsPostBack)
{
}
}
#region ICallbackEventHandler 成员
public int cbCount = 0;
public string GetCallbackResult()
{
//Response.Write(cbCount.ToString());
return cbCount.ToString();
}
public void RaiseCallbackEvent(String eventArgument)
{
cbCount = Convert.ToInt32(eventArgument) + 1;
}
#endregion
}
相关文章推荐
- c# asp.net ajax 用法一例
- [导入]ASP.NET AJAX客户端编程之旅(三)——让JavaScript和C#无障碍沟通:数据类型自动转换&序列化
- AJAX 怎样在一个UpDatePanel中刷新另一个updatePanel (asp.net C#)
- C# Asp.Net Ajax简单聊天室源码和设计文档
- ASP.NET中AJAX的UpdatePannel控件的用法
- Bind和Eval的不同用法 (asp.net C#)
- asp.net MVC中防止跨站请求攻击(CSRF)的ajax用法
- asp.net(c#) MS AJAX的安装
- ASP.NET Ajax AsyncFileUpload 控件用法
- Javascript 直接调用服务器C#代码 ASP.NET Ajax实例
- asp.net(c#) static关键字用法小结
- ASP.NET Ajax实例—Javascript直接调用服务器C#代码
- ASP.NET AjaxControlToolkit 的基本用法
- asp.net(c#) static关键字用法小结[zz]
- ajax asp.net ashx用法
- ASP.NET MVC Ajax.ActionLink 简单用法
- 清新空气---我的.net(C#)生涯知识总结 跨CSS,JS,JAVA,AJAX,WPF,WCF,LINQ,ASP.NET,Winform,Sqlserver,Mysql,EF,OOP,开发工具等
- ASP.NET C#中Application的用法教程
- ASP.NET2.0中ClientScriptManager的用法(使用ASP.NET 2.0 AJAX 弹出对话框)
- ASP.NET MVC应用中浏览器无法发出Ajax请求的问题解决一例