以前经常看见asp的例子代码,没看见谁放个asp.net的,为了给新手点帮助,顺序贴上来。<%@ Page language="c#" AutoEventWireup="false" Inherits="asp_test.WebForm1" %>
<HTML>
 <body MS_POSITIONING="GridLayout">
  <script language="javascript">
  function Go()
  {
   //新建ActiveXObject
   var htp =new ActiveXObject("microsoft.xmlhttp");
   
   //发送并接受数据
   htp.open("POST","webform1.aspx?abc="+Form1.text1.value,false);
   htp.send();
   
   //send()返回就说明数据已传完。因为open()的第三个参数是决定是否异步。
   //显示
   alert(htp.responsetext);
  }
  </script>
  <%
   if (Request.QueryString["abc"] != null)
   {
    //清空Response对象,如果是在Page_Load事件中可以省略这步。
    Response.Clear();    //写回数据----在这里是计算传过来的计算机的长度。
    Response.Write(Request.QueryString["abc"].Length.ToString());
    
    //完成并马上关闭。以免传入多余的数据。
    Response.Flush();
    Response.Close();
   }
  %>
  <form id="Form1" method="post" runat="server">
   <INPUT style="Z-INDEX: 101; LEFT: 328px; POSITION: absolute; TOP: 208px" type="button"
    value="下载显示" onclick="Go()">
   <INPUT style="Z-INDEX: 102; LEFT: 280px; POSITION: absolute; TOP: 152px" type="text" name="text1">
  </form>
 </body>
</HTML>
[共享3]编码问题:
http://community.csdn.net/Expert/topic/4002/4002354.xml[共享2]参数传递:
http://community.csdn.net/Expert/topic/3999/3999829.xml[共享1]try,catch中的return:
http://community.csdn.net/Expert/topic/3990/3990402.xml

解决方案 »

  1.   

    我也共享一个无刷新的联动(xmlhttp)
    <HTML>
    <HEAD>
    <title>WebForm2</title>
    </HEAD>
    <BODY>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    <script>
     
      function load(TypeId)
      {
      //alert(TypeId);
       var drp2 = document.getElementById("DropDownList2");
       for(var i = 0;i<=drp2.options.length -1;i++)
       {
       drp2.remove(i);
       }
       var dt = new Date();   var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
       //var oHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
       var oDoc = new ActiveXObject("MSXML2.DOMDocument");
       oHttpReq.open("POST", "data.aspx?TypeId="+TypeId+"&temp=" + dt.getTime(), false);
       oHttpReq.send("");
       result = oHttpReq.responseText;
       oDoc.loadXML(result);
       items = oDoc.selectNodes("//NewDataSet/Class");
       for (var item = items.nextNode(); item; item = items.nextNode())
       {
       var cid = item.selectSingleNode("Classid").nodeTypedValue;
       var cname = item.selectSingleNode("ClassName").nodeTypedValue;
      
       //document.getElementById('dropdownlist').value
      
       var newOption = document.createElement("OPTION");
       newOption.text = cname;
       newOption.value = cid;
       drp2.options.add(newOption);
       }
      }
    </script>
    <form id="Form1" method="post" runat="server">
    <asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
    <asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList><BR>
    </form>
    </BODY>
    </HTML>private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!this.IsPostBack)
    {
    SqlConnection Conn = new SqlConnection();
    Conn.ConnectionString = ConfigurationSettings.AppSettings["conn"].ToString();
    Conn.Open();
    string strSql = "select  * from Type_Info ";
    DataSet ds = new DataSet();
    SqlDataAdapter Adp = new SqlDataAdapter(strSql,Conn); 
    Adp.Fill(ds,"TypeIdList");
    DropDownList1.DataSource = ds.Tables["TypeIdList"].DefaultView;
    DropDownList1.DataTextField = "typename";
    DropDownList1.DataValueField = "typeid";
    DropDownList1.DataBind();
    ListItem pitme=new ListItem("选择类别","0");
    DropDownList1.Items.Insert(0,pitme);
    DropDownList2.Items.Insert(0,pitme);
    //this.DropDownList1.Attributes.Add("onchange","load(this.options[this.selectedIndex].innerText)");
    this.DropDownList1.Attributes.Add("onchange","load(this.value)");
       }
    }
      

  2.   

    data.aspx后台private void Page_Load(object sender, System.EventArgs e)
    {
    if(this.Request["TypeId"]!=null)
     {
       string TypeId = this.Request["TypeId"].ToString();  SqlConnection Conn = new SqlConnection();  Conn.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["conn"].ToString();
     Conn.Open();  string strSql = "select  * from class_Info where typeid="+ TypeId ;

     DataSet ds = new DataSet();  SqlDataAdapter Adp = new SqlDataAdapter(strSql,Conn);   Adp.Fill(ds,"Class");  XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Response.ContentEncoding);   writer.Formatting = Formatting.Indented;
       writer.Indentation = 4;
       writer.IndentChar = ' ';
       ds.WriteXml(writer);
       writer.Flush();
       Response.End();
       writer.Close();
       }
    }