[英]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.