Browse Source

More implementations.

svn path=/trunk/mcs/; revision=565
Bob Smith 24 years ago
parent
commit
f417e9e65d

+ 5 - 0
mcs/class/System.Web/ChangeLog

@@ -1,3 +1,8 @@
+2001-08-22  Bob Smith <[email protected]>
+
+        * Added directory: System.Web.UI.HtmlControls
+        * Added directory: Test
+
 2001-08-17  Bob Smith <[email protected]>
 
         * Added directory: System.Web.UI

+ 5 - 0
mcs/class/System.Web/System.Web.UI.HtmlControls/ChangeLog

@@ -0,0 +1,5 @@
+2001-08-22  Bob Smith  <[email protected]>
+
+         * HtmlContainerControl.cs: Initial implementation.
+         * HtmlControl.cs: Initial implementation.
+         * HtmlGenericControl.cs: Initial implementation.

+ 75 - 0
mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlContainerControl.cs

@@ -0,0 +1,75 @@
+//
+// System.Web.UI.HtmlControls.HtmlContainerControl.cs
+//
+// Author:
+//   Bob Smith <[email protected]>
+//
+// (C) Bob Smith
+//
+
+using System;
+using System.Web;
+using System.Web.UI;
+
+//LAMESPEC: The dox talk about HttpException but are very ambigious.
+//TODO: Check to see if Render really is overridden instead of a LiteralControl being added. It apears that this is the
+//case due to testing. Anything inside the block is overwritten by the content of this control, so it doesnt apear
+//to do anything with children.
+// a doc references this. add? protected override ControlCollection CreateControlCollection();
+
+//TODO: If Test.InnerText = Test.InnerHtml without ever assigning anything into InnerHtml, you get this:
+// Exception Details: System.Web.HttpException: Cannot get inner content of Message because the contents are not literal.
+//[HttpException (0x80004005): Cannot get inner content of Message because the contents are not literal.]
+//  System.Web.UI.HtmlControls.HtmlContainerControl.get_InnerHtml() +278
+//  ASP.test3_aspx.AnchorBtn_Click(Object Source, EventArgs E) in \\genfs2\www24\bobsmith11\test3.aspx:6
+//  System.Web.UI.HtmlControls.HtmlAnchor.OnServerClick(EventArgs e) +108
+//  System.Web.UI.HtmlControls.HtmlAnchor.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +26
+//  System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
+//  System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +149
+//  System.Web.UI.Page.ProcessRequestMain() +660
+
+
+namespace System.Web.UI.HtmlControls
+{
+        public abstract class HtmlContainerControl : HtmlControl
+        {
+                private string _innterHtml = "";
+                private string _innterText = "";
+                private bool _doText = false;
+                private bool _doChildren = true;
+                public HtmlContainerControl() : base(); {}
+                public HtmlContainerControl(string tag) : base(tag) {}
+                public virtual string InnerHtml
+                {
+                        get
+                        {
+                                return _innerHtml;
+                        }
+                        set
+                        {
+                                _innerHtml = value;
+                                _doText = false;
+                                _doChildren = false;
+                        }
+                }
+                public virtual string InnerText
+                {
+                        get
+                        {
+                                return _innerText;
+                        }
+                        set
+                        {
+                                _innerText = value;
+                                _doText = true;
+                                _doChildren = false;
+                        }
+                }
+                public override Render(HtmlTextWriter writer)
+                {
+                        if(_doChildren) RenderChildren(writer);
+                        else if(_doText) writer.write(Page.Server.HtmlEncode(_innerText));
+                        else writer.write(_innerHtml);
+                }
+        }
+}

+ 60 - 0
mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlControl.cs

