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
}
查看全文
相关阅读:
Codeforces Round #450 (Div. 2)
吉哥系列故事——恨7不成妻(数位DP)
Codeforces Round #546 (Div. 2)
Balanced Numbers (数位DP)
XHXJ's LIS(数位DP)
Balanced Number(数位DP)
(2016北京集训十三)【xsy1533】mushroom
(2016北京集训十三)【xsy1532】网络战争
(2016北京集训十三)【xsy1531】魔法游戏
(2016北京集训十二)【xsy1542】疯狂求导
原文地址:https://www.cnblogs.com/ding0910/p/430428.html
最新文章
最长括号化长度 java
高性能Mysql
使用递归打印二叉树的左视图 java
mysql 出现的错误
数据库知识,mysql索引原理
oracle 安装,登陆,配置
多版本python的使用
ubuntu 忘记root密码
python的pexpect详解
ntp服务配置
热门文章
linux设置系统时间与时区以及设置bios时间同步系统时间
keepalived检测脚本及注意事项
keepalived主从及双主配置
Keepalived安装配置
zabbix安装配置
linux上安装redis4.0.9
Codeforces Round #518 (Div. 2) [Thanks, Mail.Ru!]
Codeforces Round #520 (Div. 2)
Aladdin and the Flying Carpet
Codeforces Round #257 (Div. 2)
Copyright © 2011-2022 走看看