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 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 object _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)
104 [EditorBrowsable (EditorBrowsableState.Never)]
110 const string postEventArgumentID = "__EVENTARGUMENT";
112 [EditorBrowsable (EditorBrowsableState.Never)]
118 const string postEventSourceID = "__EVENTTARGET";
121 const string ScrollPositionXID = "__SCROLLPOSITIONX";
122 const string ScrollPositionYID = "__SCROLLPOSITIONY";
126 internal const string CallbackArgumentID = "__CALLBACKARGUMENT";
127 internal const string CallbackSourceID = "__CALLBACKTARGET";
128 internal const string PreviousPageID = "__PREVIOUSPAGE";
132 MasterPage masterPage;
133 string masterPageFile;
136 bool isCrossPagePostBack;
139 ArrayList requireStateControls;
140 Hashtable _validatorsByGroup;
145 string _styleSheetTheme;
148 bool _maintainScrollPositionOnPostBack;
154 scriptManager = new ClientScriptManager (this);
163 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
165 public HttpApplicationState Application
168 if (_context == null)
170 return _context.Application;
174 [EditorBrowsable (EditorBrowsableState.Never)]
175 protected bool AspCompatMode
178 get { return false; }
180 set { throw new NotImplementedException (); }
183 [EditorBrowsable (EditorBrowsableState.Never)]
185 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
186 [BrowsableAttribute (false)]
189 get { return Response.BufferOutput; }
190 set { Response.BufferOutput = value; }
193 protected bool Buffer
195 set { Response.BufferOutput = value; }
199 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
204 if (_context == null)
205 throw new HttpException ("No cache available without a context.");
206 return _context.Cache;
211 [EditorBrowsableAttribute (EditorBrowsableState.Advanced)]
213 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
214 [Browsable (false), DefaultValue ("")]
215 [WebSysDescription ("Value do override the automatic browser detection and force the page to use the specified browser.")]
216 public string ClientTarget
218 get { return (clientTarget == null) ? "" : clientTarget; }
220 clientTarget = value;
226 [EditorBrowsable (EditorBrowsableState.Never)]
228 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
229 [BrowsableAttribute (false)]
232 get { return Response.ContentEncoding.CodePage; }
233 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
236 protected int CodePage
238 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
242 [EditorBrowsable (EditorBrowsableState.Never)]
244 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
245 [BrowsableAttribute (false)]
246 public string ContentType
248 get { return Response.ContentType; }
249 set { Response.ContentType = value; }
252 protected string ContentType
254 set { Response.ContentType = value; }
258 protected override HttpContext Context
261 if (_context == null)
262 return HttpContext.Current;
269 [EditorBrowsable (EditorBrowsableState.Advanced)]
270 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
271 [BrowsableAttribute (false)]
272 public string Culture
274 get { return Thread.CurrentThread.CurrentCulture.Name; }
275 set { Thread.CurrentThread.CurrentCulture = GetPageCulture (value, Thread.CurrentThread.CurrentCulture); }
278 [EditorBrowsable (EditorBrowsableState.Never)]
279 protected string Culture
281 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
286 public virtual bool EnableEventValidation {
287 get { return _eventValidation; }
289 if (_lifeCycle > PageLifeCycle.Init)
290 throw new InvalidOperationException ("The 'EnableEventValidation' property can be set only in the Page_init, the Page directive or in the <pages> configuration section.");
291 _eventValidation = value;
295 internal PageLifeCycle LifeCycle {
296 get { return _lifeCycle; }
301 public override bool EnableViewState
303 get { return _viewState; }
304 set { _viewState = value; }
308 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
309 [BrowsableAttribute (false)]
311 [EditorBrowsable (EditorBrowsableState.Never)]
317 bool EnableViewStateMac
319 get { return _viewStateMac; }
320 set { _viewStateMac = value; }
323 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
324 [Browsable (false), DefaultValue ("")]
325 [WebSysDescription ("The URL of a page used for error redirection.")]
326 public string ErrorPage
328 get { return _errorPage; }
331 if (_context != null)
332 _context.ErrorPage = value;
339 [EditorBrowsable (EditorBrowsableState.Never)]
340 protected ArrayList FileDependencies
343 if (Response != null)
344 Response.AddFileDependencies (value);
350 [EditorBrowsable (EditorBrowsableState.Never)]
352 public override string ID
354 get { return base.ID; }
355 set { base.ID = value; }
358 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
360 public bool IsPostBack
366 return _requestValueCollection != null;
371 [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
372 public bool IsReusable {
373 get { return false; }
376 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
378 public bool IsValid {
381 throw new HttpException (Locale.GetText ("Page hasn't been validated."));
384 foreach (IValidator val in Validators)
389 return ValidateCollection (_validators);
394 public IDictionary Items {
397 items = new Hashtable ();
403 [EditorBrowsable (EditorBrowsableState.Never)]
405 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
406 [BrowsableAttribute (false)]
408 get { return Thread.CurrentThread.CurrentCulture.LCID; }
409 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
413 set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
419 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
420 public bool MaintainScrollPositionOnPostBack {
421 get { return _maintainScrollPositionOnPostBack; }
422 set { _maintainScrollPositionOnPostBack = value; }
427 public PageAdapter PageAdapter {
429 return (PageAdapter)Adapter;
434 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
436 public HttpRequest Request
439 if (_context != null)
440 return _context.Request;
442 throw new HttpException("Request is not available without context");
446 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
448 public HttpResponse Response
451 if (_context != null)
452 return _context.Response;
454 throw new HttpException ("Response is not available without context");
458 [EditorBrowsable (EditorBrowsableState.Never)]
460 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
461 [BrowsableAttribute (false)]
462 public string ResponseEncoding
464 get { return Response.ContentEncoding.WebName; }
465 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
468 protected string ResponseEncoding
470 set { Response.ContentEncoding = Encoding.GetEncoding (value); }
474 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
476 public HttpServerUtility Server
479 return Context.Server;
483 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
485 public virtual HttpSessionState Session
488 if (_context == null)
489 _context = HttpContext.Current;
491 if (_context == null)
492 throw new HttpException ("Session is not available without context");
494 if (_context.Session == null)
495 throw new HttpException ("Session state can only be used " +
496 "when enableSessionState is set to true, either " +
497 "in a configuration file or in the Page directive.");
499 return _context.Session;
504 [FilterableAttribute (false)]
508 public bool SmartNavigation
510 get { return _smartNavigation; }
511 set { _smartNavigation = value; }
515 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
518 public virtual string StyleSheetTheme {
519 get { return _styleSheetTheme; }
520 set { _styleSheetTheme = value; }
524 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
525 public virtual string Theme {
526 get { return _theme; }
527 set { _theme = value; }
530 void InitializeStyleSheet ()
532 if (_styleSheetTheme == null) {
533 PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
535 _styleSheetTheme = ps.StyleSheetTheme;
537 if (_styleSheetTheme != null && _styleSheetTheme != "")
538 _styleSheetPageTheme = ThemeDirectoryCompiler.GetCompiledInstance ("~/App_Themes/" + _styleSheetTheme + "/", _context);
541 void InitializeTheme ()
543 if (_theme == null) {
544 PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
548 if (_theme != null && _theme != "") {
549 _pageTheme = ThemeDirectoryCompiler.GetCompiledInstance ("~/App_Themes/" + _theme + "/", _context);
558 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
559 public string Title {
562 return htmlHeader.Title;
566 if (htmlHeader != null)
567 htmlHeader.Title = value;
574 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
576 public TraceContext Trace
578 get { return Context.Trace; }
581 [EditorBrowsable (EditorBrowsableState.Never)]
583 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
584 [BrowsableAttribute (false)]
585 public bool TraceEnabled
587 get { return Trace.IsEnabled; }
588 set { Trace.IsEnabled = value; }
591 protected bool TraceEnabled
593 set { Trace.IsEnabled = value; }
597 [EditorBrowsable (EditorBrowsableState.Never)]
599 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
600 [BrowsableAttribute (false)]
601 public TraceMode TraceModeValue
603 get { return Trace.TraceMode; }
604 set { Trace.TraceMode = value; }
607 protected TraceMode TraceModeValue
609 set { Trace.TraceMode = value; }
613 [EditorBrowsable (EditorBrowsableState.Never)]
614 protected int TransactionMode
617 get { return _transactionMode; }
619 set { _transactionMode = value; }
623 [EditorBrowsable (EditorBrowsableState.Advanced)]
624 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
625 [BrowsableAttribute (false)]
626 public string UICulture
628 get { return Thread.CurrentThread.CurrentUICulture.Name; }
629 set { Thread.CurrentThread.CurrentUICulture = GetPageCulture (value, Thread.CurrentThread.CurrentUICulture); }
632 [EditorBrowsable (EditorBrowsableState.Never)]
633 protected string UICulture
635 set { Thread.CurrentThread.CurrentUICulture = new CultureInfo (value); }
639 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
641 public IPrincipal User
643 get { return Context.User; }
646 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
648 public ValidatorCollection Validators
651 if (_validators == null)
652 _validators = new ValidatorCollection ();
657 [MonoTODO ("Use this when encrypting/decrypting ViewState")]
659 public string ViewStateUserKey {
660 get { return viewStateUserKey; }
661 set { viewStateUserKey = value; }
665 public override bool Visible
667 get { return base.Visible; }
668 set { base.Visible = value; }
676 CultureInfo GetPageCulture (string culture, CultureInfo deflt)
680 CultureInfo ret = null;
681 if (culture.StartsWith ("auto")) {
682 string[] languages = Request.UserLanguages;
684 if (languages != null && languages.Length > 0)
685 ret = new CultureInfo (languages[0]);
692 ret = new CultureInfo (culture);
698 [EditorBrowsable (EditorBrowsableState.Never)]
699 protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
703 throw new NotImplementedException ();
706 [EditorBrowsable (EditorBrowsableState.Never)]
707 protected void AspCompatEndProcessRequest (IAsyncResult result)
709 throw new NotImplementedException ();
712 [EditorBrowsable (EditorBrowsableState.Advanced)]
713 protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
715 return new HtmlTextWriter (tw);
718 [EditorBrowsable (EditorBrowsableState.Never)]
719 public void DesignerInitialize ()
721 InitRecursive (null);
724 [EditorBrowsable (EditorBrowsableState.Advanced)]
725 protected virtual NameValueCollection DeterminePostBackMode ()
727 if (_context == null)
730 HttpRequest req = _context.Request;
734 NameValueCollection coll = null;
735 if (0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture)) {
737 WebROCollection c = (WebROCollection) coll;
738 allow_load = !c.GotID;
740 c.ID = GetTypeHashCode ();
742 allow_load = (c.ID == GetTypeHashCode ());
745 coll = req.QueryString;
748 if (coll != null && coll ["__VIEWSTATE"] == null && coll ["__EVENTTARGET"] == null)
755 public override Control FindControl (string id) {
759 return base.FindControl (id);
766 [EditorBrowsable (EditorBrowsableState.Advanced)]
767 public string GetPostBackClientEvent (Control control, string argument)
769 return scriptManager.GetPostBackEventReference (control, argument);
775 [EditorBrowsable (EditorBrowsableState.Advanced)]
776 public string GetPostBackClientHyperlink (Control control, string argument)
778 return scriptManager.GetPostBackClientHyperlink (control, argument);
784 [EditorBrowsable (EditorBrowsableState.Advanced)]
785 public string GetPostBackEventReference (Control control)
787 return scriptManager.GetPostBackEventReference (control, "");
793 [EditorBrowsable (EditorBrowsableState.Advanced)]
794 public string GetPostBackEventReference (Control control, string argument)
796 return scriptManager.GetPostBackEventReference (control, argument);
799 internal void RequiresPostBackScript ()
801 requiresPostBackScript = true;
804 [EditorBrowsable (EditorBrowsableState.Never)]
805 public virtual int GetTypeHashCode ()
811 [MonoTODO("The following properties of OutputCacheParameters are silently ignored: CacheProfile, NoStore, SqlDependency")]
812 protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings)
814 if (cacheSettings.Enabled)
815 InitOutputCache(cacheSettings.Duration,
816 cacheSettings.VaryByHeader,
817 cacheSettings.VaryByCustom,
818 cacheSettings.Location,
819 cacheSettings.VaryByParam);
823 [EditorBrowsable (EditorBrowsableState.Never)]
824 protected virtual void InitOutputCache (int duration,
827 OutputCacheLocation location,
830 HttpCachePolicy cache = _context.Response.Cache;
831 bool set_vary = false;
834 case OutputCacheLocation.Any:
835 cache.SetCacheability (HttpCacheability.Public);
836 cache.SetMaxAge (new TimeSpan (0, 0, duration));
837 cache.SetLastModified (_context.Timestamp);
840 case OutputCacheLocation.Client:
841 cache.SetCacheability (HttpCacheability.Private);
842 cache.SetMaxAge (new TimeSpan (0, 0, duration));
843 cache.SetLastModified (_context.Timestamp);
845 case OutputCacheLocation.Downstream:
846 cache.SetCacheability (HttpCacheability.Public);
847 cache.SetMaxAge (new TimeSpan (0, 0, duration));
848 cache.SetLastModified (_context.Timestamp);
850 case OutputCacheLocation.Server:
851 cache.SetCacheability (HttpCacheability.Server);
854 case OutputCacheLocation.None:
859 if (varyByCustom != null)
860 cache.SetVaryByCustom (varyByCustom);
862 if (varyByParam != null && varyByParam.Length > 0) {
863 string[] prms = varyByParam.Split (';');
864 foreach (string p in prms)
865 cache.VaryByParams [p.Trim ()] = true;
866 cache.VaryByParams.IgnoreParams = false;
868 cache.VaryByParams.IgnoreParams = true;
871 if (varyByHeader != null && varyByHeader.Length > 0) {
872 string[] hdrs = varyByHeader.Split (';');
873 foreach (string h in hdrs)
874 cache.VaryByHeaders [h.Trim ()] = true;
878 cache.Duration = duration;
879 cache.SetExpires (_context.Timestamp.AddSeconds (duration));
885 [EditorBrowsable (EditorBrowsableState.Advanced)]
887 public bool IsClientScriptBlockRegistered (string key)
889 return scriptManager.IsClientScriptBlockRegistered (key);
895 [EditorBrowsable (EditorBrowsableState.Advanced)]
897 public bool IsStartupScriptRegistered (string key)
899 return scriptManager.IsStartupScriptRegistered (key);
902 public string MapPath (string virtualPath)
904 return Request.MapPath (virtualPath);
908 protected internal override void Render (HtmlTextWriter writer) {
909 if (MaintainScrollPositionOnPostBack) {
910 RequiresPostBackScript ();
912 string scriptUrl = ClientScript.GetWebResourceUrl (typeof (Page), "MaintainScrollPositionOnPostBack.js");
914 ClientScript.RegisterClientScriptInclude (typeof (Page), "MaintainScrollPositionOnPostBack.js", scriptUrl);
916 ClientScript.RegisterHiddenField (ScrollPositionXID, Request [ScrollPositionXID]);
917 ClientScript.RegisterHiddenField (ScrollPositionYID, Request [ScrollPositionYID]);
919 StringBuilder script = new StringBuilder ();
920 script.AppendLine ("<script type=\"text/javascript\">");
921 script.AppendLine ("<!--");
922 script.AppendLine ("theForm.oldSubmit = theForm.submit");
923 script.AppendLine ("theForm.submit = WebForm_SaveScrollPositionSubmit");
924 script.AppendLine ("theForm.oldOnSubmit = theForm.onsubmit");
925 script.AppendLine ("theForm.onsubmit = WebForm_SaveScrollPositionOnSubmit");
927 script.AppendLine ("theForm.oldOnLoad = window.onload");
928 script.AppendLine ("window.onload = WebForm_RestoreScrollPosition");
930 script.AppendLine ("// -->");
931 script.AppendLine ("</script>");
933 ClientScript.RegisterStartupScript (typeof (Page), "MaintainScrollPositionOnPostBackStartup", script.ToString());
935 base.Render (writer);
939 private void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
941 writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventSourceID);
942 writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventArgumentID);
944 writer.WriteLine ("<script language=\"javascript\">");
945 writer.WriteLine ("<!--");
947 writer.WriteLine ("\tvar theForm;\n\tif (document.getElementById) {{ theForm = document.getElementById ('{0}'); }}", formUniqueID);
948 writer.WriteLine ("\telse {{ theForm = document.{0}; }}", formUniqueID);
949 writer.WriteLine ("\tfunction __doPostBack(eventTarget, eventArgument) {");
950 writer.WriteLine ("\t\ttheForm.{0}.value = eventTarget;", postEventSourceID);
951 writer.WriteLine ("\t\ttheForm.{0}.value = eventArgument;", postEventArgumentID);
952 writer.WriteLine ("\t\ttheForm.submit();");
953 writer.WriteLine ("\t}");
954 writer.WriteLine ("// -->");
955 writer.WriteLine ("</script>");
958 internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
961 throw new HttpException ("Only 1 HtmlForm is allowed per page.");
963 renderingForm = true;
965 scriptManager.WriteHiddenFields (writer);
966 if (requiresPostBackScript) {
967 RenderPostBackScript (writer, formUniqueID);
968 postBackScriptRendered = true;
971 if (handleViewState) {
972 string vs = GetViewStateString ();
973 writer.Write ("<input type=\"hidden\" name=\"__VIEWSTATE\" ");
974 writer.WriteLine ("value=\"{0}\" />", vs);
977 scriptManager.WriteClientScriptBlocks (writer);
980 internal LosFormatter GetFormatter ()
983 PagesSection config = (PagesSection) WebConfigurationManager.GetSection ("system.web/pages");
985 PagesConfiguration config = PagesConfiguration.GetInstance (_context);
988 if (config.EnableViewStateMac) {
990 MachineKeySection mconfig = (MachineKeySection) WebConfigurationManager.GetSection ("system.web/machineKey");
991 vkey = mconfig.ValidationKeyBytes;
993 MachineKeyConfig mconfig = HttpContext.GetAppConfig ("system.web/machineKey") as MachineKeyConfig;
994 vkey = mconfig.ValidationKey;
998 return new LosFormatter (config.EnableViewStateMac, vkey);
1001 string GetViewStateString ()
1003 if (_savedViewState == null)
1006 LosFormatter fmt = GetFormatter ();
1007 return fmt.SerializeToBase64 (_savedViewState);
1010 internal object GetSavedViewState ()
1012 return _savedViewState;
1015 internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
1017 scriptManager.WriteArrayDeclares (writer);
1019 if (!postBackScriptRendered && requiresPostBackScript)
1020 RenderPostBackScript (writer, formUniqueID);
1023 scriptManager.SaveEventValidationState ();
1024 scriptManager.WriteExpandoAttributes (writer);
1026 scriptManager.WriteHiddenFields (writer);
1027 scriptManager.WriteClientScriptIncludes (writer);
1028 scriptManager.WriteStartupScriptBlocks (writer);
1029 renderingForm = false;
1030 postBackScriptRendered = false;
1033 private void ProcessPostData (NameValueCollection data, bool second)
1038 if (_requiresPostBackCopy == null && _requiresPostBack != null)
1039 _requiresPostBackCopy = (ArrayList) _requiresPostBack.Clone ();
1041 Hashtable used = new Hashtable ();
1042 foreach (string id in data.AllKeys){
1043 if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID)
1046 string real_id = id;
1047 int dot = real_id.IndexOf ('.');
1049 real_id = real_id.Substring (0, dot);
1051 if (real_id == null || used.ContainsKey (real_id))
1054 used.Add (real_id, real_id);
1056 Control ctrl = FindControl (real_id);
1058 IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
1059 IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
1063 RegisterRequiresRaiseEvent (pbeh);
1067 if (pbdh.LoadPostData (real_id, data) == true) {
1068 if (requiresPostDataChanged == null)
1069 requiresPostDataChanged = new ArrayList ();
1070 requiresPostDataChanged.Add (pbdh);
1071 if (_requiresPostBackCopy != null)
1072 _requiresPostBackCopy.Remove (ctrl.UniqueID);
1074 } else if (!second) {
1075 if (secondPostData == null)
1076 secondPostData = new NameValueCollection ();
1077 secondPostData.Add (real_id, data [id]);
1081 ArrayList list1 = null;
1082 if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
1083 string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
1084 foreach (string id in handlers) {
1085 IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
1087 _requiresPostBackCopy.Remove (id);
1088 if (pbdh.LoadPostData (id, data)) {
1089 if (requiresPostDataChanged == null)
1090 requiresPostDataChanged = new ArrayList ();
1092 requiresPostDataChanged.Add (pbdh);
1094 } else if (second) {
1096 list1 = new ArrayList ();
1101 _requiresPostBack = list1;
1104 [EditorBrowsable (EditorBrowsableState.Never)]
1105 #if NET_2_0 || TARGET_JVM
1106 public virtual void ProcessRequest (HttpContext context)
1108 public void ProcessRequest (HttpContext context)
1112 _lifeCycle = PageLifeCycle.Unknown;
1115 if (clientTarget != null)
1116 Request.ClientTarget = clientTarget;
1118 WireupAutomaticEvents ();
1119 //-- Control execution lifecycle in the docs
1121 // Save culture information because it can be modified in FrameworkInitialize()
1122 CultureInfo culture = Thread.CurrentThread.CurrentCulture;
1123 CultureInfo uiculture = Thread.CurrentThread.CurrentUICulture;
1124 FrameworkInitialize ();
1125 context.ErrorPage = _errorPage;
1128 InternalProcessRequest ();
1129 } catch (ThreadAbortException) {
1130 // Do nothing, just ignore it by now.
1131 } catch (Exception e) {
1132 context.AddError (e); // OnError might access LastError
1133 OnError (EventArgs.Empty);
1134 context.ClearError (e);
1135 // We want to remove that error, as we're rethrowing to stop
1136 // further processing.
1137 Trace.Warn ("Unhandled Exception", e.ToString (), e);
1142 _lifeCycle = PageLifeCycle.Unload;
1145 UnloadRecursive (true);
1147 _lifeCycle = PageLifeCycle.End;
1150 if (Thread.CurrentThread.CurrentCulture.Equals (culture) == false)
1151 Thread.CurrentThread.CurrentCulture = culture;
1153 if (Thread.CurrentThread.CurrentUICulture.Equals (uiculture) == false)
1154 Thread.CurrentThread.CurrentUICulture = uiculture;
1159 internal void ProcessCrossPagePostBack (HttpContext context)
1161 isCrossPagePostBack = true;
1162 ProcessRequest (context);
1166 void InternalProcessRequest ()
1168 _requestValueCollection = this.DeterminePostBackMode();
1171 _lifeCycle = PageLifeCycle.Start;
1172 // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
1173 if (_requestValueCollection != null) {
1174 if (!isCrossPagePostBack && _requestValueCollection [PreviousPageID] != null && _requestValueCollection [PreviousPageID] != Request.FilePath) {
1175 _doLoadPreviousPage = true;
1178 isCallback = _requestValueCollection [CallbackArgumentID] != null;
1179 isPostBack = !isCallback;
1183 // if request was transfered from other page - track Prev. Page
1184 previousPage = _context.LastPage;
1185 _context.LastPage = this;
1187 InitializeCulture ();
1188 _lifeCycle = PageLifeCycle.PreInit;
1189 OnPreInit (EventArgs.Empty);
1193 _lifeCycle = PageLifeCycle.Init;
1195 Trace.Write ("aspx.page", "Begin Init");
1196 InitRecursive (null);
1197 Trace.Write ("aspx.page", "End Init");
1200 _lifeCycle = PageLifeCycle.InitComplete;
1201 OnInitComplete (EventArgs.Empty);
1204 renderingForm = false;
1206 if (IsPostBack || IsCallback) {
1207 _lifeCycle = PageLifeCycle.PreLoad;
1208 if (_requestValueCollection != null)
1209 scriptManager.RestoreEventValidationState (_requestValueCollection [scriptManager.EventStateFieldName]);
1213 Trace.Write ("aspx.page", "Begin LoadViewState");
1214 LoadPageViewState ();
1215 Trace.Write ("aspx.page", "End LoadViewState");
1216 Trace.Write ("aspx.page", "Begin ProcessPostData");
1217 ProcessPostData (_requestValueCollection, false);
1218 Trace.Write ("aspx.page", "End ProcessPostData");
1222 OnPreLoad (EventArgs.Empty);
1223 _lifeCycle = PageLifeCycle.Load;
1228 if (IsPostBack || IsCallback) {
1229 _lifeCycle = PageLifeCycle.ControlEvents;
1233 Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
1234 ProcessPostData (secondPostData, true);
1235 Trace.Write ("aspx.page", "End ProcessPostData Second Try");
1236 Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
1237 RaiseChangedEvents ();
1238 Trace.Write ("aspx.page", "End Raise ChangedEvents");
1239 Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
1240 RaisePostBackEvents ();
1241 Trace.Write ("aspx.page", "End Raise PostBackEvent");
1245 _lifeCycle = PageLifeCycle.LoadComplete;
1246 OnLoadComplete (EventArgs.Empty);
1248 if (IsCrossPagePostBack)
1252 string result = ProcessCallbackData ();
1253 HtmlTextWriter callbackOutput = new HtmlTextWriter (_context.Response.Output);
1254 callbackOutput.Write (result);
1255 callbackOutput.Flush ();
1259 _lifeCycle = PageLifeCycle.PreRender;
1262 Trace.Write ("aspx.page", "Begin PreRender");
1263 PreRenderRecursiveInternal ();
1264 Trace.Write ("aspx.page", "End PreRender");
1267 _lifeCycle = PageLifeCycle.PreRenderComplete;
1268 OnPreRenderComplete (EventArgs.Empty);
1271 Trace.Write ("aspx.page", "Begin SaveViewState");
1272 SavePageViewState ();
1273 Trace.Write ("aspx.page", "End SaveViewState");
1276 _lifeCycle = PageLifeCycle.SaveStateComplete;
1277 OnSaveStateComplete (EventArgs.Empty);
1278 _lifeCycle = PageLifeCycle.Render;
1282 Trace.Write ("aspx.page", "Begin Render");
1283 HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
1284 RenderControl (output);
1285 Trace.Write ("aspx.page", "End Render");
1288 private void RenderTrace ()
1290 TraceManager traceManager = HttpRuntime.TraceManager;
1292 if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
1297 if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput)
1300 if (!traceManager.LocalOnly || Context.Request.IsLocal) {
1301 HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
1302 Trace.Render (output);
1307 bool CheckForValidationSupport (Control targetControl)
1309 if (targetControl == null)
1311 Type type = targetControl.GetType ();
1312 object[] attributes = type.GetCustomAttributes (true);
1313 foreach (object attr in attributes)
1314 if (attr is SupportsEventValidationAttribute)
1320 void RaisePostBackEvents ()
1323 Control targetControl;
1325 if (requiresRaiseEvent != null) {
1327 targetControl = requiresRaiseEvent as Control;
1328 if (targetControl != null && CheckForValidationSupport (targetControl))
1329 scriptManager.ValidateEvent (targetControl.UniqueID, null);
1331 RaisePostBackEvent (requiresRaiseEvent, null);
1335 NameValueCollection postdata = _requestValueCollection;
1336 if (postdata == null)
1339 string eventTarget = postdata [postEventSourceID];
1340 if (eventTarget == null || eventTarget.Length == 0) {
1346 targetControl = FindControl (eventTarget);
1347 IPostBackEventHandler target = targetControl as IPostBackEventHandler;
1349 IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
1355 string eventArgument = postdata [postEventArgumentID];
1357 if (CheckForValidationSupport (targetControl))
1358 scriptManager.ValidateEvent (targetControl.UniqueID, eventArgument);
1360 RaisePostBackEvent (target, eventArgument);
1363 internal void RaiseChangedEvents ()
1365 if (requiresPostDataChanged == null)
1368 foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
1369 ipdh.RaisePostDataChangedEvent ();
1371 requiresPostDataChanged = null;
1374 [EditorBrowsable (EditorBrowsableState.Advanced)]
1375 protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
1377 sourceControl.RaisePostBackEvent (eventArgument);
1383 [EditorBrowsable (EditorBrowsableState.Advanced)]
1384 public void RegisterArrayDeclaration (string arrayName, string arrayValue)
1386 scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
1392 [EditorBrowsable (EditorBrowsableState.Advanced)]
1393 public virtual void RegisterClientScriptBlock (string key, string script)
1395 scriptManager.RegisterClientScriptBlock (key, script);
1401 [EditorBrowsable (EditorBrowsableState.Advanced)]
1402 public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
1404 scriptManager.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
1407 [MonoTODO("Not implemented, Used in HtmlForm")]
1408 internal void RegisterClientScriptFile (string a, string b, string c)
1410 throw new NotImplementedException ();
1416 [EditorBrowsable (EditorBrowsableState.Advanced)]
1417 public void RegisterOnSubmitStatement (string key, string script)
1419 scriptManager.RegisterOnSubmitStatement (key, script);
1422 internal string GetSubmitStatements ()
1424 return scriptManager.WriteSubmitStatements ();
1427 [EditorBrowsable (EditorBrowsableState.Advanced)]
1428 public void RegisterRequiresPostBack (Control control)
1430 if (_requiresPostBack == null)
1431 _requiresPostBack = new ArrayList ();
1433 _requiresPostBack.Add (control.UniqueID);
1436 [EditorBrowsable (EditorBrowsableState.Advanced)]
1437 public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
1439 requiresRaiseEvent = control;
1445 [EditorBrowsable (EditorBrowsableState.Advanced)]
1446 public virtual void RegisterStartupScript (string key, string script)
1448 scriptManager.RegisterStartupScript (key, script);
1451 [EditorBrowsable (EditorBrowsableState.Advanced)]
1452 public void RegisterViewStateHandler ()
1454 handleViewState = true;
1457 [EditorBrowsable (EditorBrowsableState.Advanced)]
1458 protected virtual void SavePageStateToPersistenceMedium (object viewState)
1460 _savedViewState = viewState;
1463 [EditorBrowsable (EditorBrowsableState.Advanced)]
1464 protected virtual object LoadPageStateFromPersistenceMedium ()
1466 NameValueCollection postdata = _requestValueCollection;
1468 if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
1471 if (view_state == "")
1474 LosFormatter fmt = GetFormatter ();
1476 return fmt.Deserialize (view_state);
1477 } catch (Exception e) {
1478 throw new HttpException ("Error restoring page viewstate.", e);
1482 internal void LoadPageViewState()
1484 object sState = LoadPageStateFromPersistenceMedium ();
1485 if (sState != null) {
1487 Triplet data = (Triplet) sState;
1489 LoadPageControlState (data.Third);
1490 LoadViewStateRecursive (data.First);
1491 _requiresPostBack = data.Second as ArrayList;
1494 Pair pair = (Pair) sState;
1496 LoadViewStateRecursive (pair.First);
1497 _requiresPostBack = pair.Second as ArrayList;
1503 internal void SavePageViewState ()
1505 if (!handleViewState)
1509 object controlState = SavePageControlState ();
1512 object viewState = SaveViewStateRecursive ();
1513 object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
1516 Triplet triplet = new Triplet ();
1517 triplet.First = viewState;
1518 triplet.Second = reqPostback;
1519 triplet.Third = controlState;
1521 if (triplet.First == null && triplet.Second == null && triplet.Third == null)
1524 SavePageStateToPersistenceMedium (triplet);
1526 Pair pair = new Pair ();
1527 pair.First = viewState;
1528 pair.Second = reqPostback;
1530 if (pair.First == null && pair.Second == null)
1533 SavePageStateToPersistenceMedium (pair);
1537 public virtual void Validate ()
1539 is_validated = true;
1540 ValidateCollection (_validators);
1544 internal bool AreValidatorsUplevel () {
1545 return AreValidatorsUplevel (String.Empty);
1548 internal bool AreValidatorsUplevel (string valGroup)
1550 internal virtual bool AreValidatorsUplevel ()
1553 bool uplevel = false;
1555 foreach (IValidator v in Validators) {
1556 BaseValidator bv = v as BaseValidator;
1557 if (bv == null) continue;
1560 if (valGroup != bv.ValidationGroup)
1563 if (bv.GetRenderUplevel()) {
1572 bool ValidateCollection (ValidatorCollection validators)
1575 if (!_eventValidation)
1579 if (validators == null || validators.Count == 0)
1582 bool all_valid = true;
1583 foreach (IValidator v in validators){
1585 if (v.IsValid == false)
1592 [EditorBrowsable (EditorBrowsableState.Advanced)]
1593 public virtual void VerifyRenderingInServerForm (Control control)
1595 if (_context == null)
1599 throw new HttpException ("Control '" +
1602 control.GetType ().Name +
1603 "' must be placed inside a form tag with runat=server.");
1606 protected override void FrameworkInitialize ()
1608 base.FrameworkInitialize ();
1610 InitializeStyleSheet ();
1621 ClientScriptManager ClientScript {
1622 get { return scriptManager; }
1627 static readonly object InitCompleteEvent = new object ();
1628 static readonly object LoadCompleteEvent = new object ();
1629 static readonly object PreInitEvent = new object ();
1630 static readonly object PreLoadEvent = new object ();
1631 static readonly object PreRenderCompleteEvent = new object ();
1632 static readonly object SaveStateCompleteEvent = new object ();
1634 const int initcomplete_mask = 1;
1635 const int loadcomplete_mask = 1 << 1;
1636 const int preinit_mask = 1 << 2;
1637 const int preload_mask = 1 << 3;
1638 const int prerendercomplete_mask = 1 << 4;
1639 const int savestatecomplete_mask = 1 << 5;
1641 [EditorBrowsable (EditorBrowsableState.Advanced)]
1642 public event EventHandler InitComplete {
1644 event_mask |= initcomplete_mask;
1645 Events.AddHandler (InitCompleteEvent, value);
1647 remove { Events.RemoveHandler (InitCompleteEvent, value); }
1650 [EditorBrowsable (EditorBrowsableState.Advanced)]
1651 public event EventHandler LoadComplete {
1653 event_mask |= loadcomplete_mask;
1654 Events.AddHandler (LoadCompleteEvent, value);
1656 remove { Events.RemoveHandler (LoadCompleteEvent, value); }
1659 public event EventHandler PreInit {
1661 event_mask |= preinit_mask;
1662 Events.AddHandler (PreInitEvent, value);
1664 remove { Events.RemoveHandler (PreInitEvent, value); }
1667 [EditorBrowsable (EditorBrowsableState.Advanced)]
1668 public event EventHandler PreLoad {
1670 event_mask |= preload_mask;
1671 Events.AddHandler (PreLoadEvent, value);
1673 remove { Events.RemoveHandler (PreLoadEvent, value); }
1676 [EditorBrowsable (EditorBrowsableState.Advanced)]
1677 public event EventHandler PreRenderComplete {
1679 event_mask |= prerendercomplete_mask;
1680 Events.AddHandler (PreRenderCompleteEvent, value);
1682 remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
1685 [EditorBrowsable (EditorBrowsableState.Advanced)]
1686 public event EventHandler SaveStateComplete {
1688 event_mask |= savestatecomplete_mask;
1689 Events.AddHandler (SaveStateCompleteEvent, value);
1691 remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
1694 protected virtual void OnInitComplete (EventArgs e)
1696 if ((event_mask & initcomplete_mask) != 0) {
1697 EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
1698 if (eh != null) eh (this, e);
1702 protected virtual void OnLoadComplete (EventArgs e)
1704 if ((event_mask & loadcomplete_mask) != 0) {
1705 EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
1706 if (eh != null) eh (this, e);
1710 protected virtual void OnPreInit (EventArgs e)
1712 if ((event_mask & preinit_mask) != 0) {
1713 EventHandler eh = (EventHandler) (Events [PreInitEvent]);
1714 if (eh != null) eh (this, e);
1718 protected virtual void OnPreLoad (EventArgs e)
1720 if ((event_mask & preload_mask) != 0) {
1721 EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
1722 if (eh != null) eh (this, e);
1726 protected virtual void OnPreRenderComplete (EventArgs e)
1728 if ((event_mask & prerendercomplete_mask) != 0) {
1729 EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
1730 if (eh != null) eh (this, e);
1735 if (!Form.DetermineRenderUplevel ())
1738 /* figure out if we have some control we're going to focus */
1739 if (String.IsNullOrEmpty (_focusedControlID)) {
1740 _focusedControlID = Form.DefaultFocus;
1741 if (String.IsNullOrEmpty (_focusedControlID))
1742 _focusedControlID = Form.DefaultButton;
1745 if (!String.IsNullOrEmpty (_focusedControlID) || Form.SubmitDisabledControls) {
1747 RequiresPostBackScript ();
1748 ClientScript.RegisterWebFormClientScript ();
1750 if (!String.IsNullOrEmpty (_focusedControlID)) {
1751 ClientScript.RegisterStartupScript ("HtmlForm-DefaultButton-StartupScript",
1752 String.Format ("<script type=\"text/javascript\">\n" +
1754 "WebForm_AutoFocus('{0}');// -->\n" +
1755 "</script>\n", _focusedControlID));
1758 if (Form.SubmitDisabledControls) {
1759 ClientScript.RegisterOnSubmitStatement ("HtmlForm-SubmitDisabledControls-SubmitStatement",
1760 "javascript: return WebForm_OnSubmit();");
1761 ClientScript.RegisterStartupScript ("HtmlForm-SubmitDisabledControls-StartupScript",
1762 @"<script language=""JavaScript"">
1764 function WebForm_OnSubmit() {
1765 WebForm_ReEnableControls();
1773 protected virtual void OnSaveStateComplete (EventArgs e)
1775 if ((event_mask & savestatecomplete_mask) != 0) {
1776 EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
1777 if (eh != null) eh (this, e);
1781 public HtmlForm Form {
1782 get { return _form; }
1785 internal void RegisterForm (HtmlForm form)
1790 [BrowsableAttribute (false)]
1791 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1792 public Page PreviousPage {
1794 if (_doLoadPreviousPage) {
1795 _doLoadPreviousPage = false;
1796 LoadPreviousPageReference ();
1798 return previousPage;
1803 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1804 [BrowsableAttribute (false)]
1805 public bool IsCallback {
1806 get { return isCallback; }
1809 [BrowsableAttribute (false)]
1810 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1811 public bool IsCrossPagePostBack {
1812 get { return isCrossPagePostBack; }
1815 string ProcessCallbackData ()
1817 string callbackTarget = _requestValueCollection [CallbackSourceID];
1818 if (callbackTarget == null || callbackTarget.Length == 0)
1819 throw new HttpException ("Callback target not provided.");
1821 Control targetControl = FindControl (callbackTarget);
1822 ICallbackEventHandler target = targetControl as ICallbackEventHandler;
1824 throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
1826 string callbackArgument = _requestValueCollection [CallbackArgumentID];
1827 if (CheckForValidationSupport (targetControl))
1828 scriptManager.ValidateEvent (targetControl.UniqueID, callbackArgument);
1829 target.RaiseCallbackEvent (callbackArgument);
1830 return target.GetCallbackResult ();
1833 [BrowsableAttribute (false)]
1834 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1835 public HtmlHead Header {
1836 get { return htmlHeader; }
1839 internal void SetHeader (HtmlHead header)
1841 htmlHeader = header;
1842 if (_title != null) {
1843 htmlHeader.Title = _title;
1848 [MonoTODO("Not Implemented")]
1849 protected bool AsyncMode {
1851 throw new NotImplementedException ();
1854 throw new NotImplementedException ();
1858 [MonoTODO ("Not Implemented")]
1859 public TimeSpan AsyncTimeout {
1861 throw new NotImplementedException ();
1864 throw new NotImplementedException ();
1868 [MonoTODO ("Not Implemented")]
1869 public bool IsAsync {
1871 throw new NotImplementedException ();
1875 [MonoTODO ("Not Implemented")]
1876 protected internal virtual string UniqueFilePathSuffix {
1878 throw new NotImplementedException ();
1882 [MonoTODO ("Not Implemented")]
1883 public int MaxPageStateFieldLength {
1885 throw new NotImplementedException ();
1888 throw new NotImplementedException ();
1892 [MonoTODO ("Not Implemented")]
1893 public ViewStateEncryptionMode ViewStateEncryptionMode {
1895 throw new NotImplementedException ();
1898 throw new NotImplementedException ();
1902 [MonoTODO ("Not Implemented")]
1903 public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler)
1905 throw new NotImplementedException ();
1908 [MonoTODO ("Not Implemented")]
1909 public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, Object state)
1911 throw new NotImplementedException ();
1914 [MonoTODO ("Not Implemented")]
1915 public void ExecuteRegisteredAsyncTasks ()
1917 throw new NotImplementedException ();
1920 [MonoTODO ("Not Implemented")]
1921 public static HtmlTextWriter CreateHtmlTextWriterFromType (TextWriter tw, Type writerType)
1923 throw new NotImplementedException ();
1926 [MonoTODO ("Not Implemented")]
1927 public void RegisterRequiresViewStateEncryption ()
1929 throw new NotImplementedException ();
1932 void ApplyMasterPage ()
1934 if (masterPageFile != null && masterPageFile.Length > 0) {
1935 ArrayList appliedMasterPageFiles = new ArrayList ();
1937 if (Master != null) {
1938 MasterPage.ApplyMasterPageRecursive (Master, appliedMasterPageFiles);
1942 Controls.Add (Master);
1947 [DefaultValueAttribute ("")]
1948 public virtual string MasterPageFile {
1949 get { return masterPageFile; }
1951 masterPageFile = value;
1956 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1957 [BrowsableAttribute (false)]
1958 public MasterPage Master {
1960 if (Context == null || String.IsNullOrEmpty (masterPageFile))
1963 if (masterPage == null)
1964 masterPage = MasterPage.CreateMasterPage (this, Context, masterPageFile, contentTemplates);
1970 public void SetFocus (string clientID)
1972 if (String.IsNullOrEmpty (clientID))
1973 throw new ArgumentNullException ("control");
1975 if (_lifeCycle > PageLifeCycle.PreRender)
1976 throw new InvalidOperationException ("SetFocus can only be called before and during PreRender.");
1979 throw new InvalidOperationException ("A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.");
1981 _focusedControlID = clientID;
1984 public void SetFocus (Control control)
1986 if (control == null)
1987 throw new ArgumentNullException ("control");
1989 SetFocus (control.ClientID);
1992 [EditorBrowsable (EditorBrowsableState.Advanced)]
1993 public void RegisterRequiresControlState (Control control)
1995 if (control == null)
1996 throw new ArgumentNullException ("control");
1998 if (RequiresControlState (control))
2001 if (requireStateControls == null)
2002 requireStateControls = new ArrayList ();
2003 int n = requireStateControls.Add (control);
2005 if (_savedControlState == null || n >= _savedControlState.Length)
2008 for (Control parent = control.Parent; parent != null; parent = parent.Parent)
2009 if (parent.IsChildControlStateCleared)
2012 object state = _savedControlState [n];
2014 control.LoadControlState (state);
2017 public bool RequiresControlState (Control control)
2019 if (requireStateControls == null) return false;
2020 return requireStateControls.Contains (control);
2023 [EditorBrowsable (EditorBrowsableState.Advanced)]
2024 public void UnregisterRequiresControlState (Control control)
2026 if (requireStateControls != null)
2027 requireStateControls.Remove (control);
2030 public ValidatorCollection GetValidators (string validationGroup)
2032 string valgr = validationGroup;
2034 valgr = String.Empty;
2036 if (_validatorsByGroup == null) _validatorsByGroup = new Hashtable ();
2037 ValidatorCollection col = _validatorsByGroup [valgr] as ValidatorCollection;
2039 col = new ValidatorCollection ();
2040 _validatorsByGroup [valgr] = col;
2045 public virtual void Validate (string validationGroup)
2047 is_validated = true;
2048 if (validationGroup == null)
2049 ValidateCollection (_validatorsByGroup [String.Empty] as ValidatorCollection);
2050 else if (_validatorsByGroup != null) {
2051 ValidateCollection (_validatorsByGroup [validationGroup] as ValidatorCollection);
2055 object SavePageControlState ()
2057 if (requireStateControls == null) return null;
2058 object[] state = new object [requireStateControls.Count];
2060 bool allNull = true;
2061 for (int n=0; n<state.Length; n++) {
2062 state [n] = ((Control) requireStateControls [n]).SaveControlState ();
2063 if (state [n] != null) allNull = false;
2065 if (allNull) return null;
2069 void LoadPageControlState (object data)
2071 _savedControlState = (object []) data;
2073 if (requireStateControls == null) return;
2075 int max = Math.Min (requireStateControls.Count, _savedControlState != null ? _savedControlState.Length : requireStateControls.Count);
2076 for (int n=0; n < max; n++) {
2077 Control ctl = (Control) requireStateControls [n];
2078 ctl.LoadControlState (_savedControlState != null ? _savedControlState [n] : null);
2082 void LoadPreviousPageReference ()
2084 if (_requestValueCollection != null) {
2085 string prevPage = _requestValueCollection [PreviousPageID];
2086 if (prevPage != null) {
2087 previousPage = (Page) PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
2088 previousPage.ProcessCrossPagePostBack (_context);
2094 Hashtable contentTemplates;
2095 [EditorBrowsable (EditorBrowsableState.Never)]
2096 protected internal void AddContentTemplate (string templateName, ITemplate template)
2098 if (contentTemplates == null)
2099 contentTemplates = new Hashtable ();
2100 contentTemplates [templateName] = template;
2103 PageTheme _pageTheme;
2104 internal PageTheme PageTheme {
2105 get { return _pageTheme; }
2108 PageTheme _styleSheetPageTheme;
2109 internal PageTheme StyleSheetPageTheme {
2110 get { return _styleSheetPageTheme; }
2115 internal void PushDataItemContext (object o) {
2116 if (dataItemCtx == null)
2117 dataItemCtx = new Stack ();
2119 dataItemCtx.Push (o);
2122 internal void PopDataItemContext () {
2123 if (dataItemCtx == null)
2124 throw new InvalidOperationException ();
2129 public object GetDataItem() {
2130 if (dataItemCtx == null || dataItemCtx.Count == 0)
2131 throw new InvalidOperationException ("No data item");
2133 return dataItemCtx.Peek ();
2136 protected internal override void OnInit (EventArgs e)
2142 ArrayList themes = new ArrayList();
2144 if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
2145 themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
2146 if (PageTheme != null && PageTheme.GetStyleSheets () != null)
2147 themes.AddRange (PageTheme.GetStyleSheets ());
2149 foreach (string lss in themes) {
2150 HtmlLink hl = new HtmlLink ();
2151 hl.Href = ResolveUrl (lss);
2152 hl.Attributes["type"] = "text/css";
2153 hl.Attributes["rel"] = "stylesheet";
2154 Header.Controls.Add (hl);
2161 [MonoTODO ("Not implemented. Only used by .net aspx parser")]
2162 protected object GetWrappedFileDependencies (string [] list)
2167 [MonoTODO ("Does nothing. Used by .net aspx parser")]
2168 protected virtual void InitializeCulture ()
2172 [MonoTODO ("Does nothing. Used by .net aspx parser")]
2173 protected internal void AddWrappedFileDependencies (object virtualFileDependencies)