@@ -0,0 +1,60 @@
+//
+// System.Web.UI.HtmlControls.HtmlControl.cs
+//
+// Author:
+//   Bob Smith <[email protected]>
+//
+// (C) Bob Smith
+//
+
+using System;
+using System.Web;
+using System.Web.UI;
+
+namespace System.Web.UI.HtmlControls
+{
+        public abstract class HtmlControl : Control, IAttributeAccessor
+        {
+                private string _tagName = "span";
+//TODO: Is this correct, or is the StateBag really the ViewState?
+                private AttributeCollection _attributes = new AttributeCollection(new StateBag(true));
+                private bool _disabled = false;
+                public HtmlControl() {}
+                public HtmlControl(string tag)
+                {
+                        if(tag != null && tag != "") _tagName = tag;
+                }
+                public AttributeCollection Attributes
+                {
+                        get
+                        {
+                                return _attributes;
+                        }
+                }
+                public bool Disabled
+                {
+                        get
+                        {
+                                return _disabled;
+                        }
+                        set
+                        {
+                                _disabled = value;
+                        }
+                }
+                public CssStyleCollection Style
+                {
+                        get
+                        {
+                                return _attributes.CssStyle;
+                        }
+                }
+                public virtual string TagName
+                {
+                        get
+                        {
+                                return _tagName;
+                        }
+                }
+        }
+}

+ 21 - 0
mcs/class/System.Web/System.Web.UI.HtmlControls/HtmlGenericControl.cs

@@ -0,0 +1,21 @@
+/
+// System.Web.UI.HtmlControls.HtmlGenericControl.cs
+//
+// Author:
+//   Bob Smith <[email protected]>
+//
+// (C) Bob Smith
+//
+
+using System;
+using System.Web;
+using System.Web.UI;
+
+namespace System.Web.UI.HtmlControls
+{
+        public class HtmlGenericControl : HtmlContainerControl
+        {
+                public HtmlContainerControl() : base(); {}
+                public HtmlContainerControl(string tag) : base(tag) {}
+        }
+}

+ 3 - 0
mcs/class/System.Web/System.Web.UI.HtmlControls/common.src

@@ -0,0 +1,3 @@
+HtmlContainerControl.cs
+HtmlControl.cs
+HtmlGenericControl.cs

+ 0 - 0
mcs/class/System.Web/System.Web.UI.HtmlControls/unix.src


+ 0 - 0
mcs/class/System.Web/System.Web.UI.HtmlControls/windows.src


+ 5 - 1
mcs/class/System.Web/System.Web.UI/ChangeLog

@@ -1,8 +1,12 @@
+2001-08-22  Bob Smith  <[email protected]>
+
+        * Control.cs: Even more implementation (Events). What a beast.
+
 2001-08-20  Bob Smith  <[email protected]>
 
         * Control.cs: More implementation. Not done yet. Shutter.
 
 2001-08-17  Bob Smith  <[email protected]>
 
-         * Control.cs: Partial implementation.
+        * Control.cs: Partial implementation.
 

+ 49 - 6
mcs/class/System.Web/System.Web.UI/Control.cs

