您的位置:首页 > 编程语言 > ASP

Web Server Controls->ASP.NET Literal Control

2007-03-27 09:41 549 查看

Definition and Usage

The Literal control is used to display text on a page. The text is programmable.

Note:[/b] This control does not let you apply styles to its content!

Properties

PropertyDescription
idA unique id for the control
runatSpecifies that the control is a server control. Must be set to "server"
TextSpecifies the text to display

Examples

Literal
ASPX Source:

<html>
<body>

<form runat="server">
<asp:Literal Text="I love ASP. NET!" runat="server" />
</form>

</body>
</html>
Output Result:

I love ASP. NET!


In this example we declare one Literal control which displays some static text in an .aspx file.

Literal 2
ASPX Source:

<script runat="server">
Sub submit(sender As Object, e As EventArgs)
Literal1.Text="I love ASP.NET!"
End Sub
</script>

<html>
<body>

<form runat="server">
<asp:Literal id="Literal1" Text="I love ASP!" runat="server" />
<br><br>
<asp:Button Text="Change Text" OnClick="submit" runat="server" />
</form>

</body>
</html>

Output Result:

I love ASP!

If you click the button "Chang Text", it will show:

I love ASP.NET!

In this example we declare one Literal control and one Button control in an .aspx file. When the user clicks on the button, the submit subroutine is executed. The subroutine changes the text of the Literal control.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: