Senin, 15 Juli 2013

How to use Literal Control in ASP.NET

Introduction of Literal control in ASP.NET:
The literal control is another Web Server control used for displaying text on a Web page, similar to that done by a Label control in ASP.NET , You can add HTML in a web page with the help of Literal control , without switching to the .aspx page. The Literal control exists within the System.Web.UI.WebControls namespace.

Public Properties of the Literal Class

Mode : Obtains or sets an enumeration value that specifies how the content in the Literal control is rendered.

Text : Obtains or sets the caption displayed in the Literal control.

Example of Literal control

How to use Facebook developer plugin using Literal control.


<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:Literal ID="Literal1" runat="server" Mode ="Transform">
            <div id="fb-root"></div>
<script>(function (d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=257965964247226";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
            <div class="fb-like-box" data-href="https://www.facebook.com/Dotprogramming?ref=hl" data-width="292" data-show-faces="true" data-stream="true" data-show-border="true" data-header="true"></div>          
        </asp:Literal>
   
    </div>
    </form>
</body>
</html>
Output
How to use Literal Control in ASP.NET
 
When you add a Literal control on a web page , The following code is added to the source code of the Web page.
 
<asp:Literal Id="Literal1" runat="server"></asp:Literal>
in above example mode property is set to Transform that convert your HTML tag into your HTML output.
simply you can say
<H1> Hello world </H1>
 
Transform enumeration property  gives effect of the heading Tag
Output
Hello world
 
 
 


Tidak ada komentar:

Posting Komentar