第一次接触Ajxa,实现对比客户端控件和服务器控件的区别

时间:2022-08-11 08:37:09
<%@ 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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="Button1" style="width: 115px" type="button" value="button" />
    <script  language="javascript">
   
    var xmlhttp=false;
    function a()
    {
    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");使用ie6
      xmlhttp.onreadystatechange=ff;
      xmlhttp.open("get","http://localhost:15834/ajax/Default.aspx?a=a",true);
 
      xmlhttp.send("");
   
    }
    function ff()
    {
    if(xmlhttp.readyState==4)
    {
       alert(xmlhttp.responseText);
    }
    }
    </script>
        &nbsp;
        <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" /></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;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Request .QueryString ["a"]!=null )
        {
            SqlDataAdapter DA = new SqlDataAdapter("select * from news",@"Data Source=F3539F15DC0840A\SQLEXPRESS;Initial Catalog=shengya;Integrated Security=True");
            DataTable DT=new DataTable ();
            DA .Fill (DT);
            Response.ContentType = "text/xml";
            Response.Write("请求返回!"+DT .Rows .Count );
            Response.End();
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        SqlDataAdapter DA = new SqlDataAdapter("select * from news", @"Data Source=F3539F15DC0840A\SQLEXPRESS;Initial Catalog=shengya;Integrated Security=True");
        DataTable DT = new DataTable();
        DA.Fill(DT);
;
        Response.Write("<script>alert('请求返回!" + DT.Rows.Count+"')</script>");
     
    }
}

本文出自 “叶子文文” 博客,转载请与作者联系!