I have a master page named MasterPage_MyMasterPage on whic i have created a static method as
public static string GetRoleName()
{
string sRoleName="admin";
if (HttpContext.Current.Session["UserName"] != null)
{
sRoleName = HttpContext.Current.Session["UserName"].ToString();
}
return sRoleName;
}
and on aspx page i called it as
<a >Brayan <asp:Label runat="server" Text='<%= MasterPage_MyMasterPage.GetRoleName() %>' ></asp:Label>
but it doesn't worked, it print as ...
Brayan <span><%= MasterPage_MyMasterPage.GetRoleName() ;></span>
Session["UserName"] is bind when login successfull.Please help me.
嘿,请尝试对我有用
<a >Brayan <asp:Label runat="server" Text='' ><%= MasterPage_MyMasterPage.GetRoleName()%> </asp:Label>
Inline expressions using the <%= ... %>
syntax can be used to render to the page.
But they can't be used to set a server-control property, which is what you're attempting to do (Label.Text property).
Consider using data-binding syntax instead:
... Text = "<%# MasterPage_MyMasterPage.GetRoleName() %>"
Try this
<%= ((MasterPage_MyMasterPage)Page.Master).GetRoleName() %>
Update:
Make a protected method in your cs file something like this
protected string getRoleName()
{
return ((MasterPage_MyMasterPage)Page.Master).GetRoleName();
}
and in aspx file
<%= getRoleName() %>
Could it be the same as this one?
How do I set an ASP.NET Label text from code behind on page load?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.