Asp.net 第一次回发后如何更新母版页上的文本框?

Asp.net 第一次回发后如何更新母版页上的文本框?,asp.net,master-pages,postback,pageload,Asp.net,Master Pages,Postback,Pageload,大家好,所以我有点问题,我知道这里有人可以帮助我,因为我无法解决这个问题 我有一个母版页,其中包含一个div,其中包含一个文本框,当客户在内容页中选择服务时,其中包含$和时间总计 我遇到的问题是,当选择服务时,第一次回发不会在母版页中的div上显示更新的总计。在第二次回发时,将显示第一次选择的结果 我理解这是因为回发直到页面加载之后才被处理。但我不知道如何解决这个问题。我试图调用母版页的方法,该方法处理内容页的init方法中的总计更新,但当我这样做时,母版页的文本框为空 以下是我的母版页代码:

大家好,所以我有点问题,我知道这里有人可以帮助我,因为我无法解决这个问题

我有一个母版页,其中包含一个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,以便回发立即显示在母版页上


谢谢

好的,所以我刚刚想好了,我想我会为像我这样的新手们发帖,希望他们能解决这个问题

我了解到,prerender阶段允许您在页面呈现之前更新页面上的控件,但此阶段是在处理回发之后

 protected void Page_PreRender(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                TabMath();
            }
        }
这样,每次回发后,total都可以显示正确的版本

希望它也能帮助其他人