Reputation: 27387
I have no problem to get text content if it is declear inside the <asp:LinkButton runat="server" Text="Test Content">
.
However, when I place the text content between a pair of open and close <asp:LinkButton>
tags. Using the following code cannot get the text content.
ASP.NET WebForm
<li>
<asp:LinkButton ID="linkButtonLogout" runat="server" OnClick="menuItem_Click"><span class="glyphicon glyphicon-log-out"></span> Logout</asp:LinkButton>
</li>
C# Code
protected void menuItem_Click(object sender, EventArgs e)
{
LinkButton clickedMenuItem = (LinkButton)sender;
string menuItemStr = clickedMenuItem.Text;
Debug.WriteLine(">>> menuItem_Click item: " + clickedMenuItem.Text);
}
Is there a way to get text content between asp tags?
Upvotes: 1
Views: 1284
Reputation: 21795
If you will check the page source in both cases i.e. if you specify the text property explicitly or write the text between tags, you can see that both are same so in either of the two cased you can use the Text
property like this:-
protected void menuItem_Click(object sender, EventArgs e)
{
Response.Write(">>> menuItem_Click item: " + linkButtonLogout.Text);
}
Upvotes: 1