Dot Net Ajax2使用方法

  1、將ajax.dll復製到網站的bin目錄

2、Web.Config文件配置如下:
<?xml version="1.0"?>
<configuration>
<appSettings>
  <add key="ConnectionString" value="Data Source=localhost;user id=sa;password=xxx;initial catalog=db1"/>
</appSettings>
<system.web>
    ......
  <customErrors mode="RemoteOnly"/>
  <!--用于配置登陸,驗證身份後轉向:FormsAuthentication.RedirectFromLoginPage(Login1.UserName, false);
      驗證身份後設置票證:FormsAuthentication.SetAuthCookie(Login1.UserName,false);
                //FormsAuthentication.SignOut();
                //取得身份驗證票證用戶可用Page.User.Identity.Name属性
                //Server.Transfer(strGoto);
                Response.Redirect(strGoto);
                //Response.Write("<script>window.location.href='" + strGoto + "';</script>");
  -->
  <authentication mode="Forms">
      <forms loginUrl="Login.aspx"/>
  </authentication>
  <authorization>
      <deny users="?"/>
  </authorization>
  <!--用于配置ajax-->
  <httpHandlers>
   <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
  </httpHandlers>

  <system.web>
</configuration>

3、Default.aspx
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<head runat="server">
    <title>无标题页</title>
    <script type="text/javascript">
       function send()
       {
           main.innerHTML=document.all("input1").value + _Default.GetMsg().value ;
       }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <input id="input1" type="text" οnkeydοwn="if (event.keyCode == 13) {send();return false;}" />
    <input id="btn1" type="button" value="send" οnclick="send();" />
    

    

    <span id="main"></span>
    </div>
    </form>
</body>
</html>

4、Default.aspx.cs
using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
         Ajax.Utility.RegisterTypeForAjax(typeof(_Default));
    }
    [Ajax.AjaxMethod()]
    public string GetMsg()
    {
        //讀數據庫代碼或其他,在這里僅測試

        string str1 = "Welcome to here";
        return str1;
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值