如何VS08中创建有ASP.NET AJAX-Enabled Web Site 模版?
1个回答
2013-11-11
展开全部
给你一个使用ajax的步骤参考一下吧:Ajax初步使用方法 Ajax定义为“Asynchronous JavaScript + XML”的简称,也就是异步的JavaScript和XML处理。从原理上看,主要是Ajax可以通过调用HttpRequest实现与服务器的异步通讯,并最终在网页中实现丰富友好的用户界面
Ajax使用初步,配置步骤
1.把Ajax.dll copy到应用系统bin目录下,然后在工程引用中引用Ajax.dll,如果没有的话可以下载/Files/singlepine/Ajax.rar
2.配置web.config,添加如下信息
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
</httpHandlers>3.假设应用系统叫Document,目录格式为Pages\AjaxTest
4.在Pages\AjaxTest下建立cs文件AjaxMethod.cs,添加如下方法
//[Ajax.AjaxMethod]
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
public static string GetNIVNumber(string str)
{
return str;
}5.在Pages\AjaxTest下建立页面AjaxForm.aspx
<HTML>
<HEAD>
<title>AjaxForm</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">
function testAjax()
{
var first=document.getElementById("txtfirst");
AjaxMethod.GetNIVNumber(first.value,callback_GetNIVNumber);
}
function callback_GetNIVNumber(res)
{
var obj=document.getElementById("txtsecond");
obj.value=res.value;
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT style="Z-INDEX: 101; LEFT: 208px; POSITION: absolute; TOP: 40px" type="button" value="Button"
onclick="testAjax();">
<asp:TextBox id="txtfirst" style="Z-INDEX: 102; LEFT: 40px; POSITION: absolute; TOP: 40px" runat="server"></asp:TextBox>
<asp:TextBox id="txtsecond" style="Z-INDEX: 103; LEFT: 40px; POSITION: absolute; TOP: 72px" runat="server"></asp:TextBox>
</form>
</body>
</HTML>protected System.Web.UI.WebControls.TextBox txtfirst;
protected System.Web.UI.WebControls.TextBox txtsecond;
private void Page_Load(object sender, System.EventArgs e)
{
//注册,其中Document.Pages.AjaxTest.AjaxMethod为AjaxMethod.cs方法所在的命名空间
Ajax.Utility.RegisterTypeForAjax(typeof(Document.Pages.AjaxTest.AjaxMethod));
}然后运行就可以了,
Ajax使用初步,配置步骤
1.把Ajax.dll copy到应用系统bin目录下,然后在工程引用中引用Ajax.dll,如果没有的话可以下载/Files/singlepine/Ajax.rar
2.配置web.config,添加如下信息
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
</httpHandlers>3.假设应用系统叫Document,目录格式为Pages\AjaxTest
4.在Pages\AjaxTest下建立cs文件AjaxMethod.cs,添加如下方法
//[Ajax.AjaxMethod]
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
public static string GetNIVNumber(string str)
{
return str;
}5.在Pages\AjaxTest下建立页面AjaxForm.aspx
<HTML>
<HEAD>
<title>AjaxForm</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">
function testAjax()
{
var first=document.getElementById("txtfirst");
AjaxMethod.GetNIVNumber(first.value,callback_GetNIVNumber);
}
function callback_GetNIVNumber(res)
{
var obj=document.getElementById("txtsecond");
obj.value=res.value;
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT style="Z-INDEX: 101; LEFT: 208px; POSITION: absolute; TOP: 40px" type="button" value="Button"
onclick="testAjax();">
<asp:TextBox id="txtfirst" style="Z-INDEX: 102; LEFT: 40px; POSITION: absolute; TOP: 40px" runat="server"></asp:TextBox>
<asp:TextBox id="txtsecond" style="Z-INDEX: 103; LEFT: 40px; POSITION: absolute; TOP: 72px" runat="server"></asp:TextBox>
</form>
</body>
</HTML>protected System.Web.UI.WebControls.TextBox txtfirst;
protected System.Web.UI.WebControls.TextBox txtsecond;
private void Page_Load(object sender, System.EventArgs e)
{
//注册,其中Document.Pages.AjaxTest.AjaxMethod为AjaxMethod.cs方法所在的命名空间
Ajax.Utility.RegisterTypeForAjax(typeof(Document.Pages.AjaxTest.AjaxMethod));
}然后运行就可以了,
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询