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

  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次,找了好长时间,未能找到原因。高手给回应吧!

慕莱坞森
浏览 233回答 1
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("", "", "", "", "", ""); } } } 试试
打开App,查看更多内容
随时随地看视频慕课网APP