[英]Calling Static method on aspx page does not work?
我有一个名为MasterPage_MyMasterPage的母版页,我已经创建了一个静态方法
public static string GetRoleName()
{
string sRoleName="admin";
if (HttpContext.Current.Session["UserName"] != null)
{
sRoleName = HttpContext.Current.Session["UserName"].ToString();
}
return sRoleName;
}
在aspx页面上我称之为
<a >Brayan <asp:Label runat="server" Text='<%= MasterPage_MyMasterPage.GetRoleName() %>' ></asp:Label>
但它不起作用,它打印为...
Brayan <span><%= MasterPage_MyMasterPage.GetRoleName() ;></span>
成功登录后,Session [“ UserName”]已绑定。请帮助我。
嘿,请尝试对我有用
<a >Brayan <asp:Label runat="server" Text='' ><%= MasterPage_MyMasterPage.GetRoleName()%> </asp:Label>
尝试这个
<%= ((MasterPage_MyMasterPage)Page.Master).GetRoleName() %>
更新:
在您的cs文件中创建一个受保护的方法,如下所示
protected string getRoleName()
{
return ((MasterPage_MyMasterPage)Page.Master).GetRoleName();
}
并在aspx文件中
<%= getRoleName() %>
可以和这个一样吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.