当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > Web服务器控件:Literal控件

ASP.NET
关于.NET动态代理的介绍和应用简介
ASP.NET2.0服务器控件之类型转换器
ASP.net做的IP访问限制
Asp.Net2.0权限树中Checkbox的操作
ASP.NET数据库编程之Access连接失败
ASP.NET 2005 Treeview终极解决方案
ASP.NET数据库编程之处理文件访问许可
ASP.NET 2.0中的页面输出缓存
ASP.NET 2.0服务器控件开发之复杂属性
ASP.NET2.0中数据源控件之异步数据访问
將datagrid控件內容輸出到excel文件
ASP.NET技巧:教你制做Web实时进度条
实现基于事件通知的.Net套接字
ASP.NET技巧:同时对多个文件进行大量写操作对性能优化
ASP.NET中根据XML动态创建使用WEB组件
QQ关于.net的精彩对话
ASP.NET技巧:access下的分页方案
为自己的ASP网站系统构建一套标记语言
Visual Studio.Net 内幕(6)
Asp.Net中NHiernate的Session的管理

ASP.NET 中的 Web服务器控件:Literal控件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 139 ::
收藏到网摘: n/a

阅读此文请先查看软晨学习网的:ASP.NET入门教程:Web服务器控件,简单讲述了Web服务器控件的使用方法。

定义和用法

Literal 控件用于在页面上显示文本。此文本是可编程的。

注释:控件不允许您向其内容应用样式!

属性

属性 描述 .NET
Mode   2.0
runat 规定该控件是服务器控件。必须设置为 "server"。 1.0
Text 规定要显示的文本。 1.0

Web 控件标准属性

AccessKey, Attributes, BackColor, BorderColor, BorderStyle, BorderWidth,
CssClass, Enabled, Font, EnableTheming, ForeColor, Height, IsEnabled,
SkinID, Style, TabIndex, ToolTip, Width

控件标准属性

AppRelativeTemplateSourceDirectory, BindingContainer, ClientID, Controls,
EnableTheming, EnableViewState, ID, NamingContainer, Page, Parent, Site,
TemplateControl, TemplateSourceDirectory, UniqueID, Visible

语法

<asp:Literal
    EnableTheming="True|False"
    EnableViewState="True|False"
    ID="string"
    Mode="Transform|PassThrough|Encode"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    runat="server"
    SkinID="string"
    Text="string"
    Visible="True|False"
/>

使用 Literal 控件在 Web 窗体页上显示静态文本。与 Label控件不同的是,Literal 不允许您向其内容应用样式。文本在 Literal 控件中显示之前并非 HTML 编码形式。这使得可以在文本中的 HTML 标记中嵌入脚本。如果控件的值是由用户输入的,请务必要对输入值进行验证以防止出现安全漏洞。

语法

下面的示例演示如何使用 Literal 控件显示静态文本。

Visual Basic

<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>
   <script runat="server">
      Sub ButtonClick(sender As Object, e As EventArgs)     
         Literal1.Text="Welcome to ASP.NET!!"     
      End Sub
   </script>
</head>
<body>
   <form runat="server">
      <h3>Literal Example</h3>
      <asp:Literal id="Literal1"
           Text="Hello World!!"
           runat="server"/>
      <br><br>
      <asp:Button id="Button1"
           Text="Change Literal Text"
           OnClick="ButtonClick"
           runat="server"/>
   </form>
</body>
</html>

C#

<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
   <script runat="server">
      void ButtonClick(Object sender, EventArgs e)
      {
         Literal1.Text="Welcome to ASP.NET!!";
      }
   </script>
</head>
<body>
   <form runat="server">
      <h3>Literal Example</h3>
      <asp:Literal id="Literal1"
           Text="Hello World!!"
           runat="server"/>
      <br><br>
      <asp:Button id="Button1"
           Text="Change Literal Text"
           OnClick="ButtonClick"
           runat="server"/>
   </form>
</body>
</html>