母版页与非母版页之间的关系

时间:2017-08-20 07:11:18

标签: c# asp.net webforms

有一个页面Login.aspx,其Label控件为“Lbl_LoginExpired”。 还有一个MasterPage。 我想从母版页中更改“Lbl_LoginExpired”的文本。 我怎样才能做到这一点?

  

注意:   1)Login.aspx不是内容页面。

     

2)Label label1=new (Label)Login.FndControl("Lbl_LoginExpired")         不适用于MasterPage。

1 个答案:

答案 0 :(得分:1)

如果这两个页面之间没有母版页内容关系。我认为您的选择有限。此外,我假设Lbl_LoginExpired不是您可以在两个页面中注册的用户控件的一部分。我建议使用Session对象在这两个页面之间传递此信息。

因此在您的母版页

 Session["expiredtext"] = "Your login has been expired";

在您的登录pag中检查此会话值是否为null并显示其内容。

Lbl_LoginExpired.Text=Session["expiredtext"]?.ToString();

另外不要忘记重置(或在用户注销时忽略会话)