XYZ
XYZ

Reputation: 27387

How to get text content between asp:LinkButton tag

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>&nbsp;&nbsp;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

Answers (1)

Rahul Singh
Rahul Singh

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 Textproperty like this:-

protected void menuItem_Click(object sender, EventArgs e)
{
     Response.Write(">>> menuItem_Click item: " + linkButtonLogout.Text);
}

Upvotes: 1

Related Questions