我有一些代码如下:
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;
}
}
}
如果在lblTypeOfSearch
不为空时附加了一些文字,我想在Page_Load
中显示此typeOfSearch
。如果我检查lblTypeOfSearch
中的值Page_Load
,它在那里显示为null。如何在那里使用这个变量来显示?
答案 0 :(得分:0)
正如我所看到的,您的代码必须正常工作,可能会看到缓存结果,在这种情况下,您可以按ctrl + F5键查看新代码结果。 如果你想在按钮点击和表单加载中访问你的文本,你可以将你的字符串变量声明为全局(在这些方法中)。
答案 1 :(得分:0)
每次用户点击某些内容并且未在客户端处理时,都会向服务器发送请求,并返回一个新页面及其新实例化的代码隐藏。因此,如果你想在回发期间保留数据,返回到页面等,你需要先将它存储在某个地方(session,db,等等......)然后你可以在Page_Load中访问它。
请记住,网站是无国籍的。