zoukankan
html css js c++ java
ICallbackEventHandler接口实现无刷新调用后台
前台HTML代码
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Default.aspx.cs
"
Inherits
=
"
_Default
"
%>
<!
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
>
<
title
>
Untitled Page
</
title
>
<
script
type
="text/javascript"
>
<!--
function
test()
{
var
lb
=
document.getElementById(
"
Select1
"
);
//
取的那个下拉框
var
argTxt
=
lb.options[lb.selectedIndex].text;
//
得到你选择的下拉框的文本再调用CallTheServer,由服务器端输出的js函数
CallTheServer(argTxt,'');
}
function
ReceiveServerData(rValue,context)
{
document.getElementById('Results').innerHTML=rValue
;
}
//
-->
</
script
>
</
head
>
<
body
>
<
form
id
="form1"
runat
="server"
>
<
div
>
<
select
id
="Select1"
>
<
option
value
="1"
selected
="selected"
>
我为歌狂
</
option
>
<
option
value
="2"
>
正义之名
</
option
>
<
option
value
="3"
>
永不加赋
</
option
>
</
select
>
<
br
/>
<
br
/>
<
input
onclick
="test()"
value
="从服务器返回下拉框文本"
type
="button"
/>
<
br
/>
<
br
/>
<
span
id
="Results"
></
span
>
<
br
/>
</
div
>
</
form
>
</
body
>
</
html
>
using
System;
using
System.Data;
using
System.Configuration;
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
_Default : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
//
实现ICallbackEventHandler接口
{
private
string
_callbackEventArgument;
protected
void
Page_Load(
object
sender, EventArgs e)
{
String cbReference
=
Page.ClientScript.GetCallbackEventReference(
this
,
"
arg
"
,
"
ReceiveServerData
"
,
"
context
"
);
String callbackScript;
callbackScript
=
"
function CallTheServer(arg,context)
"
+
"
{
"
+
cbReference
+
"
} ;
"
;
Page.ClientScript.RegisterStartupScript(
this
.GetType(), Guid.NewGuid().ToString(), callbackScript,
true
);
}
public
String RaiseCallbackEvent(String eventArgument)
{
return
"
你选择的是:
"
+
eventArgument;
}
//
自动生成接口成员
ICallbackEventHandler 成员
#region
ICallbackEventHandler 成员
string
ICallbackEventHandler.GetCallbackResult()
{
//
throw new Exception("The method or operation is not implemented.");
return
_callbackEventArgument;
}
void
ICallbackEventHandler.RaiseCallbackEvent(
string
eventArgument)
{
//
throw new Exception("The method or operation is not implemented.");
_callbackEventArgument
=
this
.RaiseCallbackEvent(eventArgument);
}
#endregion
}
查看全文
相关阅读:
八、JVM视角浅理解并发和锁
七、JVM类加载机制
六、JVM命令和工具
五、jvm垃圾回收3(几种垃圾收集器)
四、JVM垃圾回收2(垃圾收集算法)
jvm引用类型
三、JVM垃圾回收1(如何寻找垃圾?)
【原创】Android 对话框的使用
【原创】CMD常用命令:解决实际问题
【原创】开机出现grub rescue,修复办法
原文地址:https://www.cnblogs.com/ding0910/p/430428.html
最新文章
Linux安装Zabbix客户端
Jenkins 参数化shell脚本
Linux下安装ActiveMQ5.16
Docker安装Oracle11g
-bash: $'yum302240install302240libxml2': command not found
编译安装PHP5.6
nginx配置CDN和自签名SSL
内存与地址的理解
java虚拟机
Spring boot配置mybatis
热门文章
头条类网站的数据库设计
初探mybatis框架
mysql常用基础知识
MySql和Mysql Workbench安装事宜
spring boot中的IOC和AOP
spring boot之http,页面状态跳转与异常处理实战
Thymeleaf初体验
java中HashTable、HashMap、LinkedHashMap
转(hash算法原理详解)
ThreadLocal了解
Copyright © 2011-2022 走看看