下面是我看的例子的一段脚本.但是不知道为什么参数"state"在webform6中始终是空值"",
请各位大侠帮我分析下<script>

  function load(state){ 
  //alert(state);在这里是有值的.
  var drp2 = document.getElementById("DropDownList2");
  for(var i = 0;i<=drp2.options.length -1;i++){
  drp2.remove(i);
  }
  var oHttpReq = new ActiveXObject("MSXML2.XMLHTTP");
  var oDoc = new ActiveXObject("MSXML2.DOMDocument");
  oHttpReq.open("POST", "webform6.aspx?state="+state, false);
  oHttpReq.send("");
   result = oHttpReq.responseText;
   //document.write(result);
  oDoc.loadXML(result);
  items = oDoc.selectNodes("//CITY/Table");
  for (var item = items.nextNode(); item; item = items.nextNode())
  {
   var city = item.selectSingleNode("city").nodeTypedValue;
   var newOption = document.createElement("OPTION");  
   newOption.text = city;
   newOption.value = city;
   drp2.options.add(newOption);
  
  }
  }
</script>

解决方案 »

  1.   

    脚本的代码没有错误,看看你的page_load事件的代码是否正确,或者你贴出来
      

  2.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!this.IsPostBack)
    {
       SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["strconn"]);
       SqlDataAdapter da = new SqlDataAdapter("select Address_province from DataBook_Address group by Address_province",con);
       DataSet ds = new DataSet();
    da.Fill(ds,"TableBind");
    this.DropDownList1.DataSource=ds.Tables["TableBind"];
       this.DropDownList1.DataTextField = "Address_province";
       this.DropDownList1.DataValueField = "Address_province";
       this.DropDownList1.DataBind();
       this.DropDownList1.Attributes.Add("onchange","load(this.options[this.selectedIndex].innerText)");
    }webform6.cs page_load
    if(this.Request.QueryString["state"]!=null)
    {//**state始终是""
                      string state = Request.QueryString["state"];
       SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["strconn"]);
       SqlDataAdapter da = new SqlDataAdapter("select city from DataBook_Address where Address_province = '"+state+"'",con);
       DataSet ds = new DataSet("CITY");
       da.Fill(ds);
       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();

    } }
      

  3.   

    webform6.cs page_load的问题。
    Response.End(); 可能会引发异常。这样导致javascript里面的,取道的result为空。看看 function load(state){ }
    里面 result = oHttpReq.responseText;,看看result有没有值
      

  4.   

    多谢关注,并不是webform6的问题.因为如果把设置state为常量
    则result可以正常返回.
    现在的问题主要是state参数传递到webform6中始终为空.
    帮忙分析下参数不能正常传递的原因
      

  5.   

    这样试试看。看看参数state 前后是否有空格,把它trim一下。
    oHttpReq.open("POST", "webform6.aspx?state="+state, false);
    把那个 url--"webform6.aspx?state="+state 
    alert出来看看,是否正确。
      

  6.   

    web.config里面 requestEncoding="gb2312" 
                responseEncoding="gb2312"改成这样
      

  7.   

    oHttpReq.open("POST", "webform6.aspx?state="+state, false);
    改成
    oHttpReq.open("POST", "webform6.aspx?state="+escape(state), false);  
      

  8.   

    多谢babyfishlh(babyfishlh) ,终于解决了
    lr2651的方法不行,参数传递虽然正常,但是返回值确出问题
      

  9.   

    lr2651的方法也可以,你把
     XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Response.ContentEncoding);
    改成utf-8
      

  10.   

    楼主:
       你是说state这个参数webform6.aspx根本接收不到?