首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

菜鸟有关问题帮忙看看啊分不够再加.

2012-03-11 
初学者问题帮忙看看啊,急!!!!!!!!!!!!!!!!!!!!!!!分不够再加.我创建了两个用户控件Top5BuildingsSaleAndHi

初学者问题帮忙看看啊,急!!!!!!!!!!!!!!!!!!!!!!!分不够再加.
我创建了两个用户控件Top5BuildingsSaleAndHire和Top5BuildingsBuyAndForHouse
用户控件Top5BuildingsSaleAndHire的作用是在页面首次加载的时候调用javascript中的Building2GetHouse函数的把出售的房屋信息加载到前台中.并根据用户通过选择出售和出租[color=#FF0000][/color]的两个链接来动态在数据库中调出关于房屋出售和出租的信息并显示在页面上.
前台代码为: 
 <script type="text/javascript" >
  var xmlHttp;
  function Building2createXMLHttpRequest() 
  {
  if (window.ActiveXObject) 
  {
  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  else if (window.XMLHttpRequest) 
  {
  xmlHttp = new XMLHttpRequest();
  }
  }  
  function Building2GetHouse(obj) 
  { 
  var ProvinceID=obj.id 
  //alert(obj.id);
  Building2createXMLHttpRequest(); 
  xmlHttp.onreadystatechange = Building2handleStateChange; 
  xmlHttp.open("GET", "?TradeModleID="+obj.id, true); 
  xmlHttp.send(null); 
  }  
  function Building2FirsLoad(obj) 
  {  
  Building2createXMLHttpRequest(); 
  xmlHttp.onreadystatechange = Building2handleStateChange; 
  xmlHttp.open("GET", "?TradeModleID="+obj, true); 
  xmlHttp.send(null); 
  }  
  function Building2handleStateChange() 
  {
  if(xmlHttp.readyState == 4) //0(未初始化);1(正在装载);2 (装载完毕);3 (交互中);4 (完成) 
  {
  if(xmlHttp.status == 200) //200(OK);404(not found)
  {
  document.getElementById("BuildingsSaleAndHire").innerHTML=xmlHttp.responseText;
  }
  }
  }
 </script>  
  <div class="div"> 楼房 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;     &nbsp;
  &nbsp; &nbsp; &nbsp;&nbsp; <a id="1" href="#" onclick="Building2GetHouse(this)">出售</a>
  <a id="2" href="#" onclick="Building2GetHouse(this)">出租</a>
  <a id="3" href="../CompanySite/MoreBuildingsSaleAndHire.aspx" class="more">更多..</a>
  </div>  
  <div id ="BuildingsSaleAndHire">
  &nbsp;</div>
后台代码为:
  public partial class SaleAndHire : System.Web.UI.UserControl
 {
  protected void Page_Load(object sender, EventArgs e)
  {
  if (!Page.IsPostBack)
  {
  this.Parent.Page.ClientScript.RegisterStartupScript(this.GetType(),                           "abc", "Building2FirsLoad(1);", true);//调用前台的javascript中的Building2FirsLoad函数来为页面首次加载时调出数据.
  if (TradeModleID != "")
  {
  GetHouseInfoByTradeModleID(TradeModleID);
  }
  }
  }
  #region property
  private string TradeModleID
  {
  get
  {
  if (Request["TradeModleID"] != null && Request["TradeModleID"].ToString() != "")
  {


  return Request["TradeModleID"];
  }
  else
  {
  return "";
  }
  }
  }
  #endregion 
  #region GetHouseInfoByTradeModleID
  private void GetHouseInfoByTradeModleID(string TradeModleID)
  {  
  HouseManger.HouseDB SaleAndHireHouseInfo = new HouseManger.HouseDB();
  SqlDataReader dr = SaleAndHireHouseInfo.GetSingleHouseInfo1(TradeModleID, "1");
  string s = @"<table cellspacing='0' cellpadding='4' border='0' id='GridView1' style='color:#333333;border-collapse:collapse;'>";
  s += "<tr style='color:black;background-color:White;'>";
  s += "<th scope='col' style=' font-size:14px;'>意向</th><th scope='col' style=' font-size:14px;'>面积</th><th scope='col' style=' font-size:14px;'>新旧</th><th scope='col' style=' font-size:14px;'>价格</th><th scope='col' style=' font-size:14px;'>电话</th><th scope='col'></th></tr>";
  int m = 0;
  while (dr.Read())
  {
  if (m % 2 == 0)
  {
  s += "<tr style='color:#333333;background-color:#EFF3FB;'>";
  }
  else
  {
  s += "<tr style='color:#333333;background-color:White;'>";
  }
  m++;
  s += "<td style=' font-size:13px;'>" + dr["TradeName"] + "</td>";
  s += "<td style=' font-size:13px;'>" + dr["HouseareaName"] + "</td>";
  s += "<td style=' font-size:13px;'>" + dr["Neworold"] + "</td>";
  s += "<td style=' font-size:13px;'>" + dr["SalePriceName"] + "</td>";
  s += "<td style=' font-size:13px;'>" + dr["Telephone"] + "</td>";
  s += "<td style=' font-size:14px;'><a style='background-color:#FF8000; color:white' href='HouseDetail.aspx?HouseID=" + dr["ID"] + "'>详细信息</a></td>";
  s += "</tr>";
  }
  s += "</table>";
  dr.Close();
  //conn.Close();
  this.Response.Write(s);
  this.Response.End();  
  }
  #endregion
}
用户控件Top5BuildingsBuyAndForHouse的功能和上面的很相似就是调出求购和求租的信息
前台代码为:
<script type="text/javascript">
 var xmlHttp;
  function Building1createXMLHttpRequest() 
  {
  if (window.ActiveXObject) 
  {
  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  else if (window.XMLHttpRequest) 
  {
  xmlHttp = new XMLHttpRequest();
  }
  } 
  function Building1GetHouse(obj) 
  { 
  var ProvinceID=obj.id 
  //alert(obj.id);
  Building1createXMLHttpRequest(); 
  xmlHttp.onreadystatechange = Building1handleStateChange; 
  xmlHttp.open("GET", "?TradeModleID="+obj.id, true); 
  xmlHttp.send(null); 


  }  
  function Building1FirsLoad(obj) 
  {  
  //alert("abc");  
  Building1createXMLHttpRequest(); 
  xmlHttp.onreadystatechange = Building1handleStateChange; 
  xmlHttp.open("GET", "?TradeModleID="+obj, true); 
  xmlHttp.send(null); 
  }  
  function Building1handleStateChange() 
  {
  if(xmlHttp.readyState == 4) //0(未初始化);1(正在装载);2 (装载完毕);3 (交互中);4 (完成) 
  {
  if(xmlHttp.status == 200) //200(OK);404(not found)
  {
  document.getElementById("BuildingsBuyAndForHire").innerHTML=xmlHttp.responseText;
  }
  }
  }
  </script>
  <div class="div"> 楼房 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
  &nbsp; &nbsp; &nbsp;&nbsp; <a id="5" href="#" onclick="Building1GetHouse(this)">求购</a>
  <a id="6" href="#" onclick="Building1GetHouse(this)">求租</a>
  <a id="3" href="../CompanySite/MoreBuildingsBuyAndForHose.aspx" class="more">更多..</a> 
  </div>
  <div id ="BuildingsBuyAndForHire">
  &nbsp;</div>
  后台代码为:
  public partial class UserControl_Top5BuildingsBuyAndForHouse : System.Web.UI.UserControl
{
  protected void Page_Load(object sender, EventArgs e)
  {
  if (!Page.IsPostBack)
  {
  this.Parent.Page.ClientScript.RegisterStartupScript(this.GetType(), "abc", "Building1FirsLoad(5);", true);

  if (TradeModleID != "")
  {
  GetHouseInfoByTradeModleID(TradeModleID);
  }
  }
  }
............同上字太多了哦...............
 }
现在的主要问题是如果把这两个用户控件同时放到一个页面上,只有后面的那个用户控件在页面第一次加载时会有数据显示,而第一个用户控件没有加载数据.如在Default.aspx页面先加入Top5BuildingsSaleAndHire,再加入Top5BuildingsBuyAndForHouse,则只有Top5BuildingsBuyAndForHouse用户控件在Default.aspx页面首次加载时有数据显示.而Top5BuildingsSaleAndHire没有数据显示.把两个用户控件的顺序反过来,也只是最后加入的控件有数据显示.
当单独把它们中的任何一个放到一个页面上时都能够正确执行.  
本人是个初学者,想用异步刷新的方式来实现这个功能,如果大家有什么好的方法也可以说下.本人情愿把分都给他.

[解决办法]
this.Parent.Page.ClientScript.RegisterStartupScript 只能注册一次 是不是两次注册的KEY一样 代码太长了···
[解决办法]
很简单,因为你给两个异步都设置了一同一个变量var xmlHttp; 
所以在两个用户控件运用在同一个页面时,第二个异步方法覆盖了第一个。
你只需要给两个异步设置不同的变量名就解决问题了

热点排行