ASP:Literal控件用法
刚开始学.NET的朋友可能不清楚Literal和Label到底有什么区别,其实它们也只有一个区别,就是在转换成客户端Html代码后,Label就成了<span></span>,而Literal则是什么标记都不带,下面进入正题:
昨天做一个网站的视频新闻管理,首先我要在页面里添加一个播放器,如下:
那么如何让这个播放器能根据我们传的参数不同而播放不同的内容呢?上面一段Html代码的第5行就指明了这个播放器播放的内容来源,为了实现能根据参数不同播放不同的内容,我们将其Value值设置为一个Literal控件,然后在后置代码中动态的对Literal的Text属性赋值就OK了。代码如下:
/// <summary>
/// Author: SHY520
/// http://pw.cnblogs.com
/// </summary>
public class ShowVideoContent : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Literal lt_reader;
protected System.Web.UI.WebControls.Literal lt_vdate;
protected System.Web.UI.WebControls.Literal lb_author;
protected System.Web.UI.WebControls.Literal lt_resource;
protected System.Web.UI.WebControls.Label lb_title;
![](/Images/OutliningIndicators/InBlock.gif)
//注意:写在Object中的Literal需要我们手工定义
Literal lt_src;
![](/Images/OutliningIndicators/InBlock.gif)
private void Page_Load(object sender, System.EventArgs e)
{
if(Request.QueryString["id"] != null)
{
int id = int.Parse(Request.QueryString["id"].ToString());
//得到视频新闻内容
VideoContent vc = VideoContent.Find(id);
![](/Images/OutliningIndicators/InBlock.gif)
lt_reader.Text = vc.Announcer;
lt_vdate.Text = vc.Vdate.ToShortDateString();
lb_author.Text = vc.Author;
lt_resource.Text = vc.Resource;
lb_title.Text = vc.Videotitle;
//对播放内容赋值
lt_src.Text = vc.Linkurl;
}
}
}
Literal的用法非常灵活,希望上面的说的能对您有所帮助!
昨天做一个网站的视频新闻管理,首先我要在页面里添加一个播放器,如下:
1
<OBJECT height=288 width=384 classid=clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa VIEWASTEXT>
2
<PARAM NAME="_ExtentX" VALUE="10160"><PARAM NAME="_ExtentY" VALUE="7620">
3
<PARAM NAME="AUTOSTART" VALUE="-1"><PARAM NAME="SHUFFLE" VALUE="0">
4
<PARAM NAME="PREFETCH" VALUE="0"><PARAM NAME="NOLABELS" VALUE="0">
5
<PARAM NAME="SRC" VALUE="<asp:Literal id='lt_src' runat='server'></asp:Literal>">
6
<PARAM NAME="CONTROLS" VALUE="imagewindow"><PARAM NAME="CONSOLE" VALUE="clip1">
7
<PARAM NAME="LOOP" VALUE="0"><PARAM NAME="NUMLOOP" VALUE="0"><PARAM NAME="CENTER" VALUE="0">
8
<PARAM NAME="MAINTAINASPECT" VALUE="0"><PARAM NAME="BACKGROUNDCOLOR" VALUE="#000000">
9
</OBJECT>
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)
9
![](/Images/OutliningIndicators/None.gif)
那么如何让这个播放器能根据我们传的参数不同而播放不同的内容呢?上面一段Html代码的第5行就指明了这个播放器播放的内容来源,为了实现能根据参数不同播放不同的内容,我们将其Value值设置为一个Literal控件,然后在后置代码中动态的对Literal的Text属性赋值就OK了。代码如下:
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
Literal的用法非常灵活,希望上面的说的能对您有所帮助!
posted on 2006-06-05 20:37 Daniel Pang 阅读(26482) 评论(9) 编辑 收藏 举报