runxinzhi.com
首页
百度搜索
初识AJAX
1、HTML代码:
<%
@ Page language
=
"
c#
"
Codebehind
=
"
Default.aspx.cs
"
AutoEventWireup
=
"
false
"
Inherits
=
"
AjaxTest._Default
"
%>
<!
DOCTYPE HTML PUBLIC
"
-//W3C//DTD HTML 4.0 Transitional//EN
"
>
<
HTML
>
<
HEAD
>
<
title
>
Default
</
title
>
<
meta name
=
"
GENERATOR
"
Content
=
"
Microsoft Visual Studio .NET 7.1
"
>
<
meta name
=
"
CODE_LANGUAGE
"
Content
=
"
C#
"
>
<
meta name
=
"
vs_defaultClientScript
"
content
=
"
JavaScript
"
>
<
meta name
=
"
vs_targetSchema
"
content
=
"
http://schemas.microsoft.com/intellisense/ie5
"
>
<
script language
=
"
javascript
"
type
=
"
text/javascript
"
>
function getServerTime()
{
document.getElementById(
'
Label1
'
).innerText
=
AjaxTest._Default.GetTime().value ;
}
function add( a,b )
{
var a1
=
parseInt( a );
var b1
=
parseInt( b );
document.getElementById(
'
Label2
'
).innerText
=
AjaxTest._Default.AddTwo( a1,b1 ).value;
}
</
script
>
</
HEAD
>
<
body
>
<
form id
=
"
Form1
"
method
=
"
post
"
runat
=
"
server
"
>
<
table cellpadding
=
"
0
"
cellspacing
=
"
0
"
>
<
tr
>
<
td align
=
"
center
"
height
=
"
100
"
valign
=
"
bottom
"
><
FONT color
=
"
red
"
size
=
"
6
"
>
计算两数之和
</
FONT
></
td
>
</
tr
>
<
tr
>
<
td
>
<
asp:TextBox id
=
"
TextBox1
"
runat
=
"
server
"
></
asp:TextBox
>
<
asp:TextBox id
=
"
TextBox2
"
runat
=
"
server
"
></
asp:TextBox
>
<
input id
=
"
Button
"
type
=
"
button
"
value
=
"
计算两数之和
"
onclick
=
"
add( document.getElementById( 'TextBox1' ).value,document.getElementById( 'TextBox2' ).value )
"
>
</
td
>
</
tr
>
<
tr
>
<
td
><
asp:Label id
=
"
Label2
"
runat
=
"
server
"
Width
=
"
416px
"
Height
=
"
48px
"
></
asp:Label
></
td
>
</
tr
>
<
tr
>
<
td align
=
"
center
"
valign
=
"
bottom
"
height
=
"
100
"
><
FONT color
=
"
red
"
size
=
"
6
"
>
获取服务器时间
</
FONT
></
td
>
</
tr
>
<
tr
>
<
td
><
input id
=
"
Button1
"
type
=
"
button
"
value
=
"
获得服务器时间
"
onclick
=
"
getServerTime();
"
>
<
asp:Label id
=
"
Label1
"
runat
=
"
server
"
Width
=
"
264px
"
></
asp:Label
></
td
>
</
tr
>
</
table
>
</
form
>
</
body
>
</
HTML
>
2、CS代码:
using
System;
using
System.Collections;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Web;
using
System.Web.SessionState;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.HtmlControls;
namespace
AjaxTest
{
/**/
///
<summary>
///
_Default 的摘要说明。
///
</summary>
public
class
_Default : System.Web.UI.Page
{
protected
System.Web.UI.WebControls.TextBox TextBox1;
protected
System.Web.UI.WebControls.Label Label1;
protected
System.Web.UI.WebControls.Label Label2;
protected
System.Web.UI.WebControls.TextBox TextBox2;
private
void
Page_Load(
object
sender, System.EventArgs e)
{
//
在此处放置用户代码以初始化页面
AjaxPro.Utility.RegisterTypeForAjax(
typeof
( _Default ) );
}
Web 窗体设计器生成的代码
#region
Web 窗体设计器生成的代码
override
protected
void
OnInit(EventArgs e)
{
//
//
CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base
.OnInit(e);
}
/**/
///
<summary>
///
设计器支持所需的方法 - 不要使用代码编辑器修改
///
此方法的内容。
///
</summary>
private
void
InitializeComponent()
{
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
}
#endregion
[AjaxPro.AjaxMethod]
public
int
AddTwo(
int
a,
int
b )
{
return
a
+
b;
}
[AjaxPro.AjaxMethod]
public
DateTime GetTime()
{
return
DateTime.Now;
}
}
//
end class
}
3、WEBCONFIG
<
httpHandlers
>
<
add verb
=
"
*
"
path
=
"
*.ashx
"
type
=
"
AjaxPro.AjaxHandlerFactory,AjaxPro
"
/>
</
httpHandlers
>
相关阅读:
16平衡树
15二叉检索树
11用户权限
10触发器
8函数
8存储过程
linux下如何进入单用户模式
RHEL6.4 字符模式下安装图形界面图文教程
杂记
Java内存管理(一):深入Java内存区域
原文地址:https://www.cnblogs.com/wander/p/476525.html
最新文章
mysql查看正在运行的语句
php生成0~1随机小数方法
php str_getcsv解决explode不能解决的问题
php实现文件与16进制相互转换
PHP比较两个版本的方法
Android:ImageView应用之图片浏览器
十六 直线检测
十五 Canny边缘检测算法
十四 图像梯度
十三 高斯金字塔和拉普拉斯金字塔
热门文章
十二 图像二值化
十一 模板匹配match template
十 直方图
九 模糊操作
八 ROI(region of interest)和泛洪填充
七 图片切割、合并、填充
19哈夫曼树
18B树、B++树和Trie树
17红黑树
16-1平衡树源代码
Copyright © 2020-2023
润新知