What is Literal in asp.net?
Asp Literal. Text or HTML content can be directly inserted in ASP.NET. This does not require a tag in the HTML. We add dynamic content and minimize the number of DOM elements in the rendered page. The asp Literal control is useful.
Example. Here we use the <asp Literal> control. This is a good way to render content from HtmlTextWriter or to add a comment to a page. First I show an example of the asp Literal tag in the aspx markup. Then we use it in C# source code-behind.
<ul> <li><asp:Literal runat="server" ID="FeaturedCount1"/> articles</li> <li><asp:Literal runat="server" ID="CategoryCount1" /> <i><asp:Literal runat="server" ID="CategoryText1" /></i> articles similar to this one</li>
We can use code-behind in ASP.NET to "render" the above markup to actual concise page HTML. The above code shows a UL (unordered list), and we want the first list item to say "50 articles". FeaturedCount1 is where we will insert the 50.
Asp Literal. Text or HTML content can be directly inserted in ASP.NET. This does not require a tag in the HTML. We add dynamic content and minimize the number of DOM elements in the rendered page. The asp Literal control is useful.
Example. Here we use the <asp Literal> control. This is a good way to render content from HtmlTextWriter or to add a comment to a page. First I show an example of the asp Literal tag in the aspx markup. Then we use it in C# source code-behind.
<ul> <li><asp:Literal runat="server" ID="FeaturedCount1"/> articles</li> <li><asp:Literal runat="server" ID="CategoryCount1" /> <i><asp:Literal runat="server" ID="CategoryText1" /></i> articles similar to this one</li>
We can use code-behind in ASP.NET to "render" the above markup to actual concise page HTML. The above code shows a UL (unordered list), and we want the first list item to say "50 articles". FeaturedCount1 is where we will insert the 50.
public partial class SiteHome : MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
// Set the bottom article count message.
FeaturedCount1.Text = SiteStructure.Instance.MapCount.ToString();
// FeaturedCountSpan1.Text = "50";
string categoryName = "Category";
// Just for example.
int countCat = SiteStructure.Instance.CountCategory();
CategoryCount1.Text = countCat.ToString();
// "5"
CategoryText1.Text = categoryName;
// "Category"
}
}
No comments:
Post a Comment