2 // System.Web.UI.Page.cs
5 // Duncan Mak (duncan@ximian.com)
6 // Gonzalo Paniagua (gonzalo@ximian.com)
7 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
9 // (C) 2002,2003 Ximian, Inc. (http://www.ximian.com)
10 // Copyright (C) 2003,2005 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Collections;
34 using System.Collections.Specialized;
35 using System.ComponentModel;
36 using System.ComponentModel.Design;
37 using System.ComponentModel.Design.Serialization;
38 using System.Globalization;
40 using System.Security.Cryptography;
41 using System.Security.Permissions;
42 using System.Security.Principal;
44 using System.Threading;
46 using System.Web.Caching;
47 using System.Web.Configuration;
48 using System.Web.SessionState;
49 using System.Web.Util;
50 using System.Web.UI.HtmlControls;
51 using System.Web.UI.WebControls;
53 using System.Web.UI.Adapters;
56 namespace System.Web.UI
59 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
60 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
62 [RootDesignerSerializer ("Microsoft.VSDesigner.WebForms.RootCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design, true)]
64 [DefaultEvent ("Load"), DesignerCategory ("ASPXCodeBehind")]
67 [Designer ("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VisualStudio_Web, typeof (IRootDesigner))]
69 [Designer ("Microsoft.VSDesigner.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VSDesigner, typeof (IRootDesigner))]
71 public partial class Page : TemplateControl, IHttpHandler
74 private PageLifeCycle _lifeCycle = PageLifeCycle.Unknown;
75 private bool _eventValidation = true;
76 private object [] _savedControlState;
77 private bool _doLoadPreviousPage;
78 string _focusedControlID;
80 private bool _viewState = true;
81 private bool _viewStateMac;
82 private string _errorPage;
83 private bool is_validated;
84 private bool _smartNavigation;
85 private int _transactionMode;
86 private HttpContext _context;
87 private ValidatorCollection _validators;
88 private bool renderingForm;
89 private string _savedViewState;
90 private ArrayList _requiresPostBack;
91 private ArrayList _requiresPostBackCopy;
92 private ArrayList requiresPostDataChanged;
93 private IPostBackEventHandler requiresRaiseEvent;
94 private NameValueCollection secondPostData;
95 private bool requiresPostBackScript;
96 private bool postBackScriptRendered;
98 string viewStateUserKey;
99 NameValueCollection _requestValueCollection;
101 ClientScriptManager scriptManager;
102 bool allow_load; // true when the Form collection belongs to this page (GetTypeHashCode)
103 PageStatePersister page_state_persister;
105 [EditorBrowsable (EditorBrowsableState.Never)]
111 const string postEventArgumentID = "__EVENTARGUMENT";
113 [EditorBrowsable (EditorBrowsableState.Never)]
119 const string postEventSourceID = "__EVENTTARGET";
122 const string ScrollPositionXID = "__SCROLLPOSITIONX";
123 const string ScrollPositionYID = "__SCROLLPOSITIONY";
127 internal const string CallbackArgumentID = "__CALLBACKARGUMENT";
128 internal const string CallbackSourceID = "__CALLBACKTARGET";
129 internal const string PreviousPageID = "__PREVIOUSPAGE";
133 MasterPage masterPage;
134 string masterPageFile;
137 bool isCrossPagePostBack;
140 ArrayList requireStateControls;
141 Hashtable _validatorsByGroup;
146 string _styleSheetTheme;
149 bool _maintainScrollPositionOnPostBack;
155 scriptManager = new ClientScriptManager (this);
164 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
166 public HttpApplicationState Application
169 if (_context == null)
171 return _context.Application;
175 [EditorBrowsable (EditorBrowsableState.Never)]
176 protected bool AspCompatMode
179 get { return false; }
181 set { throw new NotImplementedException (); }
184 [EditorBrowsable (EditorBrowsableState.Never)]
186 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
187 [BrowsableAttribute (false)]
190 get { return Response.BufferOutput; }
191 set { Response.BufferOutput = value; }
194 protected bool Buffer
196 set { Response.BufferOutput = value; }
200 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
205 if (_context == null)
206 throw new HttpException ("No cache available without a context.");
207 return _context.Cache;
212 [EditorBrowsableAttribute (EditorBrowsableState.Advanced)]
214 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
215 [Browsable (false), DefaultValue ("")]
216 [WebSysDescription ("Value do override the automatic browser detection and force the page to use the specified browser.")]
217 public string ClientTarget
219 get { return (clientTarget == null) ? "" : clientTarget; }
221 clientTarget = value;
227 [EditorBrowsable (EditorBrowsableState.Never)]
229 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
230 [BrowsableAttribute (false)]
233 get { return Response.ContentEncoding.CodePage; }
234 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
237 protected int CodePage
239 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
243 [EditorBrowsable (EditorBrowsableState.Never)]
245 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
246 [BrowsableAttribute (false)]
247 public string ContentType
249 get { return Response.ContentType; }
250 set { Response.ContentType = value; }
253 protected string ContentType
255 set { Response.ContentType = value; }
259 protected override HttpContext Context
262 if (_context == null)
263 return HttpContext.Current;
270 [EditorBrowsable (EditorBrowsableState.Advanced)]
271 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
272 [BrowsableAttribute (false)]
273 public string Culture
275 get { return Thread.CurrentThread.CurrentCulture.Name; }
276 set { Thread.CurrentThread.CurrentCulture = GetPageCulture (value, Thread.CurrentThread.CurrentCulture); }
279 [EditorBrowsable (EditorBrowsableState.Never)]
280 protected string Culture
282 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
287 public virtual bool EnableEventValidation {
288 get { return _eventValidation; }
290 if (_lifeCycle > PageLifeCycle.Init)
291 throw new InvalidOperationException ("The 'EnableEventValidation' property can be set only in the Page_init, the Page directive or in the <pages> configuration section.");
292 _eventValidation = value;
296 internal PageLifeCycle LifeCycle {
297 get { return _lifeCycle; }
302 public override bool EnableViewState
304 get { return _viewState; }
305 set { _viewState = value; }
309 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
310 [BrowsableAttribute (false)]
312 [EditorBrowsable (EditorBrowsableState.Never)]
318 bool EnableViewStateMac
320 get { return _viewStateMac; }
321 set { _viewStateMac = value; }
325 internal bool EnableViewStateMacInternal {
326 get { return _viewStateMac; }
327 set { _viewStateMac = value; }
331 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
332 [Browsable (false), DefaultValue ("")]
333 [WebSysDescription ("The URL of a page used for error redirection.")]
334 public string ErrorPage
336 get { return _errorPage; }
339 if (_context != null)
340 _context.ErrorPage = value;
347 [EditorBrowsable (EditorBrowsableState.Never)]
348 protected ArrayList FileDependencies
351 if (Response != null)
352 Response.AddFileDependencies (value);
358 [EditorBrowsable (EditorBrowsableState.Never)]
360 public override string ID
362 get { return base.ID; }
363 set { base.ID = value; }
366 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
368 public bool IsPostBack
374 return _requestValueCollection != null;
379 [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
380 public bool IsReusable {
381 get { return false; }
384 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
386 public bool IsValid {
389 throw new HttpException (Locale.GetText ("Page hasn't been validated."));
392 foreach (IValidator val in Validators)
397 return ValidateCollection (_validators);
402 public IDictionary Items {
405 items = new Hashtable ();
411 [EditorBrowsable (EditorBrowsableState.Never)]
413 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
414 [BrowsableAttribute (false)]
416 get { return Thread.CurrentThread.CurrentCulture.LCID; }
417 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
421 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
427 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
428 public bool MaintainScrollPositionOnPostBack {
429 get { return _maintainScrollPositionOnPostBack; }
430 set { _maintainScrollPositionOnPostBack = value; }
435 public PageAdapter PageAdapter {
437 return (PageAdapter)Adapter;
443 internal string PostBackFunctionName {
445 return "__doPostBack";
450 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
452 public HttpRequest Request
455 if (_context != null)
456 return _context.Request;
458 throw new HttpException("Request is not available without context");
462 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
464 public HttpResponse Response
467 if (_context != null)
468 return _context.Response;
470 throw new HttpException ("Response is not available without context");
474 [EditorBrowsable (EditorBrowsableState.Never)]
476 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
477 [BrowsableAttribute (false)]
478 public string ResponseEncoding
480 get { return Response.ContentEncoding.WebName; }
481 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
484 protected string ResponseEncoding
486 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
490 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
492 public HttpServerUtility Server
495 return Context.Server;
499 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
501 public virtual HttpSessionState Session
504 if (_context == null)
505 _context = HttpContext.Current;
507 if (_context == null)
508 throw new HttpException ("Session is not available without context");
510 if (_context.Session == null)
511 throw new HttpException ("Session state can only be used " +
512 "when enableSessionState is set to true, either " +
513 "in a configuration file or in the Page directive.");
515 return _context.Session;
520 [FilterableAttribute (false)]
524 public bool SmartNavigation
526 get { return _smartNavigation; }
527 set { _smartNavigation = value; }
531 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
534 public virtual string StyleSheetTheme {
535 get { return _styleSheetTheme; }
536 set { _styleSheetTheme = value; }
540 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
541 public virtual string Theme {
542 get { return _theme; }
543 set { _theme = value; }
546 void InitializeStyleSheet ()
548 if (_styleSheetTheme == null) {
549 PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
551 _styleSheetTheme = ps.StyleSheetTheme;
553 if (_styleSheetTheme != null && _styleSheetTheme != "")
554 _styleSheetPageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_styleSheetTheme, _context);
557 void InitializeTheme ()
559 if (_theme == null) {
560 PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
564 if (_theme != null && _theme != "") {
565 _pageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_theme, _context);
566 _pageTheme.SetPage (this);
575 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
576 public string Title {
579 return htmlHeader.Title;
583 if (htmlHeader != null)
584 htmlHeader.Title = value;
591 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
593 public TraceContext Trace
595 get { return Context.Trace; }
598 [EditorBrowsable (EditorBrowsableState.Never)]
600 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
601 [BrowsableAttribute (false)]
602 public bool TraceEnabled
604 get { return Trace.IsEnabled; }
605 set { Trace.IsEnabled = value; }
608 protected bool TraceEnabled
610 set { Trace.IsEnabled = value; }
614 [EditorBrowsable (EditorBrowsableState.Never)]
616 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
617 [BrowsableAttribute (false)]
618 public TraceMode TraceModeValue
620 get { return Trace.TraceMode; }
621 set { Trace.TraceMode = value; }
624 protected TraceMode TraceModeValue
626 set { Trace.TraceMode = value; }
630 [EditorBrowsable (EditorBrowsableState.Never)]
631 protected int TransactionMode
634 get { return _transactionMode; }
636 set { _transactionMode = value; }
641 // This method is here just to remove the warning about "_transactionMode" not being
642 // used. We probably will use it internally at some point.
644 internal int GetTransactionMode ()
646 return _transactionMode;
651 [EditorBrowsable (EditorBrowsableState.Advanced)]
652 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
653 [BrowsableAttribute (false)]
654 public string UICulture
656 get { return Thread.CurrentThread.CurrentUICulture.Name; }
657 set { Thread.CurrentThread.CurrentUICulture = GetPageCulture (value, Thread.CurrentThread.CurrentUICulture); }
660 [EditorBrowsable (EditorBrowsableState.Never)]
661 protected string UICulture
663 set { Thread.CurrentThread.CurrentUICulture = new CultureInfo (value); }
667 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
669 public IPrincipal User
671 get { return Context.User; }
674 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
676 public ValidatorCollection Validators
679 if (_validators == null)
680 _validators = new ValidatorCollection ();
685 [MonoTODO ("Use this when encrypting/decrypting ViewState")]
687 public string ViewStateUserKey {
688 get { return viewStateUserKey; }
689 set { viewStateUserKey = value; }
693 public override bool Visible
695 get { return base.Visible; }
696 set { base.Visible = value; }
704 CultureInfo GetPageCulture (string culture, CultureInfo deflt)
708 CultureInfo ret = null;
709 if (culture.StartsWith ("auto")) {
710 string[] languages = Request.UserLanguages;
712 if (languages != null && languages.Length > 0)
713 ret = new CultureInfo (languages[0]);
720 ret = new CultureInfo (culture);
726 [EditorBrowsable (EditorBrowsableState.Never)]
727 protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
731 throw new NotImplementedException ();
734 [EditorBrowsable (EditorBrowsableState.Never)]
735 protected void AspCompatEndProcessRequest (IAsyncResult result)
737 throw new NotImplementedException ();
740 [EditorBrowsable (EditorBrowsableState.Advanced)]
741 protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
743 return new HtmlTextWriter (tw);
746 [EditorBrowsable (EditorBrowsableState.Never)]
747 public void DesignerInitialize ()
749 InitRecursive (null);
752 [EditorBrowsable (EditorBrowsableState.Advanced)]
753 protected virtual NameValueCollection DeterminePostBackMode ()
755 if (_context == null)
758 HttpRequest req = _context.Request;
762 NameValueCollection coll = null;
763 if (0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture)) {
765 WebROCollection c = (WebROCollection) coll;
766 allow_load = !c.GotID;
768 c.ID = GetTypeHashCode ();
770 allow_load = (c.ID == GetTypeHashCode ());
773 coll = req.QueryString;
777 coll = LoadViewStateForPortlet((WebROCollection)coll);
780 if (coll != null && coll ["__VIEWSTATE"] == null && coll ["__EVENTTARGET"] == null)
787 public override Control FindControl (string id) {
791 return base.FindControl (id);
798 [EditorBrowsable (EditorBrowsableState.Advanced)]
799 public string GetPostBackClientEvent (Control control, string argument)
801 return scriptManager.GetPostBackEventReference (control, argument);
807 [EditorBrowsable (EditorBrowsableState.Advanced)]
808 public string GetPostBackClientHyperlink (Control control, string argument)
810 return scriptManager.GetPostBackClientHyperlink (control, argument);
816 [EditorBrowsable (EditorBrowsableState.Advanced)]
817 public string GetPostBackEventReference (Control control)
819 return scriptManager.GetPostBackEventReference (control, "");
825 [EditorBrowsable (EditorBrowsableState.Advanced)]
826 public string GetPostBackEventReference (Control control, string argument)
828 return scriptManager.GetPostBackEventReference (control, argument);
831 internal void RequiresPostBackScript ()
833 requiresPostBackScript = true;
836 [EditorBrowsable (EditorBrowsableState.Never)]
837 public virtual int GetTypeHashCode ()
843 [MonoTODO("The following properties of OutputCacheParameters are silently ignored: CacheProfile, NoStore, SqlDependency")]
844 protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings)
846 if (cacheSettings.Enabled)
847 InitOutputCache(cacheSettings.Duration,
848 cacheSettings.VaryByHeader,
849 cacheSettings.VaryByCustom,
850 cacheSettings.Location,
851 cacheSettings.VaryByParam);
855 [EditorBrowsable (EditorBrowsableState.Never)]
856 protected virtual void InitOutputCache (int duration,
859 OutputCacheLocation location,
862 HttpCachePolicy cache = _context.Response.Cache;
863 bool set_vary = false;
866 case OutputCacheLocation.Any:
867 cache.SetCacheability (HttpCacheability.Public);
868 cache.SetMaxAge (new TimeSpan (0, 0, duration));
869 cache.SetLastModified (_context.Timestamp);
872 case OutputCacheLocation.Client:
873 cache.SetCacheability (HttpCacheability.Private);
874 cache.SetMaxAge (new TimeSpan (0, 0, duration));
875 cache.SetLastModified (_context.Timestamp);
877 case OutputCacheLocation.Downstream:
878 cache.SetCacheability (HttpCacheability.Public);
879 cache.SetMaxAge (new TimeSpan (0, 0, duration));
880 cache.SetLastModified (_context.Timestamp);
882 case OutputCacheLocation.Server:
883 cache.SetCacheability (HttpCacheability.Server);
886 case OutputCacheLocation.None:
891 if (varyByCustom != null)
892 cache.SetVaryByCustom (varyByCustom);
894 if (varyByParam != null && varyByParam.Length > 0) {
895 string[] prms = varyByParam.Split (';');
896 foreach (string p in prms)
897 cache.VaryByParams [p.Trim ()] = true;
898 cache.VaryByParams.IgnoreParams = false;
900 cache.VaryByParams.IgnoreParams = true;
903 if (varyByHeader != null && varyByHeader.Length > 0) {
904 string[] hdrs = varyByHeader.Split (';');
905 foreach (string h in hdrs)
906 cache.VaryByHeaders [h.Trim ()] = true;
910 cache.Duration = duration;
911 cache.SetExpires (_context.Timestamp.AddSeconds (duration));
917 [EditorBrowsable (EditorBrowsableState.Advanced)]
919 public bool IsClientScriptBlockRegistered (string key)
921 return scriptManager.IsClientScriptBlockRegistered (key);
927 [EditorBrowsable (EditorBrowsableState.Advanced)]
929 public bool IsStartupScriptRegistered (string key)
931 return scriptManager.IsStartupScriptRegistered (key);
934 public string MapPath (string virtualPath)
936 return Request.MapPath (virtualPath);
940 protected internal override void Render (HtmlTextWriter writer) {
941 if (MaintainScrollPositionOnPostBack) {
942 RequiresPostBackScript ();
944 string scriptUrl = ClientScript.GetWebResourceUrl (typeof (Page), "MaintainScrollPositionOnPostBack.js");
946 ClientScript.RegisterClientScriptInclude (typeof (Page), "MaintainScrollPositionOnPostBack.js", scriptUrl);
948 ClientScript.RegisterHiddenField (ScrollPositionXID, Request [ScrollPositionXID]);
949 ClientScript.RegisterHiddenField (ScrollPositionYID, Request [ScrollPositionYID]);
951 StringBuilder script = new StringBuilder ();
952 script.AppendLine ("<script type=\"text/javascript\">");
953 script.AppendLine ("<!--");
954 script.AppendLine ("theForm.oldSubmit = theForm.submit");
955 script.AppendLine ("theForm.submit = WebForm_SaveScrollPositionSubmit");
956 script.AppendLine ("theForm.oldOnSubmit = theForm.onsubmit");
957 script.AppendLine ("theForm.onsubmit = WebForm_SaveScrollPositionOnSubmit");
959 script.AppendLine ("theForm.oldOnLoad = window.onload");
960 script.AppendLine ("window.onload = WebForm_RestoreScrollPosition");
962 script.AppendLine ("// -->");
963 script.AppendLine ("</script>");
965 ClientScript.RegisterStartupScript (typeof (Page), "MaintainScrollPositionOnPostBackStartup", script.ToString());
967 base.Render (writer);
971 private void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
973 writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventSourceID);
974 writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventArgumentID);
976 writer.WriteLine ("<script language=\"javascript\">");
977 writer.WriteLine ("<!--");
979 writer.WriteLine ("\tvar theForm;\n\tif (document.getElementById) {{ theForm = document.getElementById ('{0}'); }}", formUniqueID);
980 writer.WriteLine ("\telse {{ theForm = document.{0}; }}", formUniqueID);
981 writer.WriteLine ("\tfunction " + PostBackFunctionName + "(eventTarget, eventArgument) {");
982 writer.WriteLine ("\t\tif(document.ValidatorOnSubmit && !ValidatorOnSubmit()) return;");
983 writer.WriteLine ("\t\ttheForm.{0}.value = eventTarget;", postEventSourceID);
984 writer.WriteLine ("\t\ttheForm.{0}.value = eventArgument;", postEventArgumentID);
985 writer.WriteLine ("\t\ttheForm.submit();");
986 writer.WriteLine ("\t}");
987 writer.WriteLine ("// -->");
988 writer.WriteLine ("</script>");
991 internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
994 throw new HttpException ("Only 1 HtmlForm is allowed per page.");
996 renderingForm = true;
1000 scriptManager.RegisterHiddenField ("__VIEWSTATE", _savedViewState);
1002 scriptManager.WriteHiddenFields (writer);
1003 if (requiresPostBackScript) {
1004 RenderPostBackScript (writer, formUniqueID);
1005 postBackScriptRendered = true;
1007 scriptManager.WriteClientScriptIncludes (writer);
1008 scriptManager.WriteClientScriptBlocks (writer);
1011 internal IStateFormatter GetFormatter ()
1013 return new ObjectStateFormatter (this);
1016 internal string GetSavedViewState ()
1018 return _savedViewState;
1021 internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
1023 scriptManager.WriteArrayDeclares (writer);
1025 if (!postBackScriptRendered && requiresPostBackScript)
1026 RenderPostBackScript (writer, formUniqueID);
1029 scriptManager.SaveEventValidationState ();
1030 scriptManager.WriteExpandoAttributes (writer);
1032 scriptManager.WriteHiddenFields (writer);
1033 scriptManager.WriteStartupScriptBlocks (writer);
1034 renderingForm = false;
1035 postBackScriptRendered = false;
1038 private void ProcessPostData (NameValueCollection data, bool second)
1042 Hashtable used = new Hashtable ();
1043 foreach (string id in data.AllKeys){
1044 if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID)
1047 string real_id = id;
1048 int dot = real_id.IndexOf ('.');
1050 real_id = real_id.Substring (0, dot);
1052 if (real_id == null || used.ContainsKey (real_id))
1055 used.Add (real_id, real_id);
1057 Control ctrl = FindControl (real_id);
1059 IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
1060 IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
1064 RegisterRequiresRaiseEvent (pbeh);
1068 if (pbdh.LoadPostData (real_id, data) == true) {
1069 if (requiresPostDataChanged == null)
1070 requiresPostDataChanged = new ArrayList ();
1071 requiresPostDataChanged.Add (pbdh);
1074 if (_requiresPostBackCopy != null)
1075 _requiresPostBackCopy.Remove (real_id);
1077 } else if (!second) {
1078 if (secondPostData == null)
1079 secondPostData = new NameValueCollection ();
1080 secondPostData.Add (real_id, data [id]);
1085 ArrayList list1 = null;
1086 if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
1087 string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
1088 foreach (string id in handlers) {
1089 IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
1091 _requiresPostBackCopy.Remove (id);
1092 if (pbdh.LoadPostData (id, data)) {
1093 if (requiresPostDataChanged == null)
1094 requiresPostDataChanged = new ArrayList ();
1096 requiresPostDataChanged.Add (pbdh);
1098 } else if (!second) {
1100 list1 = new ArrayList ();
1105 _requiresPostBackCopy = second ? null : list1;
1107 secondPostData = null;
1110 [EditorBrowsable (EditorBrowsableState.Never)]
1111 #if NET_2_0 || TARGET_JVM
1112 public virtual void ProcessRequest (HttpContext context)
1114 public void ProcessRequest (HttpContext context)
1118 _lifeCycle = PageLifeCycle.Unknown;
1121 if (clientTarget != null)
1122 Request.ClientTarget = clientTarget;
1124 WireupAutomaticEvents ();
1125 //-- Control execution lifecycle in the docs
1127 // Save culture information because it can be modified in FrameworkInitialize()
1128 CultureInfo culture = Thread.CurrentThread.CurrentCulture;
1129 CultureInfo uiculture = Thread.CurrentThread.CurrentUICulture;
1130 FrameworkInitialize ();
1131 context.ErrorPage = _errorPage;
1134 InternalProcessRequest ();
1135 } catch (ThreadAbortException) {
1136 // Do nothing, just ignore it by now.
1137 } catch (Exception e) {
1138 context.AddError (e); // OnError might access LastError
1139 OnError (EventArgs.Empty);
1140 context.ClearError (e);
1141 // We want to remove that error, as we're rethrowing to stop
1142 // further processing.
1143 Trace.Warn ("Unhandled Exception", e.ToString (), e);
1148 _lifeCycle = PageLifeCycle.Unload;
1151 UnloadRecursive (true);
1153 _lifeCycle = PageLifeCycle.End;
1156 if (Thread.CurrentThread.CurrentCulture.Equals (culture) == false)
1157 Thread.CurrentThread.CurrentCulture = culture;
1159 if (Thread.CurrentThread.CurrentUICulture.Equals (uiculture) == false)
1160 Thread.CurrentThread.CurrentUICulture = uiculture;
1165 internal void ProcessCrossPagePostBack (HttpContext context)
1167 isCrossPagePostBack = true;
1168 ProcessRequest (context);
1172 void InternalProcessRequest ()
1174 _requestValueCollection = this.DeterminePostBackMode();
1177 _lifeCycle = PageLifeCycle.Start;
1178 // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
1179 if (_requestValueCollection != null) {
1180 if (!isCrossPagePostBack && _requestValueCollection [PreviousPageID] != null && _requestValueCollection [PreviousPageID] != Request.FilePath) {
1181 _doLoadPreviousPage = true;
1184 isCallback = _requestValueCollection [CallbackArgumentID] != null;
1185 isPostBack = !isCallback;
1189 // if request was transfered from other page - track Prev. Page
1190 previousPage = _context.LastPage;
1191 _context.LastPage = this;
1193 _lifeCycle = PageLifeCycle.PreInit;
1194 OnPreInit (EventArgs.Empty);
1198 _lifeCycle = PageLifeCycle.Init;
1200 Trace.Write ("aspx.page", "Begin Init");
1201 InitRecursive (null);
1202 Trace.Write ("aspx.page", "End Init");
1205 _lifeCycle = PageLifeCycle.InitComplete;
1206 OnInitComplete (EventArgs.Empty);
1209 renderingForm = false;
1211 if (IsPostBack || IsCallback) {
1212 _lifeCycle = PageLifeCycle.PreLoad;
1213 if (_requestValueCollection != null)
1214 scriptManager.RestoreEventValidationState (_requestValueCollection [scriptManager.EventStateFieldName]);
1218 Trace.Write ("aspx.page", "Begin LoadViewState");
1219 LoadPageViewState ();
1220 Trace.Write ("aspx.page", "End LoadViewState");
1221 Trace.Write ("aspx.page", "Begin ProcessPostData");
1222 ProcessPostData (_requestValueCollection, false);
1223 Trace.Write ("aspx.page", "End ProcessPostData");
1227 OnPreLoad (EventArgs.Empty);
1228 _lifeCycle = PageLifeCycle.Load;
1233 if (IsPostBack || IsCallback) {
1234 _lifeCycle = PageLifeCycle.ControlEvents;
1238 Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
1239 ProcessPostData (secondPostData, true);
1240 Trace.Write ("aspx.page", "End ProcessPostData Second Try");
1241 Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
1242 RaiseChangedEvents ();
1243 Trace.Write ("aspx.page", "End Raise ChangedEvents");
1244 Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
1245 RaisePostBackEvents ();
1246 Trace.Write ("aspx.page", "End Raise PostBackEvent");
1250 _lifeCycle = PageLifeCycle.LoadComplete;
1251 OnLoadComplete (EventArgs.Empty);
1253 if (IsCrossPagePostBack)
1257 string result = ProcessCallbackData ();
1258 HtmlTextWriter callbackOutput = new HtmlTextWriter (_context.Response.Output);
1259 callbackOutput.Write (result);
1260 callbackOutput.Flush ();
1264 _lifeCycle = PageLifeCycle.PreRender;
1267 Trace.Write ("aspx.page", "Begin PreRender");
1268 PreRenderRecursiveInternal ();
1269 Trace.Write ("aspx.page", "End PreRender");
1272 _lifeCycle = PageLifeCycle.PreRenderComplete;
1273 OnPreRenderComplete (EventArgs.Empty);
1276 Trace.Write ("aspx.page", "Begin SaveViewState");
1277 SavePageViewState ();
1278 Trace.Write ("aspx.page", "End SaveViewState");
1281 _lifeCycle = PageLifeCycle.SaveStateComplete;
1282 OnSaveStateComplete (EventArgs.Empty);
1286 if (SaveViewStateForNextPortletRender())
1291 _lifeCycle = PageLifeCycle.Render;
1295 Trace.Write ("aspx.page", "Begin Render");
1296 HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
1297 RenderControl (output);
1298 Trace.Write ("aspx.page", "End Render");
1301 private void RenderTrace ()
1303 TraceManager traceManager = HttpRuntime.TraceManager;
1305 if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
1310 if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput)
1313 if (!traceManager.LocalOnly || Context.Request.IsLocal) {
1314 HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
1315 Trace.Render (output);
1320 bool CheckForValidationSupport (Control targetControl)
1322 if (targetControl == null)
1324 Type type = targetControl.GetType ();
1325 object[] attributes = type.GetCustomAttributes (true);
1326 foreach (object attr in attributes)
1327 if (attr is SupportsEventValidationAttribute)
1333 void RaisePostBackEvents ()
1336 Control targetControl;
1338 if (requiresRaiseEvent != null) {
1340 targetControl = requiresRaiseEvent as Control;
1341 if (targetControl != null && CheckForValidationSupport (targetControl))
1342 scriptManager.ValidateEvent (targetControl.UniqueID, null);
1344 RaisePostBackEvent (requiresRaiseEvent, null);
1348 NameValueCollection postdata = _requestValueCollection;
1349 if (postdata == null)
1352 string eventTarget = postdata [postEventSourceID];
1353 if (eventTarget == null || eventTarget.Length == 0) {
1359 targetControl = FindControl (eventTarget);
1360 IPostBackEventHandler target = targetControl as IPostBackEventHandler;
1362 IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
1368 string eventArgument = postdata [postEventArgumentID];
1370 if (CheckForValidationSupport (targetControl))
1371 scriptManager.ValidateEvent (targetControl.UniqueID, eventArgument);
1373 RaisePostBackEvent (target, eventArgument);
1376 internal void RaiseChangedEvents ()
1378 if (requiresPostDataChanged == null)
1381 foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
1382 ipdh.RaisePostDataChangedEvent ();
1384 requiresPostDataChanged = null;
1387 [EditorBrowsable (EditorBrowsableState.Advanced)]
1388 protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
1390 sourceControl.RaisePostBackEvent (eventArgument);
1396 [EditorBrowsable (EditorBrowsableState.Advanced)]
1397 public void RegisterArrayDeclaration (string arrayName, string arrayValue)
1399 scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
1405 [EditorBrowsable (EditorBrowsableState.Advanced)]
1406 public virtual void RegisterClientScriptBlock (string key, string script)
1408 scriptManager.RegisterClientScriptBlock (key, script);
1414 [EditorBrowsable (EditorBrowsableState.Advanced)]
1415 public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
1417 scriptManager.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
1420 [MonoTODO("Not implemented, Used in HtmlForm")]
1421 internal void RegisterClientScriptFile (string a, string b, string c)
1423 throw new NotImplementedException ();
1429 [EditorBrowsable (EditorBrowsableState.Advanced)]
1430 public void RegisterOnSubmitStatement (string key, string script)
1432 scriptManager.RegisterOnSubmitStatement (key, script);
1435 internal string GetSubmitStatements ()
1437 return scriptManager.WriteSubmitStatements ();
1440 [EditorBrowsable (EditorBrowsableState.Advanced)]
1441 public void RegisterRequiresPostBack (Control control)
1443 if (_requiresPostBack == null)
1444 _requiresPostBack = new ArrayList ();
1446 if (_requiresPostBack.Contains (control.UniqueID))
1449 _requiresPostBack.Add (control.UniqueID);
1452 [EditorBrowsable (EditorBrowsableState.Advanced)]
1453 public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
1455 requiresRaiseEvent = control;
1461 [EditorBrowsable (EditorBrowsableState.Advanced)]
1462 public virtual void RegisterStartupScript (string key, string script)
1464 scriptManager.RegisterStartupScript (key, script);
1467 [EditorBrowsable (EditorBrowsableState.Advanced)]
1468 public void RegisterViewStateHandler ()
1470 handleViewState = true;
1473 [EditorBrowsable (EditorBrowsableState.Advanced)]
1474 protected virtual void SavePageStateToPersistenceMedium (object viewState)
1476 PageStatePersister persister = this.PageStatePersister;
1477 if (persister == null)
1479 Pair pair = viewState as Pair;
1481 persister.ViewState = pair.First;
1482 persister.ControlState = pair.Second;
1484 persister.ViewState = viewState;
1488 internal string RawViewState {
1490 NameValueCollection postdata = _requestValueCollection;
1492 if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
1495 if (view_state == "")
1499 set { _savedViewState = value; }
1507 PageStatePersister PageStatePersister {
1509 if (page_state_persister == null)
1510 page_state_persister = new HiddenFieldPageStatePersister (this);
1511 return page_state_persister;
1515 [EditorBrowsable (EditorBrowsableState.Advanced)]
1516 protected virtual object LoadPageStateFromPersistenceMedium ()
1518 PageStatePersister persister = this.PageStatePersister;
1519 if (persister == null)
1522 return new Pair (persister.ViewState, persister.ControlState);
1525 internal void LoadPageViewState()
1527 Pair sState = LoadPageStateFromPersistenceMedium () as Pair;
1528 if (sState != null) {
1531 LoadPageControlState (sState.Second);
1533 Pair vsr = sState.First as Pair;
1535 LoadViewStateRecursive (vsr.First);
1536 _requiresPostBackCopy = vsr.Second as ArrayList;
1542 internal void SavePageViewState ()
1544 if (!handleViewState)
1548 object controlState = SavePageControlState ();
1551 object viewState = SaveViewStateRecursive ();
1552 object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
1555 if (viewState != null || reqPostback != null)
1556 vsr = new Pair (viewState, reqPostback);
1557 Pair pair = new Pair ();
1561 pair.Second = controlState;
1565 if (pair.First == null && pair.Second == null)
1566 SavePageStateToPersistenceMedium (null);
1568 SavePageStateToPersistenceMedium (pair);
1572 public virtual void Validate ()
1574 is_validated = true;
1575 ValidateCollection (_validators);
1579 internal bool AreValidatorsUplevel () {
1580 return AreValidatorsUplevel (String.Empty);
1583 internal bool AreValidatorsUplevel (string valGroup)
1585 internal virtual bool AreValidatorsUplevel ()
1588 bool uplevel = false;
1590 foreach (IValidator v in Validators) {
1591 BaseValidator bv = v as BaseValidator;
1592 if (bv == null) continue;
1595 if (valGroup != bv.ValidationGroup)
1598 if (bv.GetRenderUplevel()) {
1607 bool ValidateCollection (ValidatorCollection validators)
1610 if (!_eventValidation)
1614 if (validators == null || validators.Count == 0)
1617 bool all_valid = true;
1618 foreach (IValidator v in validators){
1620 if (v.IsValid == false)
1627 [EditorBrowsable (EditorBrowsableState.Advanced)]
1628 public virtual void VerifyRenderingInServerForm (Control control)
1630 if (_context == null)
1634 throw new HttpException ("Control '" +
1637 control.GetType ().Name +
1638 "' must be placed inside a form tag with runat=server.");
1641 protected override void FrameworkInitialize ()
1643 base.FrameworkInitialize ();
1645 InitializeStyleSheet ();
1656 ClientScriptManager ClientScript {
1657 get { return scriptManager; }
1662 static readonly object InitCompleteEvent = new object ();
1663 static readonly object LoadCompleteEvent = new object ();
1664 static readonly object PreInitEvent = new object ();
1665 static readonly object PreLoadEvent = new object ();
1666 static readonly object PreRenderCompleteEvent = new object ();
1667 static readonly object SaveStateCompleteEvent = new object ();
1669 const int initcomplete_mask = 1;
1670 const int loadcomplete_mask = 1 << 1;
1671 const int preinit_mask = 1 << 2;
1672 const int preload_mask = 1 << 3;
1673 const int prerendercomplete_mask = 1 << 4;
1674 const int savestatecomplete_mask = 1 << 5;
1676 [EditorBrowsable (EditorBrowsableState.Advanced)]
1677 public event EventHandler InitComplete {
1679 event_mask |= initcomplete_mask;
1680 Events.AddHandler (InitCompleteEvent, value);
1682 remove { Events.RemoveHandler (InitCompleteEvent, value); }
1685 [EditorBrowsable (EditorBrowsableState.Advanced)]
1686 public event EventHandler LoadComplete {
1688 event_mask |= loadcomplete_mask;
1689 Events.AddHandler (LoadCompleteEvent, value);
1691 remove { Events.RemoveHandler (LoadCompleteEvent, value); }
1694 public event EventHandler PreInit {
1696 event_mask |= preinit_mask;
1697 Events.AddHandler (PreInitEvent, value);
1699 remove { Events.RemoveHandler (PreInitEvent, value); }
1702 [EditorBrowsable (EditorBrowsableState.Advanced)]
1703 public event EventHandler PreLoad {
1705 event_mask |= preload_mask;
1706 Events.AddHandler (PreLoadEvent, value);
1708 remove { Events.RemoveHandler (PreLoadEvent, value); }
1711 [EditorBrowsable (EditorBrowsableState.Advanced)]
1712 public event EventHandler PreRenderComplete {
1714 event_mask |= prerendercomplete_mask;
1715 Events.AddHandler (PreRenderCompleteEvent, value);
1717 remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
1720 [EditorBrowsable (EditorBrowsableState.Advanced)]
1721 public event EventHandler SaveStateComplete {
1723 event_mask |= savestatecomplete_mask;
1724 Events.AddHandler (SaveStateCompleteEvent, value);
1726 remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
1729 protected virtual void OnInitComplete (EventArgs e)
1731 if ((event_mask & initcomplete_mask) != 0) {
1732 EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
1733 if (eh != null) eh (this, e);
1737 protected virtual void OnLoadComplete (EventArgs e)
1739 if ((event_mask & loadcomplete_mask) != 0) {
1740 EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
1741 if (eh != null) eh (this, e);
1745 protected virtual void OnPreInit (EventArgs e)
1747 if ((event_mask & preinit_mask) != 0) {
1748 EventHandler eh = (EventHandler) (Events [PreInitEvent]);
1749 if (eh != null) eh (this, e);
1753 protected virtual void OnPreLoad (EventArgs e)
1755 if ((event_mask & preload_mask) != 0) {
1756 EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
1757 if (eh != null) eh (this, e);
1761 protected virtual void OnPreRenderComplete (EventArgs e)
1763 if ((event_mask & prerendercomplete_mask) != 0) {
1764 EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
1765 if (eh != null) eh (this, e);
1770 if (!Form.DetermineRenderUplevel ())
1773 /* figure out if we have some control we're going to focus */
1774 if (String.IsNullOrEmpty (_focusedControlID)) {
1775 _focusedControlID = Form.DefaultFocus;
1776 if (String.IsNullOrEmpty (_focusedControlID))
1777 _focusedControlID = Form.DefaultButton;
1780 if (!String.IsNullOrEmpty (_focusedControlID) || Form.SubmitDisabledControls) {
1782 RequiresPostBackScript ();
1783 ClientScript.RegisterWebFormClientScript ();
1785 if (!String.IsNullOrEmpty (_focusedControlID)) {
1786 ClientScript.RegisterStartupScript ("HtmlForm-DefaultButton-StartupScript",
1787 String.Format ("<script type=\"text/javascript\">\n" +
1789 "WebForm_AutoFocus('{0}');// -->\n" +
1790 "</script>\n", _focusedControlID));
1793 if (Form.SubmitDisabledControls) {
1794 ClientScript.RegisterOnSubmitStatement ("HtmlForm-SubmitDisabledControls-SubmitStatement",
1795 "javascript: return WebForm_OnSubmit();");
1796 ClientScript.RegisterStartupScript ("HtmlForm-SubmitDisabledControls-StartupScript",
1797 @"<script language=""JavaScript"">
1799 function WebForm_OnSubmit() {
1800 WebForm_ReEnableControls();
1808 protected virtual void OnSaveStateComplete (EventArgs e)
1810 if ((event_mask & savestatecomplete_mask) != 0) {
1811 EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
1812 if (eh != null) eh (this, e);
1816 public HtmlForm Form {
1817 get { return _form; }
1820 internal void RegisterForm (HtmlForm form)
1825 [BrowsableAttribute (false)]
1826 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1827 public Page PreviousPage {
1829 if (_doLoadPreviousPage) {
1830 _doLoadPreviousPage = false;
1831 LoadPreviousPageReference ();
1833 return previousPage;
1838 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1839 [BrowsableAttribute (false)]
1840 public bool IsCallback {
1841 get { return isCallback; }
1844 [BrowsableAttribute (false)]
1845 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1846 public bool IsCrossPagePostBack {
1847 get { return isCrossPagePostBack; }
1850 public new virtual char IdSeparator {
1852 //TODO: why override?
1853 return base.IdSeparator;
1857 string ProcessCallbackData ()
1859 string callbackTarget = _requestValueCollection [CallbackSourceID];
1860 if (callbackTarget == null || callbackTarget.Length == 0)
1861 throw new HttpException ("Callback target not provided.");
1863 Control targetControl = FindControl (callbackTarget);
1864 ICallbackEventHandler target = targetControl as ICallbackEventHandler;
1866 throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
1868 string callbackArgument = _requestValueCollection [CallbackArgumentID];
1869 target.RaiseCallbackEvent (callbackArgument);
1870 return target.GetCallbackResult ();
1873 [BrowsableAttribute (false)]
1874 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1875 public HtmlHead Header {
1876 get { return htmlHeader; }
1879 internal void SetHeader (HtmlHead header)
1881 htmlHeader = header;
1882 if (_title != null) {
1883 htmlHeader.Title = _title;
1888 [MonoTODO("Not Implemented")]
1889 protected bool AsyncMode {
1891 throw new NotImplementedException ();
1894 throw new NotImplementedException ();
1898 [MonoTODO ("Not Implemented")]
1899 public TimeSpan AsyncTimeout {
1901 throw new NotImplementedException ();
1904 throw new NotImplementedException ();
1908 [MonoTODO ("Not Implemented")]
1909 public bool IsAsync {
1911 throw new NotImplementedException ();
1915 [MonoTODO ("Not Implemented")]
1916 protected internal virtual string UniqueFilePathSuffix {
1918 throw new NotImplementedException ();
1922 [MonoTODO ("Not Implemented")]
1923 public int MaxPageStateFieldLength {
1925 throw new NotImplementedException ();
1928 throw new NotImplementedException ();
1932 [MonoTODO ("Not Implemented")]
1933 public ViewStateEncryptionMode ViewStateEncryptionMode {
1935 throw new NotImplementedException ();
1938 throw new NotImplementedException ();
1942 [MonoTODO ("Not Implemented")]
1943 public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler)
1945 throw new NotImplementedException ();
1948 [MonoTODO ("Not Implemented")]
1949 public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, Object state)
1951 throw new NotImplementedException ();
1954 [MonoTODO ("Not Implemented")]
1955 public void ExecuteRegisteredAsyncTasks ()
1957 throw new NotImplementedException ();
1960 [MonoTODO ("Not Implemented")]
1961 public static HtmlTextWriter CreateHtmlTextWriterFromType (TextWriter tw, Type writerType)
1963 throw new NotImplementedException ();
1966 [MonoTODO ("Not Implemented")]
1967 public void RegisterRequiresViewStateEncryption ()
1969 throw new NotImplementedException ();
1972 void ApplyMasterPage ()
1974 if (masterPageFile != null && masterPageFile.Length > 0) {
1975 ArrayList appliedMasterPageFiles = new ArrayList ();
1977 if (Master != null) {
1978 MasterPage.ApplyMasterPageRecursive (Master, appliedMasterPageFiles);
1982 Controls.Add (Master);
1987 [DefaultValueAttribute ("")]
1988 public virtual string MasterPageFile {
1989 get { return masterPageFile; }
1991 masterPageFile = value;
1996 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1997 [BrowsableAttribute (false)]
1998 public MasterPage Master {
2000 if (Context == null || String.IsNullOrEmpty (masterPageFile))
2003 if (masterPage == null)
2004 masterPage = MasterPage.CreateMasterPage (this, Context, masterPageFile, contentTemplates);
2010 public void SetFocus (string clientID)
2012 if (String.IsNullOrEmpty (clientID))
2013 throw new ArgumentNullException ("control");
2015 if (_lifeCycle > PageLifeCycle.PreRender)
2016 throw new InvalidOperationException ("SetFocus can only be called before and during PreRender.");
2019 throw new InvalidOperationException ("A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.");
2021 _focusedControlID = clientID;
2024 public void SetFocus (Control control)
2026 if (control == null)
2027 throw new ArgumentNullException ("control");
2029 SetFocus (control.ClientID);
2032 [EditorBrowsable (EditorBrowsableState.Advanced)]
2033 public void RegisterRequiresControlState (Control control)
2035 if (control == null)
2036 throw new ArgumentNullException ("control");
2038 if (RequiresControlState (control))
2041 if (requireStateControls == null)
2042 requireStateControls = new ArrayList ();
2043 int n = requireStateControls.Add (control);
2045 if (_savedControlState == null || n >= _savedControlState.Length)
2048 for (Control parent = control.Parent; parent != null; parent = parent.Parent)
2049 if (parent.IsChildControlStateCleared)
2052 object state = _savedControlState [n];
2054 control.LoadControlState (state);
2057 public bool RequiresControlState (Control control)
2059 if (requireStateControls == null) return false;
2060 return requireStateControls.Contains (control);
2063 [EditorBrowsable (EditorBrowsableState.Advanced)]
2064 public void UnregisterRequiresControlState (Control control)
2066 if (requireStateControls != null)
2067 requireStateControls.Remove (control);
2070 public ValidatorCollection GetValidators (string validationGroup)
2072 string valgr = validationGroup;
2074 valgr = String.Empty;
2076 if (_validatorsByGroup == null) _validatorsByGroup = new Hashtable ();
2077 ValidatorCollection col = _validatorsByGroup [valgr] as ValidatorCollection;
2079 col = new ValidatorCollection ();
2080 _validatorsByGroup [valgr] = col;
2085 public virtual void Validate (string validationGroup)
2087 is_validated = true;
2088 if (validationGroup == null)
2089 ValidateCollection (_validatorsByGroup [String.Empty] as ValidatorCollection);
2090 else if (_validatorsByGroup != null) {
2091 ValidateCollection (_validatorsByGroup [validationGroup] as ValidatorCollection);
2095 object SavePageControlState ()
2097 if (requireStateControls == null) return null;
2098 object[] state = new object [requireStateControls.Count];
2100 bool allNull = true;
2101 for (int n=0; n<state.Length; n++) {
2102 state [n] = ((Control) requireStateControls [n]).SaveControlState ();
2103 if (state [n] != null) allNull = false;
2105 if (allNull) return null;
2109 void LoadPageControlState (object data)
2111 _savedControlState = (object []) data;
2113 if (requireStateControls == null) return;
2115 int max = Math.Min (requireStateControls.Count, _savedControlState != null ? _savedControlState.Length : requireStateControls.Count);
2116 for (int n=0; n < max; n++) {
2117 Control ctl = (Control) requireStateControls [n];
2118 ctl.LoadControlState (_savedControlState != null ? _savedControlState [n] : null);
2122 void LoadPreviousPageReference ()
2124 if (_requestValueCollection != null) {
2125 string prevPage = _requestValueCollection [PreviousPageID];
2126 if (prevPage != null) {
2127 previousPage = (Page) PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
2128 previousPage.ProcessCrossPagePostBack (_context);
2134 Hashtable contentTemplates;
2135 [EditorBrowsable (EditorBrowsableState.Never)]
2136 protected internal void AddContentTemplate (string templateName, ITemplate template)
2138 if (contentTemplates == null)
2139 contentTemplates = new Hashtable ();
2140 contentTemplates [templateName] = template;
2143 PageTheme _pageTheme;
2144 internal PageTheme PageTheme {
2145 get { return _pageTheme; }
2148 PageTheme _styleSheetPageTheme;
2149 internal PageTheme StyleSheetPageTheme {
2150 get { return _styleSheetPageTheme; }
2155 internal void PushDataItemContext (object o) {
2156 if (dataItemCtx == null)
2157 dataItemCtx = new Stack ();
2159 dataItemCtx.Push (o);
2162 internal void PopDataItemContext () {
2163 if (dataItemCtx == null)
2164 throw new InvalidOperationException ();
2169 public object GetDataItem() {
2170 if (dataItemCtx == null || dataItemCtx.Count == 0)
2171 throw new InvalidOperationException ("No data item");
2173 return dataItemCtx.Peek ();
2176 protected internal override void OnInit (EventArgs e)
2182 ArrayList themes = new ArrayList();
2184 if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
2185 themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
2186 if (PageTheme != null && PageTheme.GetStyleSheets () != null)
2187 themes.AddRange (PageTheme.GetStyleSheets ());
2189 foreach (string lss in themes) {
2190 HtmlLink hl = new HtmlLink ();
2191 hl.Href = ResolveUrl (lss);
2192 hl.Attributes["type"] = "text/css";
2193 hl.Attributes["rel"] = "stylesheet";
2194 Header.Controls.Add (hl);
2201 [MonoTODO ("Not implemented. Only used by .net aspx parser")]
2202 protected object GetWrappedFileDependencies (string [] list)
2207 [MonoTODO ("Does nothing. Used by .net aspx parser")]
2208 protected virtual void InitializeCulture ()
2212 [MonoTODO ("Does nothing. Used by .net aspx parser")]
2213 protected internal void AddWrappedFileDependencies (object virtualFileDependencies)