如何在浏览日历时让 Table 在 ASP.NET 中可见

How do you keep a Table Visible in ASP.NET while browsing a Calendar

我在我们的 ASP.NET 网站上工作时遇到问题:

我有一个 table 隐藏,直到单击指定的按钮。单击该按钮后,table - 及其内容 - 将在该点上可见。 table 的内容之一是日历。问题是这样的——每当我在日历中切换年份时,table 就会回到其隐藏状态。

我认出了这个因为我把 table_Name.visible = false; 属性 放在了 Page_load

protected void Page_Load(object sender, EventArgs e)
{
   my_Table_name.Visible = false;
}

我尝试修复它,所以我的第一个解决方案是:

int counter = 0;
protected void Page_Load(object sender, EventArgs e)
{
    if (counter == 0)
    {
        additional_Tabe.Visible = false;
        counter += 1;
    }
}

我的解决方案无效。

我的第二个和第三个解决方案的问题是我必须用我的任一解决方案替换我的组员放置的所有日历,这几乎是一项乏味但可行的任务。

我只是想知道是否有办法防止 table 在用户切换日历年份、select 日期或通常播放时返回其隐藏状态围绕着日历。

 int counter = 0;
protected void Page_Load(object sender, EventArgs e)
{
      if(!PostBack)
      {

              if (counter == 0)
              {
                   additional_Tabe.Visible = false;
                   counter += 1;

              }
       }

}

使用此代码...

使用 Page.IsPostBack 属性 inside Page_Load, https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.page.ispostback?view=netframework-4.8 it returns true if: the page is being loaded in response to a client postback; otherwise, false. 你可以将你的 my_Table_name.Visible = false; 包装在这个条件中并且只设置如果是回发,则为 false

代码:

protected void Page_Load(object sender, EventArgs e)
{
    if(IsPostBack)
       my_Table_name.Visible = false;
}