什么是LiteralControl?为什么要使用它? [英] What is LiteralControl? Why is it used?

查看:317
本文介绍了什么是LiteralControl?为什么要使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是 LiteralControl ?我正在阅读有关LiteralContols,但我不知道他们为什么被使用。
我用这个code列出的页面和控件 -
我有有一个标签和一个按钮的页面。当我使用这个

What is a LiteralControl? I was reading about LiteralContols but I am not sure why they are used. I used this code to list the controls in a page and - I have a page which has a label and a button. When I use this

foreach (Control control in Page.Controls)
{
    Response.Write(control.GetType().ToString() + " - <b> " + control.ID + "</b><br />");    

    if (control is LiteralControl)
    {
        Response.Write("Textt :" + ((LiteralControl)control).Text.ToString() + " - " + 
            Server.HtmlEncode(((LiteralControl)control).Text + "<br />") ); 
    }
}

我发现实际上有 LiteralControls 所生成之前,我已经加入到我的网页每一个控制后列出。文字控件也只有text属性。

I find that there are actually LiteralControls that are generated and listed before and after every control I have added to my page. Literal Controls also have only text property.

我仍然不知道为什么 LiteralControls 需要和使用?为什么 LiteralControls 使用吗?我添加到我的页面控件为什么有一个LiteralControl之前和之后放在哪里?他们为什么只有文本属性?

I am still not sure why LiteralControls are needed and used? Why are LiteralControls used? Why do controls that I add to my page have one LiteralControl placed before and after? And why do they have only Text Property?

推荐答案

MSDN 的文字重新控制presents HTML元素,文本和其他任何字符串不需要在服务器上处理ASP.NET页面。

From MSDN Literal Control represents HTML elements, text, and any other strings in an ASP.NET page that do not require processing on the server.

也有一看这对<一个href=\"http://www.builderau.com.au/program/asp/soa/Use-ASP-NET-s-Literal-control-to-its-full-potential/0,339028371,339286810,00.htm\">Literal控制使用

A 标签呈现一个&LT;跨度&GT; 标记。它允许您以编程方式更改
显示要显示一些文本的特征。 A LiteralControl
正是使你想让它到任何静态HTML。没有一般
优势使用一个比其他的。一个可以比另一个更有益
在某些情况下。例如,如果你想显示静态文本,
做出它没有方案变化,你可能想使用
LiteralControl。

A label renders a <span> tag. It allows you to programmatically change the display characteristics of some text you want to display. A LiteralControl renders exactly whatever static HTML you want it to. There is no general advantage of using one over the other. One may be more useful than another in certain circumstances. For example, if you want to display static text, and make no programmatic changes to it, you might want to use a LiteralControl.

这篇关于什么是LiteralControl?为什么要使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