• Literal控件用法


    刚开始学.NET的朋友可能不清楚Literal和Label到底有什么区别,其实它们也只有一个区别,就是在转换成客户端Html代码后,Label就成了<span></span>,而Literal则是什么标记都不带。

    例如:用Label时输入为"<span id="ctl00_ContentPlaceHolder1_lblTopicsTitle">求Adobe.Illustrator.CS2.简体中文版授权码</span>"

    应用:
              昨天做一个网站的视频新闻管理,首先我要在页面里添加一个播放器,如下:
    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>
    那么如何让这个播放器能根据我们传的参数不同而播放不同的内容呢?上面一段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;

               //注意:写在Object中的Literal需要我们手工定义
               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());


    ;       //得到视频新闻内容
                       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;
                    
                       //对播放内容赋值
                       lt_src.Text = vc.Linkurl;
                   }
               }
    }
    Literal的用法非常灵活,希望上面的说的能对您有所帮助!

  • 相关阅读:
    Codeforces Round #313 (Div. 2) D. Equivalent Strings 解题心得
    UVA
    2015 HUAS Summer Contest#1~A
    2015 HUAS Summer Training#2~D
    2015 HUAS Summer Training#2~C
    2015 HUAS Summer Training#2~E
    2015 HUAS Summer Training#2~A
    2015 HUAS Provincial Select Contest #1
    2015 HUAS Provincial Select Contest #1~F
    2015 HUAS Provincial Select Contest #2~A
  • 原文地址:https://www.cnblogs.com/SALIN/p/1090247.html
Copyright © 2020-2023  润新知