首页 新闻 会员 周边 捐助

后台代码绑定xml作为Repeater的数据源,Page_Load事件被执行2次!

0
悬赏园豆:10 [已解决问题] 解决于 2011-10-28 16:59
  protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Init("", "", "", "", "", "");
}

if (Request.QueryString["do"] != null && Request.QueryString["do"] == "list")
{
Init("", "", "", "", "", "");
}
}

///<summary>
/// 初始document
///</summary>
///<param name="outCity1">起飞城市(中文)</param>
///<param name="toCity1">到达城市(中文)</param>
///<param name="outCode1">起飞城市(Code)</param>
///<param name="toCode1">到达城市(Code)</param>
///<param name="outDate1">起飞日期</param>
///<param name="type1">航程类型</param>
private void Init(string outCity1, string toCity1, string outCode1, string toCode1, string outDate1, string type1)
{
//接收 往返、联程时 选择下一程 传递的参数
string outCity = outCity1;
string toCity = toCity1;
string outCode = outCode1;
string toCode = toCode1;
string outDate = outDate1;
string toDate = "";
string type = type1;

if (Request.QueryString["do"] == "list") //接收本页面 查询 按钮 传递的参数
{
outCity = Request.Form["seach_outCity"].ToString();
toCity = Request.Form["seach_toCtiy"].ToString();
outCode = Request.Form["seach_outCode"].ToString();
toCode = Request.Form["seach_toCode"].ToString();
outDate = Request.Form["seach_outDate"].ToString();
toDate = Request.Form["seach_toDate"].ToString();
type = Request.Form["seach_type"].ToString();
}
else if (outCity == "") //接收首页 查询 按钮 传递的参数
{
outCity = Request.QueryString["seach_outCity"].ToString();
toCity = Request.QueryString["seach_toCtiy"].ToString();
outCode = Request.QueryString["seach_outCode"].ToString();
toCode = Request.QueryString["seach_toCode"].ToString();
outDate = Request.QueryString["seach_outDate"].ToString();
toDate = Request.QueryString["seach_toDate"].ToString();
type = Request.QueryString["seach_type"].ToString();
}

//开始填充 document
this.lOutToCity.Text = outCity + " -- " + toCity;
this.lToOutCity.Text = outCity + " - " + toCity;
this.lOutDate.Text = Convert.ToDateTime(outDate).ToString("D");

//获取低价信息
DataTable dtPromotion = ssc.GetPromotionByCity(outCode, toCode, DateTime.Now.AddDays(1).ToString("d") + " 00:00:00", DateTime.Now.AddDays(9).ToString("d") + " 23:59:59");

this.Repeater1.DataSource = dtPromotion;
this.Repeater1.DataBind();
//获取航班信息
string xml = ssc.SeachToDayFlightInfo(outCode, toCode, Convert.ToDateTime(outDate), "0600");
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);

this.Repeater2.DataSource = doc.DocumentElement.ChildNodes;
this.Repeater2.DataBind();
this.hidNum.Value = (doc.DocumentElement.ChildNodes.Count + 10).ToString();

Session["mark"] = "0";
}

我后台用xml作为Repeater的数据源,可以每次Page_Load事件会被执行2次,找了好长时间,未能找到原因。高手给回应吧!

紫炁星的主页 紫炁星 | 初学一级 | 园豆:57
提问于:2011-10-20 08:45
< >
分享
最佳答案
0

Page_Load事件改为:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Init("", "", "", "", "", "");
}
else
{
if (Request.QueryString["do"] != null && Request.QueryString["do"] == "list")
{
Init("", "", "", "", "", "");
}
}
}

试试

收获园豆:10
artwl | 专家六级 |园豆:16736 | 2011-10-20 09:23

试了试!

IsPostBack 里面的 Init 方法还是被执行了2次!
紫炁星 | 园豆:57 (初学一级) | 2011-10-20 09:32

@紫炁星: 肯定是你其他地主代码的问题,这里不会执行多次的,你断点调试看一下吧

artwl | 园豆:16736 (专家六级) | 2011-10-20 09:37

@天行健 自强不息: 找到原因,但是不能理解为什么会这样,求解释。造成第二次加载load事件的语句是:

<img src="<%#((XmlNode)Container.DataItem).Attributes["Img"].Value %>" alt="" />

原因是,scr 不能正确连接到图像。可以,为什么会这样,我就不能理解了!

紫炁星 | 园豆:57 (初学一级) | 2011-10-20 10:49
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册