【问题标题】:Why form does not load the second time i visit the user control为什么我第二次访问用户控件时表单不加载
【发布时间】:2012-04-10 06:10:10
【问题描述】:

我有一个表单,我在表单中添加和删除用户控件,具体取决于所选内容。有一个表单有两个标签,标签信息应该在用户控件加载时改变,但它永远不会改变,它保持相同的值。现在,我在加载用户控件时添加了一个断点。它只被点击一次,其他时候它只是导航到那里,但再也不会加载了。。

private void SummaryScreen_OnLoad(object sender, EventArgs e)
{
    lblSavingsBalance.Text = Global.Instance.Accounts[1].AccountBalace.ToString();
    lblCheckingBalance.Text = Global.Instance.Accounts[0].AccountBalace.ToString();
}

我怎样才能让它在我调用这个用户控件时一直加载?

【问题讨论】:

  • 您在谈论 UserControl 的 OnLoad? (UserControl 叫 SummaryScreen?)
  • 是的,用户控件被称为 SummaryScreen - 是的 SummaryScreen 的 onload 它只被点击一次

标签: c# winforms user-controls


【解决方案1】:

UserControl.Load 仅在构造后第一次添加到表单时调用。

您需要:

  • 每次都重新创建控件(因此强制调用 Load)
  • 在UserControl上添加一个新方法(如Initialize)并在添加后调用它

【讨论】:

    【解决方案2】:

    可能是缓存 使用:-

     Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ExpiresAbsolute = DateTime.Now.AddMonths(-1); 
    

    在你的加载函数中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-13
      • 1970-01-01
      相关资源
      最近更新 更多