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 theForm {
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 = CultureInfo.CreateSpecificCulture (languages[0]);
720 ret = CultureInfo.CreateSpecificCulture (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))
766 else if (IsPortletRender && req.Form ["__VIEWSTATE"] != null)
770 coll = req.QueryString;
772 WebROCollection c = (WebROCollection) coll;
773 allow_load = !c.GotID;
775 c.ID = GetTypeHashCode ();
777 allow_load = (c.ID == GetTypeHashCode ());
779 if (coll != null && coll ["__VIEWSTATE"] == null && coll ["__EVENTTARGET"] == null)
786 public override Control FindControl (string id) {
790 return base.FindControl (id);
797 [EditorBrowsable (EditorBrowsableState.Advanced)]
798 public string GetPostBackClientEvent (Control control, string argument)
800 return scriptManager.GetPostBackEventReference (control, argument);
806 [EditorBrowsable (EditorBrowsableState.Advanced)]
807 public string GetPostBackClientHyperlink (Control control, string argument)
809 return scriptManager.GetPostBackClientHyperlink (control, argument);
815 [EditorBrowsable (EditorBrowsableState.Advanced)]
816 public string GetPostBackEventReference (Control control)
818 return scriptManager.GetPostBackEventReference (control, "");
824 [EditorBrowsable (EditorBrowsableState.Advanced)]
825 public string GetPostBackEventReference (Control control, string argument)
827 return scriptManager.GetPostBackEventReference (control, argument);
830 internal void RequiresPostBackScript ()
832 requiresPostBackScript = true;
835 ClientScript.RegisterWebFormClientScript ();
839 [EditorBrowsable (EditorBrowsableState.Never)]
840 public virtual int GetTypeHashCode ()
846 [MonoTODO("The following properties of OutputCacheParameters are silently ignored: CacheProfile, NoStore, SqlDependency")]
847 protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings)
849 if (cacheSettings.Enabled)
850 InitOutputCache(cacheSettings.Duration,
851 cacheSettings.VaryByHeader,
852 cacheSettings.VaryByCustom,
853 cacheSettings.Location,
854 cacheSettings.VaryByParam);
858 [EditorBrowsable (EditorBrowsableState.Never)]
859 protected virtual void InitOutputCache (int duration,
862 OutputCacheLocation location,
865 HttpCachePolicy cache = _context.Response.Cache;
866 bool set_vary = false;
869 case OutputCacheLocation.Any:
870 cache.SetCacheability (HttpCacheability.Public);
871 cache.SetMaxAge (new TimeSpan (0, 0, duration));
872 cache.SetLastModified (_context.Timestamp);
875 case OutputCacheLocation.Client:
876 cache.SetCacheability (HttpCacheability.Private);
877 cache.SetMaxAge (new TimeSpan (0, 0, duration));
878 cache.SetLastModified (_context.Timestamp);
880 case OutputCacheLocation.Downstream:
881 cache.SetCacheability (HttpCacheability.Public);
882 cache.SetMaxAge (new TimeSpan (0, 0, duration));
883 cache.SetLastModified (_context.Timestamp);
885 case OutputCacheLocation.Server:
886 cache.SetCacheability (HttpCacheability.Server);
889 case OutputCacheLocation.None:
894 if (varyByCustom != null)
895 cache.SetVaryByCustom (varyByCustom);
897 if (varyByParam != null && varyByParam.Length > 0) {
898 string[] prms = varyByParam.Split (';');
899 foreach (string p in prms)
900 cache.VaryByParams [p.Trim ()] = true;
901 cache.VaryByParams.IgnoreParams = false;
903 cache.VaryByParams.IgnoreParams = true;
906 if (varyByHeader != null && varyByHeader.Length > 0) {
907 string[] hdrs = varyByHeader.Split (';');
908 foreach (string h in hdrs)
909 cache.VaryByHeaders [h.Trim ()] = true;
913 cache.Duration = duration;
914 cache.SetExpires (_context.Timestamp.AddSeconds (duration));
920 [EditorBrowsable (EditorBrowsableState.Advanced)]
922 public bool IsClientScriptBlockRegistered (string key)
924 return scriptManager.IsClientScriptBlockRegistered (key);
930 [EditorBrowsable (EditorBrowsableState.Advanced)]
932 public bool IsStartupScriptRegistered (string key)
934 return scriptManager.IsStartupScriptRegistered (key);
937 public string MapPath (string virtualPath)
939 return Request.MapPath (virtualPath);
943 protected internal override void Render (HtmlTextWriter writer) {
944 if (MaintainScrollPositionOnPostBack) {
945 RequiresPostBackScript ();
946 ClientScript.RegisterWebFormClientScript ();
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 = function () { WebForm_RestoreScrollPosition (" + theForm + "); };");
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 {0};\n\tif (document.getElementById) {{ {0} = document.getElementById ('{1}'); }}", theForm, formUniqueID);
980 writer.WriteLine ("\telse {{ {0} = document.{1}; }}", theForm, formUniqueID);
981 writer.WriteLine ("\t{0}.isAspForm = true;", theForm);
982 writer.WriteLine ("\tfunction __doPostBack(eventTarget, eventArgument) {");
983 writer.WriteLine ("\t\tif(document.ValidatorOnSubmit && !ValidatorOnSubmit()) return;");
984 writer.WriteLine ("\t\tvar myForm = " + theForm + ";");
986 writer.WriteLine ("\t\tif(document.WebForm_GetFormFromCtrl) myForm = WebForm_GetFormFromCtrl (eventTarget);");
988 writer.WriteLine ("\t\tmyForm.{0}.value = eventTarget;", postEventSourceID);
989 writer.WriteLine ("\t\tmyForm.{0}.value = eventArgument;", postEventArgumentID);
990 writer.WriteLine ("\t\tmyForm.submit();");
991 writer.WriteLine ("\t}");
992 writer.WriteLine ("// -->");
993 writer.WriteLine ("</script>");
996 internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
999 throw new HttpException ("Only 1 HtmlForm is allowed per page.");
1001 renderingForm = true;
1002 writer.WriteLine ();
1004 if (handleViewState)
1005 scriptManager.RegisterHiddenField ("__VIEWSTATE", _savedViewState);
1007 scriptManager.WriteHiddenFields (writer);
1008 if (requiresPostBackScript) {
1009 RenderPostBackScript (writer, formUniqueID);
1010 postBackScriptRendered = true;
1012 scriptManager.WriteClientScriptIncludes (writer);
1013 scriptManager.WriteClientScriptBlocks (writer);
1016 internal IStateFormatter GetFormatter ()
1018 return new ObjectStateFormatter (this);
1021 internal string GetSavedViewState ()
1023 return _savedViewState;
1026 internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
1028 if (!postBackScriptRendered && requiresPostBackScript)
1029 RenderPostBackScript (writer, formUniqueID);
1031 scriptManager.WriteArrayDeclares (writer);
1034 scriptManager.SaveEventValidationState ();
1035 scriptManager.WriteExpandoAttributes (writer);
1037 scriptManager.WriteHiddenFields (writer);
1038 scriptManager.WriteClientScriptIncludes (writer);
1039 scriptManager.WriteStartupScriptBlocks (writer);
1040 renderingForm = false;
1041 postBackScriptRendered = false;
1044 private void ProcessPostData (NameValueCollection data, bool second)
1048 Hashtable used = new Hashtable ();
1049 foreach (string id in data.AllKeys){
1050 if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID)
1053 string real_id = id;
1054 int dot = real_id.IndexOf ('.');
1056 real_id = real_id.Substring (0, dot);
1058 if (real_id == null || used.ContainsKey (real_id))
1061 used.Add (real_id, real_id);
1063 Control ctrl = FindControl (real_id);
1065 IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
1066 IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
1070 RegisterRequiresRaiseEvent (pbeh);
1074 if (pbdh.LoadPostData (real_id, data) == true) {
1075 if (requiresPostDataChanged == null)
1076 requiresPostDataChanged = new ArrayList ();
1077 requiresPostDataChanged.Add (pbdh);
1080 if (_requiresPostBackCopy != null)
1081 _requiresPostBackCopy.Remove (real_id);
1083 } else if (!second) {
1084 if (secondPostData == null)
1085 secondPostData = new NameValueCollection ();
1086 secondPostData.Add (real_id, data [id]);
1091 ArrayList list1 = null;
1092 if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
1093 string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
1094 foreach (string id in handlers) {
1095 IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
1097 _requiresPostBackCopy.Remove (id);
1098 if (pbdh.LoadPostData (id, data)) {
1099 if (requiresPostDataChanged == null)
1100 requiresPostDataChanged = new ArrayList ();
1102 requiresPostDataChanged.Add (pbdh);
1104 } else if (!second) {
1106 list1 = new ArrayList ();
1111 _requiresPostBackCopy = second ? null : list1;
1113 secondPostData = null;
1116 [EditorBrowsable (EditorBrowsableState.Never)]
1117 #if NET_2_0 || TARGET_JVM
1118 public virtual void ProcessRequest (HttpContext context)
1120 public void ProcessRequest (HttpContext context)
1124 _lifeCycle = PageLifeCycle.Unknown;
1127 if (clientTarget != null)
1128 Request.ClientTarget = clientTarget;
1130 WireupAutomaticEvents ();
1131 //-- Control execution lifecycle in the docs
1133 // Save culture information because it can be modified in FrameworkInitialize()
1134 CultureInfo culture = Thread.CurrentThread.CurrentCulture;
1135 CultureInfo uiculture = Thread.CurrentThread.CurrentUICulture;
1136 FrameworkInitialize ();
1137 context.ErrorPage = _errorPage;
1140 InternalProcessRequest ();
1141 } catch (ThreadAbortException) {
1142 // Do nothing, just ignore it by now.
1143 } catch (Exception e) {
1144 context.AddError (e); // OnError might access LastError
1145 OnError (EventArgs.Empty);
1146 context.ClearError (e);
1147 // We want to remove that error, as we're rethrowing to stop
1148 // further processing.
1149 Trace.Warn ("Unhandled Exception", e.ToString (), e);
1154 _lifeCycle = PageLifeCycle.Unload;
1157 UnloadRecursive (true);
1159 _lifeCycle = PageLifeCycle.End;
1162 if (Thread.CurrentThread.CurrentCulture.Equals (culture) == false)
1163 Thread.CurrentThread.CurrentCulture = culture;
1165 if (Thread.CurrentThread.CurrentUICulture.Equals (uiculture) == false)
1166 Thread.CurrentThread.CurrentUICulture = uiculture;
1171 internal void ProcessCrossPagePostBack (HttpContext context)
1173 isCrossPagePostBack = true;
1174 ProcessRequest (context);
1178 void InternalProcessRequest ()
1180 _requestValueCollection = this.DeterminePostBackMode();
1183 _lifeCycle = PageLifeCycle.Start;
1184 // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
1185 if (_requestValueCollection != null) {
1186 if (!isCrossPagePostBack && _requestValueCollection [PreviousPageID] != null && _requestValueCollection [PreviousPageID] != Request.FilePath) {
1187 _doLoadPreviousPage = true;
1190 isCallback = _requestValueCollection [CallbackArgumentID] != null;
1191 // LAMESPEC: on Callback IsPostBack is set to false, but true.
1192 //isPostBack = !isCallback;
1197 // if request was transfered from other page - track Prev. Page
1198 previousPage = _context.LastPage;
1199 _context.LastPage = this;
1201 _lifeCycle = PageLifeCycle.PreInit;
1202 OnPreInit (EventArgs.Empty);
1206 _lifeCycle = PageLifeCycle.Init;
1208 Trace.Write ("aspx.page", "Begin Init");
1209 InitRecursive (null);
1210 Trace.Write ("aspx.page", "End Init");
1213 _lifeCycle = PageLifeCycle.InitComplete;
1214 OnInitComplete (EventArgs.Empty);
1217 renderingForm = false;
1219 if (IsPostBack || IsCallback) {
1220 _lifeCycle = PageLifeCycle.PreLoad;
1221 if (_requestValueCollection != null)
1222 scriptManager.RestoreEventValidationState (_requestValueCollection [scriptManager.EventStateFieldName]);
1226 Trace.Write ("aspx.page", "Begin LoadViewState");
1227 LoadPageViewState ();
1228 Trace.Write ("aspx.page", "End LoadViewState");
1229 Trace.Write ("aspx.page", "Begin ProcessPostData");
1230 ProcessPostData (_requestValueCollection, false);
1231 Trace.Write ("aspx.page", "End ProcessPostData");
1235 OnPreLoad (EventArgs.Empty);
1236 _lifeCycle = PageLifeCycle.Load;
1241 if (IsPostBack || IsCallback) {
1242 _lifeCycle = PageLifeCycle.ControlEvents;
1246 Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
1247 ProcessPostData (secondPostData, true);
1248 Trace.Write ("aspx.page", "End ProcessPostData Second Try");
1249 Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
1250 RaiseChangedEvents ();
1251 Trace.Write ("aspx.page", "End Raise ChangedEvents");
1252 Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
1253 RaisePostBackEvents ();
1254 Trace.Write ("aspx.page", "End Raise PostBackEvent");
1258 _lifeCycle = PageLifeCycle.LoadComplete;
1259 OnLoadComplete (EventArgs.Empty);
1261 if (IsCrossPagePostBack)
1265 string result = ProcessCallbackData ();
1266 HtmlTextWriter callbackOutput = new HtmlTextWriter (_context.Response.Output);
1267 callbackOutput.Write (result);
1268 callbackOutput.Flush ();
1272 _lifeCycle = PageLifeCycle.PreRender;
1275 Trace.Write ("aspx.page", "Begin PreRender");
1276 PreRenderRecursiveInternal ();
1277 Trace.Write ("aspx.page", "End PreRender");
1280 _lifeCycle = PageLifeCycle.PreRenderComplete;
1281 OnPreRenderComplete (EventArgs.Empty);
1284 Trace.Write ("aspx.page", "Begin SaveViewState");
1285 SavePageViewState ();
1286 Trace.Write ("aspx.page", "End SaveViewState");
1289 _lifeCycle = PageLifeCycle.SaveStateComplete;
1290 OnSaveStateComplete (EventArgs.Empty);
1294 if (SaveViewStateForNextPortletRender())
1299 _lifeCycle = PageLifeCycle.Render;
1303 Trace.Write ("aspx.page", "Begin Render");
1304 HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
1305 RenderControl (output);
1306 Trace.Write ("aspx.page", "End Render");
1309 private void RenderTrace ()
1311 TraceManager traceManager = HttpRuntime.TraceManager;
1313 if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
1318 if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput)
1321 if (!traceManager.LocalOnly || Context.Request.IsLocal) {
1322 HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
1323 Trace.Render (output);
1328 bool CheckForValidationSupport (Control targetControl)
1330 if (targetControl == null)
1332 Type type = targetControl.GetType ();
1333 object[] attributes = type.GetCustomAttributes (false);
1334 foreach (object attr in attributes)
1335 if (attr is SupportsEventValidationAttribute)
1341 void RaisePostBackEvents ()
1344 Control targetControl;
1346 if (requiresRaiseEvent != null) {
1347 RaisePostBackEvent (requiresRaiseEvent, null);
1351 NameValueCollection postdata = _requestValueCollection;
1352 if (postdata == null)
1355 string eventTarget = postdata [postEventSourceID];
1356 if (eventTarget == null || eventTarget.Length == 0) {
1362 targetControl = FindControl (eventTarget);
1363 IPostBackEventHandler target = targetControl as IPostBackEventHandler;
1365 IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
1371 string eventArgument = postdata [postEventArgumentID];
1372 RaisePostBackEvent (target, eventArgument);
1375 internal void RaiseChangedEvents ()
1377 if (requiresPostDataChanged == null)
1380 foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
1381 ipdh.RaisePostDataChangedEvent ();
1383 requiresPostDataChanged = null;
1386 [EditorBrowsable (EditorBrowsableState.Advanced)]
1387 protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
1390 Control targetControl = sourceControl as Control;
1391 if (targetControl != null && CheckForValidationSupport (targetControl))
1392 scriptManager.ValidateEvent (targetControl.UniqueID, eventArgument);
1394 sourceControl.RaisePostBackEvent (eventArgument);
1400 [EditorBrowsable (EditorBrowsableState.Advanced)]
1401 public void RegisterArrayDeclaration (string arrayName, string arrayValue)
1403 scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
1409 [EditorBrowsable (EditorBrowsableState.Advanced)]
1410 public virtual void RegisterClientScriptBlock (string key, string script)
1412 scriptManager.RegisterClientScriptBlock (key, script);
1418 [EditorBrowsable (EditorBrowsableState.Advanced)]
1419 public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
1421 scriptManager.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
1424 [MonoTODO("Not implemented, Used in HtmlForm")]
1425 internal void RegisterClientScriptFile (string a, string b, string c)
1427 throw new NotImplementedException ();
1433 [EditorBrowsable (EditorBrowsableState.Advanced)]
1434 public void RegisterOnSubmitStatement (string key, string script)
1436 scriptManager.RegisterOnSubmitStatement (key, script);
1439 internal string GetSubmitStatements ()
1441 return scriptManager.WriteSubmitStatements ();
1444 [EditorBrowsable (EditorBrowsableState.Advanced)]
1445 public void RegisterRequiresPostBack (Control control)
1447 if (_requiresPostBack == null)
1448 _requiresPostBack = new ArrayList ();
1450 if (_requiresPostBack.Contains (control.UniqueID))
1453 _requiresPostBack.Add (control.UniqueID);
1456 [EditorBrowsable (EditorBrowsableState.Advanced)]
1457 public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
1459 requiresRaiseEvent = control;
1465 [EditorBrowsable (EditorBrowsableState.Advanced)]
1466 public virtual void RegisterStartupScript (string key, string script)
1468 scriptManager.RegisterStartupScript (key, script);
1471 [EditorBrowsable (EditorBrowsableState.Advanced)]
1472 public void RegisterViewStateHandler ()
1474 handleViewState = true;
1477 [EditorBrowsable (EditorBrowsableState.Advanced)]
1478 protected virtual void SavePageStateToPersistenceMedium (object viewState)
1480 PageStatePersister persister = this.PageStatePersister;
1481 if (persister == null)
1483 Pair pair = viewState as Pair;
1485 persister.ViewState = pair.First;
1486 persister.ControlState = pair.Second;
1488 persister.ViewState = viewState;
1492 internal string RawViewState {
1494 NameValueCollection postdata = _requestValueCollection;
1496 if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
1499 if (view_state == "")
1503 set { _savedViewState = value; }
1511 PageStatePersister PageStatePersister {
1513 if (page_state_persister == null)
1514 page_state_persister = new HiddenFieldPageStatePersister (this);
1515 return page_state_persister;
1519 [EditorBrowsable (EditorBrowsableState.Advanced)]
1520 protected virtual object LoadPageStateFromPersistenceMedium ()
1522 PageStatePersister persister = this.PageStatePersister;
1523 if (persister == null)
1526 return new Pair (persister.ViewState, persister.ControlState);
1529 internal void LoadPageViewState()
1531 Pair sState = LoadPageStateFromPersistenceMedium () as Pair;
1532 if (sState != null) {
1535 LoadPageControlState (sState.Second);
1537 Pair vsr = sState.First as Pair;
1539 LoadViewStateRecursive (vsr.First);
1540 _requiresPostBackCopy = vsr.Second as ArrayList;
1546 internal void SavePageViewState ()
1548 if (!handleViewState)
1552 object controlState = SavePageControlState ();
1555 object viewState = SaveViewStateRecursive ();
1556 object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
1559 if (viewState != null || reqPostback != null)
1560 vsr = new Pair (viewState, reqPostback);
1561 Pair pair = new Pair ();
1565 pair.Second = controlState;
1569 if (pair.First == null && pair.Second == null)
1570 SavePageStateToPersistenceMedium (null);
1572 SavePageStateToPersistenceMedium (pair);
1576 public virtual void Validate ()
1578 is_validated = true;
1579 ValidateCollection (_validators);
1583 internal bool AreValidatorsUplevel () {
1584 return AreValidatorsUplevel (String.Empty);
1587 internal bool AreValidatorsUplevel (string valGroup)
1589 internal virtual bool AreValidatorsUplevel ()
1592 bool uplevel = false;
1594 foreach (IValidator v in Validators) {
1595 BaseValidator bv = v as BaseValidator;
1596 if (bv == null) continue;
1599 if (valGroup != bv.ValidationGroup)
1602 if (bv.GetRenderUplevel()) {
1611 bool ValidateCollection (ValidatorCollection validators)
1614 if (!_eventValidation)
1618 if (validators == null || validators.Count == 0)
1621 bool all_valid = true;
1622 foreach (IValidator v in validators){
1624 if (v.IsValid == false)
1631 [EditorBrowsable (EditorBrowsableState.Advanced)]
1632 public virtual void VerifyRenderingInServerForm (Control control)
1634 if (_context == null)
1641 throw new HttpException ("Control '" +
1644 control.GetType ().Name +
1645 "' must be placed inside a form tag with runat=server.");
1648 protected override void FrameworkInitialize ()
1650 base.FrameworkInitialize ();
1652 InitializeStyleSheet ();
1663 ClientScriptManager ClientScript {
1664 get { return scriptManager; }
1669 static readonly object InitCompleteEvent = new object ();
1670 static readonly object LoadCompleteEvent = new object ();
1671 static readonly object PreInitEvent = new object ();
1672 static readonly object PreLoadEvent = new object ();
1673 static readonly object PreRenderCompleteEvent = new object ();
1674 static readonly object SaveStateCompleteEvent = new object ();
1676 const int initcomplete_mask = 1;
1677 const int loadcomplete_mask = 1 << 1;
1678 const int preinit_mask = 1 << 2;
1679 const int preload_mask = 1 << 3;
1680 const int prerendercomplete_mask = 1 << 4;
1681 const int savestatecomplete_mask = 1 << 5;
1683 [EditorBrowsable (EditorBrowsableState.Advanced)]
1684 public event EventHandler InitComplete {
1686 event_mask |= initcomplete_mask;
1687 Events.AddHandler (InitCompleteEvent, value);
1689 remove { Events.RemoveHandler (InitCompleteEvent, value); }
1692 [EditorBrowsable (EditorBrowsableState.Advanced)]
1693 public event EventHandler LoadComplete {
1695 event_mask |= loadcomplete_mask;
1696 Events.AddHandler (LoadCompleteEvent, value);
1698 remove { Events.RemoveHandler (LoadCompleteEvent, value); }
1701 public event EventHandler PreInit {
1703 event_mask |= preinit_mask;
1704 Events.AddHandler (PreInitEvent, value);
1706 remove { Events.RemoveHandler (PreInitEvent, value); }
1709 [EditorBrowsable (EditorBrowsableState.Advanced)]
1710 public event EventHandler PreLoad {
1712 event_mask |= preload_mask;
1713 Events.AddHandler (PreLoadEvent, value);
1715 remove { Events.RemoveHandler (PreLoadEvent, value); }
1718 [EditorBrowsable (EditorBrowsableState.Advanced)]
1719 public event EventHandler PreRenderComplete {
1721 event_mask |= prerendercomplete_mask;
1722 Events.AddHandler (PreRenderCompleteEvent, value);
1724 remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
1727 [EditorBrowsable (EditorBrowsableState.Advanced)]
1728 public event EventHandler SaveStateComplete {
1730 event_mask |= savestatecomplete_mask;
1731 Events.AddHandler (SaveStateCompleteEvent, value);
1733 remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
1736 protected virtual void OnInitComplete (EventArgs e)
1738 if ((event_mask & initcomplete_mask) != 0) {
1739 EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
1740 if (eh != null) eh (this, e);
1744 protected virtual void OnLoadComplete (EventArgs e)
1746 if ((event_mask & loadcomplete_mask) != 0) {
1747 EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
1748 if (eh != null) eh (this, e);
1752 protected virtual void OnPreInit (EventArgs e)
1754 if ((event_mask & preinit_mask) != 0) {
1755 EventHandler eh = (EventHandler) (Events [PreInitEvent]);
1756 if (eh != null) eh (this, e);
1760 protected virtual void OnPreLoad (EventArgs e)
1762 if ((event_mask & preload_mask) != 0) {
1763 EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
1764 if (eh != null) eh (this, e);
1768 protected virtual void OnPreRenderComplete (EventArgs e)
1770 if ((event_mask & prerendercomplete_mask) != 0) {
1771 EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
1772 if (eh != null) eh (this, e);
1777 if (!Form.DetermineRenderUplevel ())
1780 /* figure out if we have some control we're going to focus */
1781 if (String.IsNullOrEmpty (_focusedControlID)) {
1782 _focusedControlID = Form.DefaultFocus;
1783 if (String.IsNullOrEmpty (_focusedControlID))
1784 _focusedControlID = Form.DefaultButton;
1787 if (!String.IsNullOrEmpty (_focusedControlID) || Form.SubmitDisabledControls) {
1789 RequiresPostBackScript ();
1790 ClientScript.RegisterWebFormClientScript ();
1792 if (!String.IsNullOrEmpty (_focusedControlID)) {
1793 ClientScript.RegisterStartupScript ("HtmlForm-DefaultButton-StartupScript",
1794 String.Format ("<script type=\"text/javascript\">\n" +
1796 "WebForm_AutoFocus('{0}');// -->\n" +
1797 "</script>\n", _focusedControlID));
1800 if (Form.SubmitDisabledControls) {
1801 ClientScript.RegisterOnSubmitStatement ("HtmlForm-SubmitDisabledControls-SubmitStatement",
1802 "javascript: return WebForm_OnSubmit(" + theForm + ");");
1803 ClientScript.RegisterStartupScript ("HtmlForm-SubmitDisabledControls-StartupScript",
1804 @"<script language=""JavaScript"">
1806 function WebForm_OnSubmit(currForm) {
1807 WebForm_ReEnableControls(currForm);
1815 protected virtual void OnSaveStateComplete (EventArgs e)
1817 if ((event_mask & savestatecomplete_mask) != 0) {
1818 EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
1819 if (eh != null) eh (this, e);
1823 public HtmlForm Form {
1824 get { return _form; }
1827 internal void RegisterForm (HtmlForm form)
1832 [BrowsableAttribute (false)]
1833 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1834 public Page PreviousPage {
1836 if (_doLoadPreviousPage) {
1837 _doLoadPreviousPage = false;
1838 LoadPreviousPageReference ();
1840 return previousPage;
1845 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1846 [BrowsableAttribute (false)]
1847 public bool IsCallback {
1848 get { return isCallback; }
1851 [BrowsableAttribute (false)]
1852 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1853 public bool IsCrossPagePostBack {
1854 get { return isCrossPagePostBack; }
1857 public new virtual char IdSeparator {
1859 //TODO: why override?
1860 return base.IdSeparator;
1864 string ProcessCallbackData ()
1866 string callbackTarget = _requestValueCollection [CallbackSourceID];
1867 if (callbackTarget == null || callbackTarget.Length == 0)
1868 throw new HttpException ("Callback target not provided.");
1870 Control targetControl = FindControl (callbackTarget);
1871 ICallbackEventHandler target = targetControl as ICallbackEventHandler;
1873 throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
1875 string callbackArgument = _requestValueCollection [CallbackArgumentID];
1876 target.RaiseCallbackEvent (callbackArgument);
1878 string eventValidation = ClientScript.GetEventValidationStateFormatted ();
1879 string callBackResult= target.GetCallbackResult ();
1881 return String.Format ("{0}|{1}{2}", eventValidation == null ? 0 : eventValidation.Length, eventValidation, callBackResult);
1884 [BrowsableAttribute (false)]
1885 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1886 public HtmlHead Header {
1887 get { return htmlHeader; }
1890 internal void SetHeader (HtmlHead header)
1892 htmlHeader = header;
1893 if (_title != null) {
1894 htmlHeader.Title = _title;
1899 [MonoTODO("Not Implemented")]
1900 protected bool AsyncMode {
1902 throw new NotImplementedException ();
1905 throw new NotImplementedException ();
1909 [MonoTODO ("Not Implemented")]
1910 public TimeSpan AsyncTimeout {
1912 throw new NotImplementedException ();
1915 throw new NotImplementedException ();
1919 [MonoTODO ("Not Implemented")]
1920 public bool IsAsync {
1922 throw new NotImplementedException ();
1926 [MonoTODO ("Not Implemented")]
1927 protected internal virtual string UniqueFilePathSuffix {
1929 throw new NotImplementedException ();
1933 [MonoTODO ("Not Implemented")]
1934 public int MaxPageStateFieldLength {
1936 throw new NotImplementedException ();
1939 throw new NotImplementedException ();
1943 [MonoTODO ("Not Implemented")]
1944 public ViewStateEncryptionMode ViewStateEncryptionMode {
1946 throw new NotImplementedException ();
1949 throw new NotImplementedException ();
1953 [MonoTODO ("Not Implemented")]
1954 public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler)
1956 throw new NotImplementedException ();
1959 [MonoTODO ("Not Implemented")]
1960 public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, Object state)
1962 throw new NotImplementedException ();
1965 [MonoTODO ("Not Implemented")]
1966 public void ExecuteRegisteredAsyncTasks ()
1968 throw new NotImplementedException ();
1971 [MonoTODO ("Not Implemented")]
1972 public static HtmlTextWriter CreateHtmlTextWriterFromType (TextWriter tw, Type writerType)
1974 throw new NotImplementedException ();
1977 [MonoTODO ("Not Implemented")]
1978 public void RegisterRequiresViewStateEncryption ()
1980 throw new NotImplementedException ();
1983 void ApplyMasterPage ()
1985 if (masterPageFile != null && masterPageFile.Length > 0) {
1986 ArrayList appliedMasterPageFiles = new ArrayList ();
1988 if (Master != null) {
1989 MasterPage.ApplyMasterPageRecursive (Master, appliedMasterPageFiles);
1993 Controls.Add (Master);
1998 [DefaultValueAttribute ("")]
1999 public virtual string MasterPageFile {
2000 get { return masterPageFile; }
2002 masterPageFile = value;
2007 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
2008 [BrowsableAttribute (false)]
2009 public MasterPage Master {
2011 if (Context == null || String.IsNullOrEmpty (masterPageFile))
2014 if (masterPage == null)
2015 masterPage = MasterPage.CreateMasterPage (this, Context, masterPageFile, contentTemplates);
2021 public void SetFocus (string clientID)
2023 if (String.IsNullOrEmpty (clientID))
2024 throw new ArgumentNullException ("control");
2026 if (_lifeCycle > PageLifeCycle.PreRender)
2027 throw new InvalidOperationException ("SetFocus can only be called before and during PreRender.");
2030 throw new InvalidOperationException ("A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.");
2032 _focusedControlID = clientID;
2035 public void SetFocus (Control control)
2037 if (control == null)
2038 throw new ArgumentNullException ("control");
2040 SetFocus (control.ClientID);
2043 [EditorBrowsable (EditorBrowsableState.Advanced)]
2044 public void RegisterRequiresControlState (Control control)
2046 if (control == null)
2047 throw new ArgumentNullException ("control");
2049 if (RequiresControlState (control))
2052 if (requireStateControls == null)
2053 requireStateControls = new ArrayList ();
2054 int n = requireStateControls.Add (control);
2056 if (_savedControlState == null || n >= _savedControlState.Length)
2059 for (Control parent = control.Parent; parent != null; parent = parent.Parent)
2060 if (parent.IsChildControlStateCleared)
2063 object state = _savedControlState [n];
2065 control.LoadControlState (state);
2068 public bool RequiresControlState (Control control)
2070 if (requireStateControls == null) return false;
2071 return requireStateControls.Contains (control);
2074 [EditorBrowsable (EditorBrowsableState.Advanced)]
2075 public void UnregisterRequiresControlState (Control control)
2077 if (requireStateControls != null)
2078 requireStateControls.Remove (control);
2081 public ValidatorCollection GetValidators (string validationGroup)
2083 string valgr = validationGroup;
2085 valgr = String.Empty;
2087 if (_validatorsByGroup == null) _validatorsByGroup = new Hashtable ();
2088 ValidatorCollection col = _validatorsByGroup [valgr] as ValidatorCollection;
2090 col = new ValidatorCollection ();
2091 _validatorsByGroup [valgr] = col;
2096 public virtual void Validate (string validationGroup)
2098 is_validated = true;
2099 if (validationGroup == null)
2100 ValidateCollection (_validatorsByGroup [String.Empty] as ValidatorCollection);
2101 else if (_validatorsByGroup != null) {
2102 ValidateCollection (_validatorsByGroup [validationGroup] as ValidatorCollection);
2106 object SavePageControlState ()
2108 if (requireStateControls == null) return null;
2109 object[] state = new object [requireStateControls.Count];
2111 bool allNull = true;
2112 for (int n=0; n<state.Length; n++) {
2113 state [n] = ((Control) requireStateControls [n]).SaveControlState ();
2114 if (state [n] != null) allNull = false;
2116 if (allNull) return null;
2120 void LoadPageControlState (object data)
2122 _savedControlState = (object []) data;
2124 if (requireStateControls == null) return;
2126 int max = Math.Min (requireStateControls.Count, _savedControlState != null ? _savedControlState.Length : requireStateControls.Count);
2127 for (int n=0; n < max; n++) {
2128 Control ctl = (Control) requireStateControls [n];
2129 ctl.LoadControlState (_savedControlState != null ? _savedControlState [n] : null);
2133 void LoadPreviousPageReference ()
2135 if (_requestValueCollection != null) {
2136 string prevPage = _requestValueCollection [PreviousPageID];
2137 if (prevPage != null) {
2138 previousPage = (Page) PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
2139 previousPage.ProcessCrossPagePostBack (_context);
2145 Hashtable contentTemplates;
2146 [EditorBrowsable (EditorBrowsableState.Never)]
2147 protected internal void AddContentTemplate (string templateName, ITemplate template)
2149 if (contentTemplates == null)
2150 contentTemplates = new Hashtable ();
2151 contentTemplates [templateName] = template;
2154 PageTheme _pageTheme;
2155 internal PageTheme PageTheme {
2156 get { return _pageTheme; }
2159 PageTheme _styleSheetPageTheme;
2160 internal PageTheme StyleSheetPageTheme {
2161 get { return _styleSheetPageTheme; }
2166 internal void PushDataItemContext (object o) {
2167 if (dataItemCtx == null)
2168 dataItemCtx = new Stack ();
2170 dataItemCtx.Push (o);
2173 internal void PopDataItemContext () {
2174 if (dataItemCtx == null)
2175 throw new InvalidOperationException ();
2180 public object GetDataItem() {
2181 if (dataItemCtx == null || dataItemCtx.Count == 0)
2182 throw new InvalidOperationException ("No data item");
2184 return dataItemCtx.Peek ();
2187 protected internal override void OnInit (EventArgs e)
2193 ArrayList themes = new ArrayList();
2195 if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
2196 themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
2197 if (PageTheme != null && PageTheme.GetStyleSheets () != null)
2198 themes.AddRange (PageTheme.GetStyleSheets ());
2200 foreach (string lss in themes) {
2201 HtmlLink hl = new HtmlLink ();
2202 hl.Href = ResolveUrl (lss);
2203 hl.Attributes["type"] = "text/css";
2204 hl.Attributes["rel"] = "stylesheet";
2205 Header.Controls.Add (hl);
2212 [MonoTODO ("Not implemented. Only used by .net aspx parser")]
2213 protected object GetWrappedFileDependencies (string [] list)
2218 [MonoTODO ("Does nothing. Used by .net aspx parser")]
2219 protected virtual void InitializeCulture ()
2223 [MonoTODO ("Does nothing. Used by .net aspx parser")]
2224 protected internal void AddWrappedFileDependencies (object virtualFileDependencies)