How to: Add Literal Web Server Controls to a Web Forms Page
You can add a Literal Web server control to your Web Forms page when you want to set text programmatically without adding extra HTML tags. The Literal control is useful as a way to add text into a page dynamically without adding any elements that are not part of the dynamic text. For example, you can use the Literal control to display HTML that you read from a file or from a stream.
To add a Literal Web server control to a Web Forms page
-
From the Standard tab of the Toolbox, drag a Literal control onto the page.
-
Optionally, in the Behavior category of the Properties window, set the Mode property to Transform, PassThrough, or Encode. The Mode property specifies how the control handles any markup that is added to it. For details, see Literal Web Server Control Overview.
The following example shows a simple Web page that displays a headline at run time. The body of the page, including the Literal control, might look like this.
<body> <form runat="server"> <h1><asp:Literal id="Headline" runat=server mode="PassThrough"/></h1> </form> </body> -
Add code to your page to set the control's Text property at run time.
The following example shows how to programmatically set the text and encoding of the Literal control. The page contains radio buttons that allow the user to choose between encoded and pass-through text.
Note