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
}
查看全文
相关阅读:
Springmvc全局异常处理
SpringMVC异常处理一
[GDB7] gdb 的学习
《Python 第七章》更加抽象
python问题:IndentationError:expected an indented block错误解决
[C/C++] C++ 类的学习
[GCC6] gcc 的学习
[Python] 列表 list
[python] 循环与轻量级 pass, del, eval
《Python 第八章》异常
原文地址:https://www.cnblogs.com/ding0910/p/430428.html
最新文章
Alpha通道的概念与功能
浅议Unix的defunct进程(“僵尸”进程)
Visual Studio 2010
dll hell
fork两次如何避免僵尸进程收藏
gdb调试多线程
gdb调试多线程
请先给自己戴好氧气面罩
dll hell
Alpha通道的概念与功能
热门文章
落窝了
共同分享
业务知识保险中的抽档什么意思
使用springmvc实现增加用户功能
使用SpringMVC框架,实现修改用户的功能
MVC标签加载静态资源文件
使用Spring框架自带的标签库改造添加用户功能
使用JSR303框架对数据进行验证spring框架
Springmvc框架实现用户列表查询·
Rest风格spingMVC框架
Copyright © 2011-2022 走看看