AjaxPro.2.dll在VS2005使用中的基本使用
2009-07-23 17:49
344 查看
在web.config文件中的<system.web>加入以下设置
<
httpHandlers
>
<
add
verb
="POST,GET"
path
="ajaxpro/*.ashx"
type
="AjaxPro.AjaxHandlerFactory,AjaxPro.2"
/>
</
httpHandlers
>
3. 创建一个页面Default.aspx
4. 在Default.aspx.cs文件的Page_Load中注册AJAX可调用的类的名称
protected
void
Page_Load(
object
sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(
typeof
(_Default));
}
5. 创建AJAX可调用的方法:
[AjaxPro.AjaxMethod]
public
string
SetTb(
string
name)
{
return
name;
}
注意:[AjaxPro
.AjaxMethod]是定义AjaxPro
可调用的方法,是必须要注明的
6. 前台代码:
<
%@ 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 runat
=
"
server
"
>
<
title
>
无标题页
</
title
>
<
script language
=
"
javascript
"
type
=
"
text/javascript
"
>
//
<
!CDATA[
Function comit_onclick()
function
comit_onclick()
{
var name
=
document.getElementById(
"
tb1
"
).value;
_Default.SetTb(name,callback);
}
Function callback()
function
callback(res)
{
document.getElementById(
"
tb
"
).value
=
res.value;
}
//
]]
>
</
script
>
</
head
>
<
body
>
<
form id
=
"
form1
"
runat
=
"
server
"
>
<
div
>
<
asp:TextBox ID
=
"
tb1
"
runat
=
"
server
"
></
asp:TextBox
><
br
/>
<
input
id
=
"
comit
"
type
=
"
button
"
value
=
"
Ok
"
onclick
=
"
return comit_onclick()
"
/>
<
br
/><
asp:TextBox ID
=
"
tb
"
runat
=
"
server
"
></
asp:TextBox
>
</
div
>
</
form
>
</
body
>
</
html
>
注意:这里值得注意的地方是
_Default.SetTb(name,callback);这句话是为了调用_Default.aspx.cs后台代码中SetTb这个方法的,如果
这个方法没有要传递的参数则指明返回的处理方法是哪一个就OK了,写成_Default.SetTb(callback);
<
httpHandlers
>
<
add
verb
="POST,GET"
path
="ajaxpro/*.ashx"
type
="AjaxPro.AjaxHandlerFactory,AjaxPro.2"
/>
</
httpHandlers
>
3. 创建一个页面Default.aspx
4. 在Default.aspx.cs文件的Page_Load中注册AJAX可调用的类的名称
protected
void
Page_Load(
object
sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(
typeof
(_Default));
}
5. 创建AJAX可调用的方法:
[AjaxPro.AjaxMethod]
public
string
SetTb(
string
name)
{
return
name;
}
注意:[AjaxPro
.AjaxMethod]是定义AjaxPro
可调用的方法,是必须要注明的
6. 前台代码:
<
%@ 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 runat
=
"
server
"
>
<
title
>
无标题页
</
title
>
<
script language
=
"
javascript
"
type
=
"
text/javascript
"
>
//
<
!CDATA[
Function comit_onclick()
function
comit_onclick()
{
var name
=
document.getElementById(
"
tb1
"
).value;
_Default.SetTb(name,callback);
}
Function callback()
function
callback(res)
{
document.getElementById(
"
tb
"
).value
=
res.value;
}
//
]]
>
</
script
>
</
head
>
<
body
>
<
form id
=
"
form1
"
runat
=
"
server
"
>
<
div
>
<
asp:TextBox ID
=
"
tb1
"
runat
=
"
server
"
></
asp:TextBox
><
br
/>
<
input
id
=
"
comit
"
type
=
"
button
"
value
=
"
Ok
"
onclick
=
"
return comit_onclick()
"
/>
<
br
/><
asp:TextBox ID
=
"
tb
"
runat
=
"
server
"
></
asp:TextBox
>
</
div
>
</
form
>
</
body
>
</
html
>
注意:这里值得注意的地方是
_Default.SetTb(name,callback);这句话是为了调用_Default.aspx.cs后台代码中SetTb这个方法的,如果
这个方法没有要传递的参数则指明返回的处理方法是哪一个就OK了,写成_Default.SetTb(callback);
相关文章推荐
- AjaxPro.2.dll在VS2005使用中的基本使用
- AjaxPro.2.dll在VS2005使用中的基本使用
- AjaxPro.2.dll在VS2005使用中的基本使用
- AjaxPro.2.dll在VS2005使用中的基本使用
- AjaxPro.2.dll在VS2005使用中的基本使用
- AjaxPro.2.dll基本使用(转载)
- AJAX在VS2005下的基本使用第一篇
- AjaxPro.2.dll基本使用
- AjaxPro.2.dll在VS2005使用中的基本使用 (转)
- AjaxPro.2.dll基本使用(转载)
- AjaxPro.2.dll基本使用
- AjaxPro.2.dll基本使用
- AjaxPro.2.dll基本使用
- AjaxPro.2.dll基本使用
- (转)AjaxPro.2.dll基本使用
- AJAX在VS2005中的简单应用 使用ajaxpro.2.dll[点击按钮执行事件不刷新]
- AjaxPro.2.dll在VS2005使用中的基本使用
- AjaxPro.2.dll在VS2005使用中的基本使用
- [导入]AjaxPro.2.dll在VS2005使用中的基本使用
- 有关VS2005使用的一些基本问题.