Friends who have just started learning .NET may not know the difference between Literal and Label. In fact, there is only one difference between them. That is, after converting into client Html code, Label becomes <span></span>, while Literal becomes There is no mark at all, so let’s get to the point:
Yesterday I was doing video news management for a website. First I had to add a player to the page, as follows:
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>
So how do we enable this player to play different content based on the different parameters we pass? Line 5 of the above Html code specifies the source of the content played by this player. In order to achieve the ability to play different content based on different parameters, We set its Value value to a Literal control, and then dynamically assign a value to the Literal Text property in the code behind. The code is as follows:
/**//// <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;
//Note: Literal written in Object needs to be defined manually
Literal lt_src;
private void Page_Load(object sender, System.EventArgs e)
{
if(Request.QueryString["id"] != null)
{
int id = int.Parse(Request.QueryString["id"].ToString());
//Get video news content
VideoContent vc = VideoContent.Find(id);
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;
//Assign value to the playback content
lt_src.Text = vc.Linkurl;
}
}
}
The usage of Literal is very flexible. I hope what I said above will be helpful to you!