标签在页面中的可见性/不可见性.cs

本文关键字:可见性 cs 标签 | 更新日期: 2023-09-27 18:21:04

我有一些代码如下:

if {
  this.showhide.ImageUrl = "../common/images/hide-icon.png";
  this.showhide.AlternateText = "Hide SearchBar";
  this.searchBar.Visible = false;
  Session["showHideImage"] = "hide";
  ScreenProjectSearch ProjSearch = CurrentProjectSearch;
  lblTypeOfSearch.Text = "Search results are based on";
  string typeOfSearch = string.Empty;
  if (CurrentProjectSearch != null)
  {
    //lblTypeOfSearch.Text = "Search results are based on";
    if (CurrentProjectSearch.IsFileName)
      typeOfSearch += " Filename " + ProjSearch.TextSearch.Trim();
    if (CurrentProjectSearch.IsDescription)
      typeOfSearch += " Description " + ProjSearch.TextSearch.Trim();
    if (CurrentProjectSearch.IsPartNumber)
      typeOfSearch += " PartNumber " + ProjSearch.TextSearch.Trim();
    if (CurrentProjectSearch.IsState)
    {
      if (CurrentProjectSearch.IsDevelopment)
        typeOfSearch += " Development State ";
      if (CurrentProjectSearch.IsValidation)
        typeOfSearch += " Validation State ";
      if (CurrentProjectSearch.IsValidationPendingApproval)
        typeOfSearch += " ValidationPendingApproval State ";
      if (CurrentProjectSearch.IsPilot)
        typeOfSearch += " Pilot State ";
      if (CurrentProjectSearch.IsFactory)
        typeOfSearch += " Factory State ";
      if (CurrentProjectSearch.IsCancel)
        typeOfSearch += " Cancel State ";
    }
    if (CurrentProjectSearch.IsDate)
      typeOfSearch += " Created Date From: " + ProjSearch.FromDate + " To: " + ProjSearch.ToDate;
    if (CurrentProjectSearch.IsPromoteDate)
      typeOfSearch += " Promoted Date From: " + ProjSearch.FromPromoteDate + " To: " + ProjSearch.ToPromoteDate;
    if (CurrentProjectSearch.IsCreatedBy)
      typeOfSearch += " Created By: " + ProjSearch.CreatedBy.ToString();
    if (CurrentProjectSearch.IsProjectIDs)
      typeOfSearch += " PrjoectIds: " + ProjSearch.ProjectIDs;
    if (CurrentProjectSearch.IsWorkFlow)
    {
      if (CurrentProjectSearch.IsMdiagsNormal)
        typeOfSearch += " WorkFlow: " + "Mdiags Normal";
      if (CurrentProjectSearch.IsMdiagsTestEngineer)
        typeOfSearch += " WorkFlow: " + "Mdiags TestEngineer";
    }
    if (!string.IsNullOrEmpty(typeOfSearch))
    {
      lblTypeOfSearch.Text += typeOfSearch;
      lblTypeOfSearch.Visible = true;
    }
  }
}

我想在Page_Load显示此lblTypeOfSearch,如果typeOfSearch不为空时附加了一些文本。如果我检查值 os lblTypeOfSearchPage_Load它在那里显示空。如何利用此变量进行显示?

标签在页面中的可见性/不可见性.cs

每次用户单击某些内容并且未在客户端处理时,都会有一个请求进入服务器,它会返回一个新页面及其新实例化的代码隐藏。因此,如果您想在回发期间保留数据,返回到页面等,则需要先将其存储在某个地方(会话,数据库等(,然后您可以在Page_Load中访问它。

请记住,网站是无状态的。

如我所见,您的代码必须正常工作,您可以看到缓存的结果,在这种情况下,您可以按 ctrl + F5 键查看您的新代码结果。如果您希望可以在按钮单击和表单加载中访问文本,则可以将字符串变量声明为全局变量(在这些方法中(。