Literal.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // System.Web.UI.WebControls.Literal.cs
  3. //
  4. // Authors:
  5. // Gaurav Vaish ([email protected])
  6. // Andreas Nahr ([email protected])
  7. // Sanjay Gupta ([email protected])
  8. //
  9. // (C) Gaurav Vaish (2002)
  10. // (C) 2003 Andreas Nahr
  11. // (C) 2004, Novell, Inc. (http://www.novell.com)
  12. //
  13. //
  14. //
  15. // Permission is hereby granted, free of charge, to any person obtaining
  16. // a copy of this software and associated documentation files (the
  17. // "Software"), to deal in the Software without restriction, including
  18. // without limitation the rights to use, copy, modify, merge, publish,
  19. // distribute, sublicense, and/or sell copies of the Software, and to
  20. // permit persons to whom the Software is furnished to do so, subject to
  21. // the following conditions:
  22. //
  23. // The above copyright notice and this permission notice shall be
  24. // included in all copies or substantial portions of the Software.
  25. //
  26. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  30. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  31. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  32. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  33. //
  34. using System;
  35. using System.Web;
  36. using System.Web.UI;
  37. using System.ComponentModel;
  38. namespace System.Web.UI.WebControls
  39. {
  40. [DefaultProperty("Text")]
  41. [ControlBuilder(typeof(LiteralControlBuilder))]
  42. [DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, " + Consts.AssemblySystem_Design)]
  43. #if NET_2_0
  44. [DesignerAttribute ("Value not found")]
  45. #endif
  46. public class Literal : Control
  47. #if NET_2_0
  48. // , IStaticTextControl
  49. #endif
  50. {
  51. public Literal () : base ()
  52. {
  53. }
  54. [DefaultValue (""), Bindable (true), WebCategory ("Appearance")]
  55. [WebSysDescription ("The text for the literal WebControl.")]
  56. #if NET_2_0
  57. [Localizable (true)]
  58. #endif
  59. public string Text
  60. {
  61. get {
  62. object o = ViewState ["Text"];
  63. return (o == null) ? String.Empty : (string) o;
  64. }
  65. set { ViewState ["Text"] = value; }
  66. }
  67. protected override ControlCollection CreateControlCollection ()
  68. {
  69. return new EmptyControlCollection (this);
  70. }
  71. protected override void AddParsedSubObject (object obj)
  72. {
  73. if (!(obj is LiteralControl))
  74. throw new HttpException (HttpRuntime.FormatResourceString (
  75. "Cannot_Have_Children_Of_Type", "Literal",
  76. obj.GetType ().Name.ToString ()));
  77. Text = ((LiteralControl) obj).Text;
  78. }
  79. protected override void Render (HtmlTextWriter writer)
  80. {
  81. if (Text.Length > 0)
  82. writer.Write (Text);
  83. }
  84. #if NET_2_0
  85. private LiteralMode literalMode;
  86. [DefaultValue (LiteralMode.Transform), WebCategory ("Behavior"), WebSysDescription ("Determines whether the text is transformed or encoded")]
  87. public LiteralMode Mode {
  88. get { return literalMode; }
  89. set { literalMode = value; }
  90. }
  91. //No information as to which Focus() method is being overridden
  92. /*[MonoTODO]
  93. public override void Focus ()
  94. {
  95. throw new Exception ("No information provided");
  96. }*/
  97. #endif
  98. }
  99. }