2014-07-23 15 views
0

大家好,所以我有一個問題,並知道有人在這裏可以幫助我,因爲我無法弄清楚這一點。如何在第一次回發後更新主頁上的TextBox?

我有一個母版頁,其中包含一個div,其中包含用於客戶端的$和時間總計的文本框,因爲它們在內容頁面中選擇服務。

我遇到的問題是,當選擇服務時,第一個回發不會在母版頁中顯示更新的div總數。第二次回發後,第一次選擇的結果將顯示出來。

據我所知,這是因爲直到頁面加載後回發才被處理。但我不知道如何解決這個問題。我嘗試調用母版頁的方法來處理內容頁的init方法中的總計更新,但是當我這樣做時,母版頁的文本框爲空。

這裏是我的代碼背後的母版頁:

namespace Teres.App 
{ 
    public partial class App : System.Web.UI.MasterPage 
    { 
     Teres.Controllers.Math M; 



     protected void Page_Load(object sender, EventArgs e) 
     { 


      TextBox1.Text = "customized for: " + HttpContext.Current.Session["UserName"].ToString(); 
      TextBox2.Text = "member: " + HttpContext.Current.Session["IsMember"].ToString(); 
      TextBox3.Text = "membership info: " + HttpContext.Current.Session["MoreInfo"].ToString(); 

      //need to create dynamic textboxes for service events 
      //will call method from Tab class 
      if (IsPostBack) 
      { 
       TabMath(); 
      } 


     } 

     public void UpdateBar (string service) 
     { 
      //TextBox TextBox = new TextBox(); 


     } 

     public void TabMath() 
     { 
      M = new Teres.Controllers.Math(); 
      string dollarTotal = Convert.ToString(M.GetDollarTotal()); 
      TextBox29.Text = "total: $" + dollarTotal; 

      string minuteTotal = Convert.ToString(M.GetMinuteTotal()); 
      TextBox30.Text = "time: " + minuteTotal + " minutes"; 
     } 


    } 
} 

,這裏是我的內容頁面的代碼隱藏

namespace Teres.App 
{ 
    public partial class Services : System.Web.UI.Page 
    { 
     Teres.Controllers.Services S; 
     Teres.Controllers.Math M; 

     protected void Page_PreInit(object sender, EventArgs e) 
     { 


     } 

     protected void Page_Init(object sender, EventArgs e) 
     { 


     } 

     protected void Page_Load(object sender, EventArgs e) 
     { 




     } 


     protected void CheckBox1_CheckedChanged(object sender, EventArgs e) 
     { 
      S = new Teres.Controllers.Services(); 
      M = new Teres.Controllers.Math(); 

      if(CheckBox1.Checked) 
      { 
       TextBox1.Text = S.GetHandDescription("manicure"); 
       TextBox2.Text = Convert.ToString(S.GetHandTimes("manicure")); 
       TextBox3.Text = Convert.ToString(S.GetHandPrices("manicure")); 

       M.UpdateMinuteTotal(S.GetHandTimes("manicure")); 
       M.UpdateDollarTotal(S.GetHandPrices("manicure")); 

       //Teres.App.App.UpdateBar("manicure"); 
      } 

      else 
      { 
       TextBox1.Text = ""; 
       TextBox2.Text = ""; 
       TextBox3.Text = ""; 

       M.SubtractMinuteTotal(S.GetHandTimes("manicure")); 
       M.SubtractDollarTotal(S.GetHandPrices("manicure")); 

       //Teres.App.App.UpdateBar("manicure"); 
      } 
     } 

我怎麼能選擇讓回傳節目後立即更新textbox29和textbox30立即在母版頁上?

謝謝!

回答

0

好的,所以我想通了,我想我會張貼像我一樣的新手尋找解決這個問題。

我瞭解到預渲染階段允許您在渲染之前更新頁面上的控件,但此階段是在處理回發之後。

protected void Page_PreRender(object sender, EventArgs e) 
     { 
      if (IsPostBack) 
      { 
       TabMath(); 
      } 
     } 

這可以讓總數在每次回傳後顯示正確的版本。

希望它可以幫助別人。

相關問題