Reputation: 31
Is it possible to put Text
in a element outside the <form runat="server">
tag?
I'm trying to at least output my Session
values like the user's name in a <a>
element.
In my login.aspx.cs i start the session
Session["username"] = firstname.Text;
and then try to output it on other pages navigation that is outside the <form>
tag
<div class="collapse navbar-collapse" id="navbar-brand-centered">
<ul class="nav navbar-nav">
<li><a href="home.aspx">Home</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="account.aspx" id = "account"><!--The place where i will output--></a></li>
<li><a href="functions/logout.aspx">Logout</a></li>
</ul>
</div>
i tried to call the id
of the <a>
it doesn't appear in suggestion and i started to think that its outside the server tag.
Thank you for understanding and for helping.
Upvotes: 2
Views: 34
Reputation: 4298
Use it like <%# Session["username"].ToString() %>
, you need not set from code behind, you will directly access to it.
<div class="collapse navbar-collapse" id="navbar-brand-centered">
<ul class="nav navbar-nav">
<li><a href="home.aspx">Home</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="account.aspx" id = "account"><%# Session["username"].ToString() %></a></li>
<li><a href="functions/logout.aspx">Logout</a></li>
</ul>
</div>
Upvotes: 1