HtmlGenericControl.Attribute.Add("class","someClass") not working when page is routed.

377 views Asked by At

There is a Default.aspx page which contains a < i > Tag with class "fa fa-lock". The page loads fine with the glyphicon when accessed individually. But it does not change the class and hence the glyphicon of < i > when this page is accessed from some other page. For example, when SomePage.aspx routes to Default.aspx by this code Server.Transfer("Default.aspx"), it does not change the class of < i > which it should as per the following code.

<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder3" runat="server">
<a id="loginText" href="Login.aspx" runat="server">
  <i id="loginIcon" class="fa fa-lock" runat="server"></i>                       
Login
</a> 

protected void Page_Load(object sender, EventArgs e)
{
        if (Session["FirstName"] != null)
        {
            loginText.InnerText = "Logout";
            loginIcon.Attributes.Add("class", "fa fa-unlock");
        }
        else
        {
            loginIcon.Attributes.Add("class", "fa fa-lock");            
        }
}
0

There are 0 answers