@@ -28,6 +28,12 @@ namespace System.Web.UI
 {
         public class Control : IComponent, IDisposable, IParserAccessor, IDataBindingsAccessor
         {
+                public event EventHandler DataBinding;
+                public event EventHandler Disposed;
+                public event EventHandler Init;
+                public event EventHandler Load;
+                public event EventHandler PreRender;
+                public event EventHandler Unload;
                 private string _clientId; //default to "ctrl#" where # is a static count of ctrls per page.
                 private string _userId = null;
                 private ControlCollection _controls;
@@ -42,7 +48,6 @@ namespace System.Web.UI
                 private StateBag _viewState; //TODO: help me.
                 private bool _trackViewState = false; //TODO: I think this is right. Verify. Also modify other methods to use this.
                 private bool _viewStateIgnoreCase = true;
-                private EventHandlerList _events;
                 public Control()
                 {
                         _namingContainer = _parent;
@@ -50,6 +55,10 @@ namespace System.Web.UI
                         _events = new EventHandlerList();
                         _controls = this.CreateControlCollection(); //FIXME: this goes here?
                 }
+                public ~Control()
+                {
+                        Dispose();
+                }
                 public virtual string ClientID
                 {
                         get
@@ -187,7 +196,14 @@ namespace System.Web.UI
                 {
                         get
                         {
-                                return _events;
+                                EventHandlerList e = new EventHandlerList();
+                                e.AddHandler(this, DataBinding);
+                                e.AddHandler(this, Disposed);
+                                e.AddHandler(this, Init);
+                                e.AddHandler(this, Load);
+                                e.AddHandler(this, PreRender);
+                                e.AddHandler(this, Unload);
+                                return e;
                         }
                 }
                 protected bool HasChildViewState
@@ -266,10 +282,22 @@ namespace System.Web.UI
                 {
                         return false; //FIXME: It might throw "ItemCommand". not sure.
                 }
-                protected virtual void OnDataBinding(EventArgs e) {} //FIXME: I think this should be empty.
-                protected virtual void OnInit(EventArgs e) {} //FIXME: This one too.controls 
-                protected virtual void OnPreRender(EventArgs e) {} //FIXME: Me to.
-                protected virtual void OnUnload(EventArgs e) {} //TODO: Ok, I'm missing something. Read up on the event system.
+                protected virtual void OnDataBinding(EventArgs e)
+                {
+                        if (DataBinding != null) DataBinding(this, e);
+                }
+                protected virtual void OnInit(EventArgs e)
+                {
+                        if (Init != null) Init(this, e);
+                }
+                protected virtual void OnPreRender(EventArgs e)
+                {
+                        if (PreRender != null) PreRender(this, e);
+                }
+                protected virtual void OnUnload(EventArgs e)
+                {
+                        if (Unload != null) Unload(this, e);
+                }
                 protected void RaiseBubbleEvent(object source, EventArgs args)
                 {
                         _parent.OnBubbleEvent(source, args); //FIXME: I think this is right. Check though.
@@ -280,10 +308,25 @@ namespace System.Web.UI
                         //if render method delegate is set, call it here. otherwise,
                         //render any child controls. just a for loop?
                 }
+                protected virtual object SaveViewState()
+                {
+                        return ViewState;
+                }
                 protected virtual void TrackViewState()
                 {
                         _trackViewState = true;
                 }
+                public virtual void DataBind()
+                {
+//TODO: I think this recursively calls this method on its children.
+                }
+                public virtual void Dispose()
+                {
+                        //TODO: nuke stuff.
+                        if (Disposed != null) Disposed(this, e);
+                }
+
+
 
 
         }

+ 29 - 0
mcs/class/System.Web/Test/test.aspx

@@ -0,0 +1,29 @@
+<%@ page language="c#"%>
+<html>
+<head>
+<title>Test</title>
+<%Response.Write("Test");%>
+
+<script runat="server" language="c#">
+  void SubmitBtn_Click(Object sender, EventArgs e) {
+    Response.Write("Hi");
+  }
+</script>
+
+<form action="test.aspx" method="post" runat="server">
+<asp:button text="Click Me" OnClick="SubmitBtn_Click" runat="server"/>
+</form>
+
+<!-- output
+
+<html>
+<head>
+<title>Test</title>
+Test<form name="ctrl0" method="post" action="test.aspx" id="ctrl0">
+<input type="hidden" name="__VIEWSTATE" value="dDwtMTc0MDc5ODg1Mzs7Pg==" />
+
+<input type="submit" name="ctrl1" value="Click Me" />
+</form>
+
+
+-->

+ 23 - 0
mcs/class/System.Web/Test/test2.aspx

@@ -0,0 +1,23 @@
+<%@ page language="c#"%>
+<html>
+<head>
+<title>Test</title>
+<%Response.Write("Test");%>
+
+<script runat="server" language="c#">
+  void Unload(Object sender, EventArgs e) {
+    Response.Write("1");
+  }
+  void Disposed(Object sender, EventArgs e) {
+    Response.Write("2");
+  }
+  void click(Object sender, EventArgs e) {
+    Response.Write("3");
+  }
+</script>
+
+<asp:label id="testing" runat="server"/>
+
+<form action="test.aspx" method="post" runat="server">
+<a OnServerClick="click" runat="server">test</a>
+</form>

+ 23 - 0
mcs/class/System.Web/Test/test3.aspx

@@ -0,0 +1,23 @@
+<%@ Page Debug="true" %>
+<html>
+<script runat=server language="vb">
+
+Sub AnchorBtn_Click(Source As Object, E as EventArgs)
+          Message.InnerText = Message.InnerHtml
+       End Sub
+
+    </script>
+
+<body>
+<form method=post runat=server>
+
+<a OnServerClick="AnchorBtn_Click" runat=server> Click here at your peril.</a>
+
+<h1>
+<span id="Message" runat=server><span id="Message2" runat=server>narf</span></span>
+</h1>
+
+</form>
+</body>
+</html>
+