Files
mono/mcs/class/System.Web/System.Web.UI/UserControl.cs
T
Gonzalo Paniagua Javier 31c202887f 2002-12-13 Gonzalo Paniagua Javier <[email protected]>
* System.Web.Compilation/AspGenerator.cs: added support for
	AutoEventWireup attribute in @Page and @Control.

	* System.Web.Compilation/CompilationResult.cs:
	* System.Web.Compilation/GlobalAsaxCompiler.cs:
	* System.Web.Compilation/PageCompiler.cs:
	* System.Web.Compilation/UserControlCompiler.cs: store the options.

	* System.Web.UI/Control.cs: added AutoEventWireup internal property.

	* System.Web.UI/Page.cs: removed page events wire up from here.

	* System.Web.UI/TemplateControl.cs: new method WireupAutomaticEvents to
	hook up page and user controls events.

	* System.Web.UI/TemplateControlParser.cs: process the options that are
	applicable once we have the instance of the control.

	* System.Web.UI/TemplateParser.cs: also stores the options.

	* System.Web.UI/UserControl.cs: hook up events before initializing the
	control.

svn path=/trunk/mcs/; revision=9623
2002-12-13 15:57:07 +00:00

191 lines
3.1 KiB
C#

//
// System.Web.UI.UserControl
//
// Authors:
// Gonzalo Paniagua Javier ([email protected])
//
// (C) 2002 Ximian, Inc (http://www.ximian.com)
//
using System;
using System.Web.Caching;
using System.Web.SessionState;
namespace System.Web.UI
{
public class UserControl : TemplateControl, IAttributeAccessor
{
private bool initialized;
private AttributeCollection attributes;
private StateBag attrBag;
public UserControl ()
{
//??
}
public HttpApplicationState Application
{
get {
Page p = Page;
if (p == null)
return null;
return p.Application;
}
}
private void EnsureAttributes ()
{
if (attributes == null) {
attrBag = new StateBag (true);
if (IsTrackingViewState)
attrBag.TrackViewState ();
attributes = new AttributeCollection (attrBag);
}
}
public AttributeCollection Attributes
{
get {
return attributes;
}
}
public Cache Cache
{
get {
Page p = Page;
if (p == null)
return null;
return p.Cache;
}
}
public bool IsPostBack
{
get {
Page p = Page;
if (p == null)
return false;
return p.IsPostBack;
}
}
public HttpRequest Request
{
get {
Page p = Page;
if (p == null)
return null;
return p.Request;
}
}
public HttpResponse Response
{
get {
Page p = Page;
if (p == null)
return null;
return p.Response;
}
}
public HttpServerUtility Server
{
get {
Page p = Page;
if (p == null)
return null;
return p.Server;
}
}
public HttpSessionState Session
{
get {
Page p = Page;
if (p == null)
return null;
return p.Session;
}
}
public TraceContext Trace
{
get {
Page p = Page;
if (p == null)
return null;
return p.Trace;
}
}
[MonoTODO]
public void DesignerInitialize ()
{
throw new NotImplementedException ();
}
public void InitializeAsUserControl (Page page)
{
if (initialized)
return;
initialized = true;
WireupAutomaticEvents ();
FrameworkInitialize ();
}
[MonoTODO]
public string MapPath (string virtualPath)
{
throw new NotImplementedException ();
}
protected override void LoadViewState (object savedState)
{
if (savedState != null) {
Pair p = (Pair) savedState;
base.LoadViewState (p.First);
if (p.Second != null) {
EnsureAttributes ();
attrBag.LoadViewState (p.Second);
}
}
}
protected override void OnInit (EventArgs e)
{
if (Page != null)
InitializeAsUserControl (Page);
base.OnInit(e);
}
protected override object SaveViewState ()
{
object baseState = base.SaveViewState();
object attrState = null;
if (attributes != null)
attrState = attrBag.SaveViewState ();
if (baseState == null && attrState == null)
return null;
return new Pair (baseState, attrState);
}
string IAttributeAccessor.GetAttribute (string name)
{
if (attributes == null)
return null;
return attributes [name];
}
void IAttributeAccessor.SetAttribute (string name, string value)
{
EnsureAttributes ();
Attributes [name] = value;
}
}
}