Parcourir la source

2001-11-29 Gaurav Vaish <[email protected]>

* CheckBox.cs     -- Can now do Render-ing and LoadPostData-ing.

* ChangeLog       -- Made proper updates

svn path=/trunk/mcs/; revision=1470
Gaurav Vaish il y a 24 ans
Parent
commit
01f2946ddf

+ 7 - 0
mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog

@@ -1,4 +1,11 @@
 
+2001-11-29
+		Gaurav Vaish <[email protected]>
+	CalendarDay.cs             - Making a note that this has been implemented
+	Calendar.cs                - Making a note that have made some changes.
+                                     Unimplmented functions throw NotImplementedException
+	CheckBox.cs                - Can now "Render" and "LoadPostData"
+
 
 2001-11-08	Gaurav Vaish <[email protected]>
 	WebControl.cs              - Total Revamp, Partial Implementation

+ 87 - 6
mcs/class/System.Web/System.Web.UI.WebControls/CheckBox.cs

@@ -8,6 +8,8 @@
  * Status:  60%
  * 
  * (C) Gaurav Vaish (2001)
+ * Thanks to Leen Toelen ([email protected])'s classes that helped me
+ * to write the contents of the function LoadPostData(...)
  */
 
 using System;
@@ -111,23 +113,102 @@ namespace System.Web.UI.WebControls
 			}
 		}
 		
+		protected virtual void OnPreRender(EventArgs e)
+		{
+			throw new NotImplementedException();
+		}
+		
 		protected override void Render(HtmlTextWriter writer)
 		{
 			//TODO: THE LOST WORLD!
-			// I know I have to do it.
+			bool hasBeginRendering = false;
+			if(ControlStyleCreated)
+			{
+				if(!ControlStyle.IsEmpty)
+				{
+					hasBeginRendering = true;
+					ControlStyle.AddAttributesToRender(writer, this);
+				}
+			}
+			if(!Enabled)
+			{
+				hasBeginRendering = true;
+				writer.AddAttribute(HtmlTextWriterAttribute.Disbled, "disabled");
+			}
+			if(ToolTip.Length > 0)
+			{
+				hasBeginRendering = true;
+				writer.AddAttribute(HtmlTextWriterAttribute.Title, ToolTip);
+			}
+			if(Attributes.Count > 0)
+			{
+				hasBeginRendering = true;
+				Attributes.AddAttributes(writer);
+			}
+			if(hasBeginRendering)
+				writer.RenderBeginTag(HtmlTextWriterTag.Span);
+			if(Text.Length > 0)
+			{
+				// Looks wierd, ain't? But found out interestingly.
+				if(TextAlign == TextAlign.Right)
+				{
+					writer.AddAttribute(HtmlTextWriterAttribute.For, ClientID);
+					writer.RenderBeginTag(HtmlTextWriterTag.Label);
+					writer.Write(Text);
+					writer.RenderEngTag();
+					RenderInputTag(writer, ClientID);
+				} else
+				{
+					RenderInputTag(writer, ClientID);
+					writer.AddAttribute(HtmlTextWriterAttribute.For, ClientID);
+					writer.RenderBeginTag(HtmlTextWriterTag.Label);
+					writer.Write(Text);
+				}
+			}
+			if(hasBeginRendering)
+				writer.RenderEndTag();
+		}
+		
+		internal virtual void RenderInputTag(HtmlTextWriter writer, string clientId)
+		{
+			writer.AddAttribute(HtmlTextWriterAttribute.Id, clientId);
+			writer.AddAttribute(HtmlTextWriterAttribute.Type, "checkbox");
+			writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID);
+			if(Checked)
+			{
+				writer.AddAttribute(HtmlTextWriterAttribute.Checked, "checked");
+			}
+			if(AutoPostBack)
+			{
+				writer.AddAttribute(HtmlTextWriterAttribute.OnClick,Page.GetPostBackClientEvent(this, String.Empty));
+				writer.AddAttribute("language", "javascript");
+			}
+			if(AccessKey.Length > 0)
+			{
+				writer.AddAttribute(HtmlTextWriterAttribute.AccessKey, AccessKey);
+			}
+			if(TabIndex != 0)
+			{
+				writer.AddAttribute(HtmlTextWriterAttribute.TabIndex, TabIndex.ToString(NumberFormatInfo.InvariantInfo));
+			}
+			writer.RenderBeginTag(HtmlTextWriterTag.Input);
+			writer.RenderEndTag();
 		}
 		
 		public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
 		{
-			//TODO: THE LOST WORLD
-			// Now what the hell is this!
-			return false;
+			string postedVal = postCollection[postDataKey];
+			bool   postChecked = false;
+			if(postedVal != null)
+			{
+				postChecked = postedVal.Length > 0;
+			}
+			Checked = postChecked;
+			return (postChecked == Checked == false);
 		}
 		
 		public void RaisePostDataChangedEvent()
 		{
-			//TODO: THE LOST WORLD...
-			// Raise the bucket out of the well :))
 			OnCheckedChanged(EventArgs.Empty);
 		}
 	}