为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕莱坞森 2018-12-07 07:43:51
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次,找了好长时间,未能找到原因。高手给回应吧!
查看完整描述

1 回答

?
小怪兽爱吃肉

TA贡献1852条经验 获得超1个赞

Page_Load事件改为:

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

试试

查看完整回答
反对 回复 2019-01-21
  • 1 回答
  • 0 关注
  • 232 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信