Literal Web Server Control

Source: Internet
Author: User

The literal control displays static text on a web page without adding any HTML elements. You can use the serverCodeControl the text statically in programming mode.

Note: If you want to display static text, you can use HTML to render it; the literal control is not required. The literal control is used only when you need to change the content of the server code.

The following topics help you learn how to use literal web server controls.

Literal Web Server Control Introduction

You can use the literal Web Server Control to render static text on a web page and manipulate the text using server code. Unlike the label Web Server Control, the literal control does not add any HTML elements to text.

For example, you may want to create a simple vertical list of text elements that can be programmed. You can create the preceding simple vertical list by setting the text attribute of the label control or literal control to the HTML content to be sent to the web page. If the label control is used, the control is encapsulated in the HTML <span> tag. <Span> rendering of the page is not affected in any obvious way. If you use the literal control, no <span> flag is added, which simplifies your code.

You cannot apply a style to the content of the literal control. This means that the literal control cannot be located when the web form designer is in grid mode. Therefore, literal may not be suitable for creating titles. In addition, you cannot use the client code to determine the control location.

Add literal Web Server Control to the web form page


Add a literal Web Server Control to the page when you want to set text programmatically instead of adding additional HTML tags.

Note: If you want to display static text, you can use HTML to render it; the literal control is not required. The literal control is used only when you need to change the content of the server code.

Add literal controls to the web forms page

In the design view, drag the literal control from the web forms tab of the toolbox to the page.

The following example shows a simple page that displays the title news at runtime. The body of the page (including the literal control) is similar to the following code:

<Body>

<Form runat = "server">

<H1> <asp: literal id = "headline" runat = server/>
</Form>

</Body>

Add the code to the page to set the text attribute of the control at runtime.

The following example shows how to set the literal control text programmatically.

'Visual basic

Sub page_load (byval sender as system. Object ,_

Byval e as system. eventargs) handles mybase. Load

Headline. Text = "new web site announced"

End sub

// C #
private void page_load (Object sender, system. eventargs e)

{< br>
headline. TEXT = "new web site announced";

}< br>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.