2010-06-21 Marek Habersack <mhabersack@novell.com>
[mcs.git] / class / System.Web / System.Web.UI.HtmlControls / HtmlControl.cs
blobad7b11094228c08420c39522ff1b4c926ae435f3
1 //
2 // System.Web.UI.HtmlControls.HtmlControl.cs
3 //
4 // Author
5 // Bob Smith <bob@thestuff.net>
6 //
7 //
8 // (C) Bob Smith
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:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
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{
38 // CAS
39 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
40 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
41 // attributes
42 [ToolboxItem(false)]
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)
54 _tagName = 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);
64 return null;
67 internal static string AttributeToString(string s){
68 if (s != null && s.Length != 0) return s;
69 return null;
72 internal void PreProcessRelativeReference(HtmlTextWriter writer, string attribName){
73 string attr = Attributes[attribName];
74 if (attr != null){
75 if (attr.Length != 0){
76 try{
77 attr = ResolveClientUrl(attr);
79 catch (Exception) {
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);
112 writer.Write ('>');
115 protected internal override void Render (HtmlTextWriter writer)
117 RenderBeginTag (writer);
120 protected virtual void RenderAttributes(HtmlTextWriter writer){
121 if (ID != null){
122 writer.WriteAttribute("id",ClientID);
124 Attributes.Render(writer);
127 [Browsable(false)]
128 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
129 public AttributeCollection Attributes {
130 get {
131 if (_attributes == null)
132 _attributes = new AttributeCollection (ViewState);
133 return _attributes;
137 [DefaultValue(false)]
138 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
139 [WebSysDescription("")]
140 [WebCategory("Behavior")]
141 [TypeConverter (typeof(MinimizableAttributeTypeConverter))]
142 public bool Disabled {
143 get {
144 string disableAttr = Attributes["disabled"] as string;
145 return (disableAttr != null);
147 set {
148 if (!value)
149 Attributes.Remove ("disabled");
150 else
151 Attributes["disabled"] = "disabled";
155 [Browsable(false)]
156 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
157 public CssStyleCollection Style {
158 get { return Attributes.CssStyle; }
161 [DefaultValue("")]
162 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
163 [WebSysDescription("")]
164 [WebCategory("Appearance")]
165 public virtual string TagName {
166 get { return _tagName; }
169 protected override bool ViewStateIgnoresCase {
170 get {
171 return true;