2 // System.Web.UI.HtmlControls.HtmlControl.cs
5 // Bob Smith <bob@thestuff.net>
9 // Copyright (C) 2005-2010 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System
.ComponentModel
;
32 using System
.ComponentModel
.Design
;
33 using System
.Globalization
;
34 using System
.Security
.Permissions
;
36 namespace System
.Web
.UI
.HtmlControls
{
39 [AspNetHostingPermission (SecurityAction
.LinkDemand
, Level
= AspNetHostingPermissionLevel
.Minimal
)]
40 [AspNetHostingPermission (SecurityAction
.InheritanceDemand
, Level
= AspNetHostingPermissionLevel
.Minimal
)]
43 [Designer ("System.Web.UI.Design.HtmlIntrinsicControlDesigner, " + Consts
.AssemblySystem_Design
,
44 "System.ComponentModel.Design.IDesigner")]
45 public abstract class HtmlControl
: Control
, IAttributeAccessor
47 internal string _tagName
;
48 AttributeCollection _attributes
;
50 protected HtmlControl() : this ("span") {}
52 protected HtmlControl(string tag
)
57 protected override ControlCollection
CreateControlCollection ()
59 return new EmptyControlCollection (this);
62 internal static string AttributeToString(int n
){
63 if (n
!= -1)return n
.ToString(NumberFormatInfo
.InvariantInfo
);
67 internal static string AttributeToString(string s
){
68 if (s
!= null && s
.Length
!= 0) return s
;
72 internal void PreProcessRelativeReference(HtmlTextWriter writer
, string attribName
){
73 string attr
= Attributes
[attribName
];
75 if (attr
.Length
!= 0){
77 attr
= ResolveClientUrl(attr
);
80 throw new HttpException(attribName
+ " property had malformed url");
82 writer
.WriteAttribute(attribName
, attr
);
83 Attributes
.Remove(attribName
);
88 /* keep these two methods in sync with the
89 * IAttributeAccessor iface methods below */
90 protected virtual string GetAttribute (string name
)
92 return Attributes
[name
];
95 protected virtual void SetAttribute (string name
, string value)
97 Attributes
[name
] = value;
100 string System
.Web
.UI
.IAttributeAccessor
.GetAttribute(string name
){
101 return Attributes
[name
];
104 void System
.Web
.UI
.IAttributeAccessor
.SetAttribute(string name
, string value){
105 Attributes
[name
] = value;
108 protected virtual void RenderBeginTag (HtmlTextWriter writer
)
110 writer
.WriteBeginTag (TagName
);
111 RenderAttributes (writer
);
115 protected internal override void Render (HtmlTextWriter writer
)
117 RenderBeginTag (writer
);
120 protected virtual void RenderAttributes(HtmlTextWriter writer
){
122 writer
.WriteAttribute("id",ClientID
);
124 Attributes
.Render(writer
);
128 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
129 public AttributeCollection Attributes
{
131 if (_attributes
== null)
132 _attributes
= new AttributeCollection (ViewState
);
137 [DefaultValue(false)]
138 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
139 [WebSysDescription("")]
140 [WebCategory("Behavior")]
141 [TypeConverter (typeof(MinimizableAttributeTypeConverter
))]
142 public bool Disabled
{
144 string disableAttr
= Attributes
["disabled"] as string;
145 return (disableAttr
!= null);
149 Attributes
.Remove ("disabled");
151 Attributes
["disabled"] = "disabled";
156 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
157 public CssStyleCollection Style
{
158 get { return Attributes.CssStyle; }
162 [DesignerSerializationVisibility (DesignerSerializationVisibility
.Hidden
)]
163 [WebSysDescription("")]
164 [WebCategory("Appearance")]
165 public virtual string TagName
{
166 get { return _tagName; }
169 protected override bool ViewStateIgnoresCase
{