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
}
查看全文
相关阅读:
第32周二
第32周一
第31周日
第31周六
第31周五
第31周四
第31周三
C++中this指针的使用方法.
ArcPad 10 的安装部署
UEditor用法
原文地址:https://www.cnblogs.com/ding0910/p/430428.html
最新文章
8.tomcat认证访问
7.分工合作include:指定多个配置文件
5.Struts2配置形式,覆盖
6.package配置相关
4.struts2的配置文件优先级
3.为什么要使用struts2代替struts1.x
2.vo传参模式和ModerDriven传参模式
Struts1项目转成Struts2项目步奏
velocity基本语法
ExtJs4得知(五岁以下儿童)主要的Ext分类
热门文章
QR代码简单
oracle_控制用户权限
最近的采访中知识的总结
IOS 数据库管理系统(SQLite)
C++
Maven聚合和继承的详细解释
怎么样eclipse发达国家多重聚合关系maven项目和使用git管理
第32周五
第32周四
第32周三
Copyright © 2011-2022 走看看