2013-02-28 38 views
2

調試消息後,同樣是始終下面按下後下一個按鈕多次, 它可以從第1頁到第2頁,但不能去第3頁Session仍然編輯

終於讓我找到問題

Session["jobsearch"] = js; 

已經得救了,但下一次我找回這一點,如不保存之前

調試消息

before js.CurrentPageNo=1 
after js.CurrentPageNo=2 
js.StartIndex=13 
js.PageSize=24 
js.TotalPageFound=5 
js.CurrentPageNo=2 
rowPerPage=12 
before js.CurrentPageNo=1 
after js.CurrentPageNo=2 
js.StartIndex=13 
js.PageSize=24 
js.TotalPageFound=5 
js.CurrentPageNo=2 
rowPerPage=12 


js.StartIndex=13js.PageSize=24js.TotalPageFound=5js.CurrentPageNo=2rowPerPage=12 
js.StartIndex=13js.PageSize=24js.TotalPageFound=5js.CurrentPageNo=2rowPerPage=12 
js.StartIndex=13js.PageSize=24js.TotalPageFound=5js.CurrentPageNo=2rowPerPage=12 
js.StartIndex=13js.PageSize=24js.TotalPageFound=5js.CurrentPageNo=2rowPerPage=12 

下一個按鈕代碼

protected void btnNext_OnClick(object sender, EventArgs e) 
    { 
     if (Session["jobsearch"] != null) 
     { 
      JobSearch js = (JobSearch)Session["jobsearch"]; 
      js.CurrentPageNo++; 
      js.StartIndex = js.StartIndex + rowPerPage; 
      js.PageSize = js.PageSize + rowPerPage; 

      Session["jobsearch"] = js; 
      if (jobResultsTable.DocumentContent.Contains("Jobs In Engineering")) 
      { 
       Session["jobsearch2"] = "Jobs In Engineering"; 
      } 
      else 
      { 
       Session["jobsearch2"] = "Jobs In IT"; 
      } 

      System.IO.File.AppendAllText(@"D:\Debug.txt", "js.StartIndex=" + js.StartIndex); 
      System.IO.File.AppendAllText(@"D:\Debug.txt", "js.PageSize=" + js.PageSize); 
      System.IO.File.AppendAllText(@"D:\Debug.txt", "js.TotalPageFound=" + js.TotalPageFound); 
      System.IO.File.AppendAllText(@"D:\Debug.txt", "js.CurrentPageNo=" + js.CurrentPageNo); 
      System.IO.File.AppendAllText(@"D:\Debug.txt", "rowPerPage=" + rowPerPage); 

      GetJobSearchBOResult(js.StartIndex, js.PageSize, js.JobType, js.JobCountry, js.Keywords); 

      ShowButton(js.CurrentPageNo, js.TotalPageFound); 

      ltrPageInfo.Text = "Page " + js.CurrentPageNo + " of " + js.TotalPageFound.ToString() + "<br/> Total Record(s) Found: " + TotalJobFound; 
     } 
    } 

回答

2

我敢打賭,

(JobSearch)Session["jobsearch"]; 

正在每一個頁面加載或者復位在您的網頁加載事件處理程序或init事件處理程序。

請記住,這兩個事件在每次回傳時都會觸發。

你可能需要在加載/初始化處理,檢查if (!Page.IsPostBack){ /*Only Init jobsearch here */ }

我會設置一個斷點,無論你有重置或初始化會話變量的代碼,然後看看這些斷點被命中往往比你想象。

相關問題