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 ()
833 if (requiresPostBackScript)
835 ClientScript.RegisterHiddenField (postEventSourceID, String.Empty);
836 ClientScript.RegisterHiddenField (postEventArgumentID, String.Empty);
838 requiresPostBackScript = true;
841 [EditorBrowsable (EditorBrowsableState.Never)]
842 public virtual int GetTypeHashCode ()
848 [MonoTODO("The following properties of OutputCacheParameters are silently ignored: CacheProfile, NoStore, SqlDependency")]
849 protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings)
851 if (cacheSettings.Enabled)
852 InitOutputCache(cacheSettings.Duration,
853 cacheSettings.VaryByHeader,
854 cacheSettings.VaryByCustom,
855 cacheSettings.Location,
856 cacheSettings.VaryByParam);
860 [EditorBrowsable (EditorBrowsableState.Never)]
861 protected virtual void InitOutputCache (int duration,
864 OutputCacheLocation location,
867 HttpCachePolicy cache = _context.Response.Cache;
868 bool set_vary = false;
871 case OutputCacheLocation.Any:
872 cache.SetCacheability (HttpCacheability.Public);
873 cache.SetMaxAge (new TimeSpan (0, 0, duration));
874 cache.SetLastModified (_context.Timestamp);
877 case OutputCacheLocation.Client:
878 cache.SetCacheability (HttpCacheability.Private);
879 cache.SetMaxAge (new TimeSpan (0, 0, duration));
880 cache.SetLastModified (_context.Timestamp);
882 case OutputCacheLocation.Downstream:
883 cache.SetCacheability (HttpCacheability.Public);
884 cache.SetMaxAge (new TimeSpan (0, 0, duration));
885 cache.SetLastModified (_context.Timestamp);
887 case OutputCacheLocation.Server:
888 cache.SetCacheability (HttpCacheability.Server);
891 case OutputCacheLocation.None:
896 if (varyByCustom != null)
897 cache.SetVaryByCustom (varyByCustom);
899 if (varyByParam != null && varyByParam.Length > 0) {
900 string[] prms = varyByParam.Split (';');
901 foreach (string p in prms)
902 cache.VaryByParams [p.Trim ()] = true;
903 cache.VaryByParams.IgnoreParams = false;
905 cache.VaryByParams.IgnoreParams = true;
908 if (varyByHeader != null && varyByHeader.Length > 0) {
909 string[] hdrs = varyByHeader.Split (';');
910 foreach (string h in hdrs)
911 cache.VaryByHeaders [h.Trim ()] = true;
915 cache.Duration = duration;
916 cache.SetExpires (_context.Timestamp.AddSeconds (duration));
922 [EditorBrowsable (EditorBrowsableState.Advanced)]
924 public bool IsClientScriptBlockRegistered (string key)
926 return scriptManager.IsClientScriptBlockRegistered (key);
932 [EditorBrowsable (EditorBrowsableState.Advanced)]
934 public bool IsStartupScriptRegistered (string key)
936 return scriptManager.IsStartupScriptRegistered (key);
939 public string MapPath (string virtualPath)
941 return Request.MapPath (virtualPath);
945 protected internal override void Render (HtmlTextWriter writer) {
946 if (MaintainScrollPositionOnPostBack) {
947 ClientScript.RegisterWebFormClientScript ();
949 ClientScript.RegisterHiddenField (ScrollPositionXID, Request [ScrollPositionXID]);
950 ClientScript.RegisterHiddenField (ScrollPositionYID, Request [ScrollPositionYID]);
952 StringBuilder script = new StringBuilder ();
953 script.AppendLine ("<script type=\"text/javascript\">");
954 script.AppendLine ("<!--");
955 script.AppendLine (theForm + ".oldSubmit = " + theForm + ".submit;");
956 script.AppendLine (theForm + ".submit = WebForm_SaveScrollPositionSubmit;");
957 script.AppendLine (theForm + ".oldOnSubmit = " + theForm + ".onsubmit;");
958 script.AppendLine (theForm + ".onsubmit = WebForm_SaveScrollPositionOnSubmit;");
960 script.AppendLine (theForm + ".oldOnLoad = window.onload;");
961 script.AppendLine ("window.onload = function () { WebForm_RestoreScrollPosition (" + theForm + "); };");
963 script.AppendLine ("// -->");
964 script.AppendLine ("</script>");
966 ClientScript.RegisterStartupScript (typeof (Page), "MaintainScrollPositionOnPostBackStartup", script.ToString());
968 base.Render (writer);
972 private void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
975 writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventSourceID);
976 writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventArgumentID);
980 ClientScript.WriteBeginScriptBlock (writer);
983 RenderClientScriptFormDeclaration (writer, formUniqueID);
985 writer.WriteLine ("function __doPostBack(eventTarget, eventArgument) {");
986 writer.WriteLine ("\tvar currForm = {0};", theForm);
988 writer.WriteLine ("\tcurrForm.__doPostBack(eventTarget, eventArgument);");
989 writer.WriteLine ("}");
990 writer.WriteLine ("{0}.__doPostBack = function (eventTarget, eventArgument) {{", theForm);
991 writer.WriteLine ("\tvar currForm = this;");
992 writer.WriteLine ("\tif(currForm.onsubmit && currForm.onsubmit() == false) return;");
994 writer.WriteLine ("\tif(document.ValidatorOnSubmit && !ValidatorOnSubmit()) return;");
996 writer.WriteLine ("\tcurrForm.{0}.value = eventTarget;", postEventSourceID);
997 writer.WriteLine ("\tcurrForm.{0}.value = eventArgument;", postEventArgumentID);
998 writer.WriteLine ("\tcurrForm.submit();");
999 writer.WriteLine ("}");
1001 ClientScript.WriteEndScriptBlock (writer);
1004 void RenderClientScriptFormDeclaration (HtmlTextWriter writer, string formUniqueID)
1006 writer.WriteLine ("\tvar {0};\n\tif (document.getElementById) {{ {0} = document.getElementById ('{1}'); }}", theForm, formUniqueID);
1007 writer.WriteLine ("\telse {{ {0} = document.{1}; }}", theForm, formUniqueID);
1008 writer.WriteLine ("\t{0}.isAspForm = true;", theForm);
1011 internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
1014 throw new HttpException ("Only 1 HtmlForm is allowed per page.");
1016 renderingForm = true;
1017 writer.WriteLine ();
1020 ClientScript.WriteBeginScriptBlock (writer);
1021 RenderClientScriptFormDeclaration (writer, formUniqueID);
1022 ClientScript.WriteEndScriptBlock (writer);
1025 if (handleViewState)
1026 scriptManager.RegisterHiddenField ("__VIEWSTATE", _savedViewState);
1028 scriptManager.WriteHiddenFields (writer);
1029 if (requiresPostBackScript) {
1030 RenderPostBackScript (writer, formUniqueID);
1031 postBackScriptRendered = true;
1033 scriptManager.WriteClientScriptIncludes (writer);
1034 scriptManager.WriteClientScriptBlocks (writer);
1037 internal IStateFormatter GetFormatter ()
1039 return new ObjectStateFormatter (this);
1042 internal string GetSavedViewState ()
1044 return _savedViewState;
1047 internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
1049 if (!postBackScriptRendered && requiresPostBackScript)
1050 RenderPostBackScript (writer, formUniqueID);
1052 scriptManager.WriteArrayDeclares (writer);
1055 scriptManager.SaveEventValidationState ();
1056 scriptManager.WriteExpandoAttributes (writer);
1058 scriptManager.WriteHiddenFields (writer);
1059 scriptManager.WriteClientScriptIncludes (writer);
1060 scriptManager.WriteStartupScriptBlocks (writer);
1061 renderingForm = false;
1062 postBackScriptRendered = false;
1065 private void ProcessPostData (NameValueCollection data, bool second)
1069 Hashtable used = new Hashtable ();
1070 foreach (string id in data.AllKeys){
1071 if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID)
1074 string real_id = id;
1075 int dot = real_id.IndexOf ('.');
1077 real_id = real_id.Substring (0, dot);
1079 if (real_id == null || used.ContainsKey (real_id))
1082 used.Add (real_id, real_id);
1084 Control ctrl = FindControl (real_id);
1086 IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
1087 IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
1091 RegisterRequiresRaiseEvent (pbeh);
1095 if (pbdh.LoadPostData (real_id, data) == true) {
1096 if (requiresPostDataChanged == null)
1097 requiresPostDataChanged = new ArrayList ();
1098 requiresPostDataChanged.Add (pbdh);
1101 if (_requiresPostBackCopy != null)
1102 _requiresPostBackCopy.Remove (real_id);
1104 } else if (!second) {
1105 if (secondPostData == null)
1106 secondPostData = new NameValueCollection ();
1107 secondPostData.Add (real_id, data [id]);
1112 ArrayList list1 = null;
1113 if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
1114 string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
1115 foreach (string id in handlers) {
1116 IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
1118 _requiresPostBackCopy.Remove (id);
1119 if (pbdh.LoadPostData (id, data)) {
1120 if (requiresPostDataChanged == null)
1121 requiresPostDataChanged = new ArrayList ();
1123 requiresPostDataChanged.Add (pbdh);
1125 } else if (!second) {
1127 list1 = new ArrayList ();
1132 _requiresPostBackCopy = second ? null : list1;
1134 secondPostData = null;
1137 [EditorBrowsable (EditorBrowsableState.Never)]
1138 #if NET_2_0 || TARGET_JVM
1139 public virtual void ProcessRequest (HttpContext context)
1141 public void ProcessRequest (HttpContext context)
1145 _lifeCycle = PageLifeCycle.Unknown;
1148 if (clientTarget != null)
1149 Request.ClientTarget = clientTarget;
1151 WireupAutomaticEvents ();
1152 //-- Control execution lifecycle in the docs
1154 // Save culture information because it can be modified in FrameworkInitialize()
1155 CultureInfo culture = Thread.CurrentThread.CurrentCulture;
1156 CultureInfo uiculture = Thread.CurrentThread.CurrentUICulture;
1157 FrameworkInitialize ();
1158 context.ErrorPage = _errorPage;
1161 InternalProcessRequest ();
1162 } catch (ThreadAbortException) {
1163 // Do nothing, just ignore it by now.
1164 } catch (Exception e) {
1165 context.AddError (e); // OnError might access LastError
1166 OnError (EventArgs.Empty);
1167 context.ClearError (e);
1168 // We want to remove that error, as we're rethrowing to stop
1169 // further processing.
1170 Trace.Warn ("Unhandled Exception", e.ToString (), e);
1175 _lifeCycle = PageLifeCycle.Unload;
1178 UnloadRecursive (true);
1180 _lifeCycle = PageLifeCycle.End;
1183 if (Thread.CurrentThread.CurrentCulture.Equals (culture) == false)
1184 Thread.CurrentThread.CurrentCulture = culture;
1186 if (Thread.CurrentThread.CurrentUICulture.Equals (uiculture) == false)
1187 Thread.CurrentThread.CurrentUICulture = uiculture;
1192 internal void ProcessCrossPagePostBack (HttpContext context)
1194 isCrossPagePostBack = true;
1195 ProcessRequest (context);
1199 void InternalProcessRequest ()
1201 _requestValueCollection = this.DeterminePostBackMode();
1204 _lifeCycle = PageLifeCycle.Start;
1205 // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
1206 if (_requestValueCollection != null) {
1207 if (!isCrossPagePostBack && _requestValueCollection [PreviousPageID] != null && _requestValueCollection [PreviousPageID] != Request.FilePath) {
1208 _doLoadPreviousPage = true;
1211 isCallback = _requestValueCollection [CallbackArgumentID] != null;
1212 // LAMESPEC: on Callback IsPostBack is set to false, but true.
1213 //isPostBack = !isCallback;
1218 // if request was transfered from other page - track Prev. Page
1219 previousPage = _context.LastPage;
1220 _context.LastPage = this;
1222 _lifeCycle = PageLifeCycle.PreInit;
1223 OnPreInit (EventArgs.Empty);
1227 _lifeCycle = PageLifeCycle.Init;
1229 Trace.Write ("aspx.page", "Begin Init");
1230 InitRecursive (null);
1231 Trace.Write ("aspx.page", "End Init");
1234 _lifeCycle = PageLifeCycle.InitComplete;
1235 OnInitComplete (EventArgs.Empty);
1238 renderingForm = false;
1240 if (IsPostBack || IsCallback) {
1241 _lifeCycle = PageLifeCycle.PreLoad;
1242 if (_requestValueCollection != null)
1243 scriptManager.RestoreEventValidationState (_requestValueCollection [scriptManager.EventStateFieldName]);
1247 Trace.Write ("aspx.page", "Begin LoadViewState");
1248 LoadPageViewState ();
1249 Trace.Write ("aspx.page", "End LoadViewState");
1250 Trace.Write ("aspx.page", "Begin ProcessPostData");
1251 ProcessPostData (_requestValueCollection, false);
1252 Trace.Write ("aspx.page", "End ProcessPostData");
1256 OnPreLoad (EventArgs.Empty);
1257 _lifeCycle = PageLifeCycle.Load;
1262 if (IsPostBack || IsCallback) {
1263 _lifeCycle = PageLifeCycle.ControlEvents;
1267 Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
1268 ProcessPostData (secondPostData, true);
1269 Trace.Write ("aspx.page", "End ProcessPostData Second Try");
1270 Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
1271 RaiseChangedEvents ();
1272 Trace.Write ("aspx.page", "End Raise ChangedEvents");
1273 Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
1274 RaisePostBackEvents ();
1275 Trace.Write ("aspx.page", "End Raise PostBackEvent");
1279 _lifeCycle = PageLifeCycle.LoadComplete;
1280 OnLoadComplete (EventArgs.Empty);
1282 if (IsCrossPagePostBack)
1286 string result = ProcessCallbackData ();
1287 HtmlTextWriter callbackOutput = new HtmlTextWriter (_context.Response.Output);
1288 callbackOutput.Write (result);
1289 callbackOutput.Flush ();
1293 _lifeCycle = PageLifeCycle.PreRender;
1296 Trace.Write ("aspx.page", "Begin PreRender");
1297 PreRenderRecursiveInternal ();
1298 Trace.Write ("aspx.page", "End PreRender");
1301 _lifeCycle = PageLifeCycle.PreRenderComplete;
1302 OnPreRenderComplete (EventArgs.Empty);
1305 Trace.Write ("aspx.page", "Begin SaveViewState");
1306 SavePageViewState ();
1307 Trace.Write ("aspx.page", "End SaveViewState");
1310 _lifeCycle = PageLifeCycle.SaveStateComplete;
1311 OnSaveStateComplete (EventArgs.Empty);
1315 if (SaveViewStateForNextPortletRender())
1320 _lifeCycle = PageLifeCycle.Render;
1324 Trace.Write ("aspx.page", "Begin Render");
1325 HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
1326 RenderControl (output);
1327 Trace.Write ("aspx.page", "End Render");
1330 private void RenderTrace ()
1332 TraceManager traceManager = HttpRuntime.TraceManager;
1334 if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
1339 if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput)
1342 if (!traceManager.LocalOnly || Context.Request.IsLocal) {
1343 HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
1344 Trace.Render (output);
1349 bool CheckForValidationSupport (Control targetControl)
1351 if (targetControl == null)
1353 Type type = targetControl.GetType ();
1354 object[] attributes = type.GetCustomAttributes (false);
1355 foreach (object attr in attributes)
1356 if (attr is SupportsEventValidationAttribute)
1362 void RaisePostBackEvents ()
1365 Control targetControl;
1367 if (requiresRaiseEvent != null) {
1368 RaisePostBackEvent (requiresRaiseEvent, null);
1372 NameValueCollection postdata = _requestValueCollection;
1373 if (postdata == null)
1376 string eventTarget = postdata [postEventSourceID];
1377 if (eventTarget == null || eventTarget.Length == 0) {
1383 targetControl = FindControl (eventTarget);
1384 IPostBackEventHandler target = targetControl as IPostBackEventHandler;
1386 IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
1392 string eventArgument = postdata [postEventArgumentID];
1393 RaisePostBackEvent (target, eventArgument);
1396 internal void RaiseChangedEvents ()
1398 if (requiresPostDataChanged == null)
1401 foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
1402 ipdh.RaisePostDataChangedEvent ();
1404 requiresPostDataChanged = null;
1407 [EditorBrowsable (EditorBrowsableState.Advanced)]
1408 protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
1411 Control targetControl = sourceControl as Control;
1412 if (targetControl != null && CheckForValidationSupport (targetControl))
1413 scriptManager.ValidateEvent (targetControl.UniqueID, eventArgument);
1415 sourceControl.RaisePostBackEvent (eventArgument);
1421 [EditorBrowsable (EditorBrowsableState.Advanced)]
1422 public void RegisterArrayDeclaration (string arrayName, string arrayValue)
1424 scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
1430 [EditorBrowsable (EditorBrowsableState.Advanced)]
1431 public virtual void RegisterClientScriptBlock (string key, string script)
1433 scriptManager.RegisterClientScriptBlock (key, script);
1439 [EditorBrowsable (EditorBrowsableState.Advanced)]
1440 public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
1442 scriptManager.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
1445 [MonoTODO("Not implemented, Used in HtmlForm")]
1446 internal void RegisterClientScriptFile (string a, string b, string c)
1448 throw new NotImplementedException ();
1454 [EditorBrowsable (EditorBrowsableState.Advanced)]
1455 public void RegisterOnSubmitStatement (string key, string script)
1457 scriptManager.RegisterOnSubmitStatement (key, script);
1460 internal string GetSubmitStatements ()
1462 return scriptManager.WriteSubmitStatements ();
1465 [EditorBrowsable (EditorBrowsableState.Advanced)]
1466 public void RegisterRequiresPostBack (Control control)
1468 if (_requiresPostBack == null)
1469 _requiresPostBack = new ArrayList ();
1471 if (_requiresPostBack.Contains (control.UniqueID))
1474 _requiresPostBack.Add (control.UniqueID);
1477 [EditorBrowsable (EditorBrowsableState.Advanced)]
1478 public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
1480 requiresRaiseEvent = control;
1486 [EditorBrowsable (EditorBrowsableState.Advanced)]
1487 public virtual void RegisterStartupScript (string key, string script)
1489 scriptManager.RegisterStartupScript (key, script);
1492 [EditorBrowsable (EditorBrowsableState.Advanced)]
1493 public void RegisterViewStateHandler ()
1495 handleViewState = true;
1498 [EditorBrowsable (EditorBrowsableState.Advanced)]
1499 protected virtual void SavePageStateToPersistenceMedium (object viewState)
1501 PageStatePersister persister = this.PageStatePersister;
1502 if (persister == null)
1504 Pair pair = viewState as Pair;
1506 persister.ViewState = pair.First;
1507 persister.ControlState = pair.Second;
1509 persister.ViewState = viewState;
1513 internal string RawViewState {
1515 NameValueCollection postdata = _requestValueCollection;
1517 if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
1520 if (view_state == "")
1524 set { _savedViewState = value; }
1532 PageStatePersister PageStatePersister {
1534 if (page_state_persister == null)
1535 page_state_persister = new HiddenFieldPageStatePersister (this);
1536 return page_state_persister;
1540 [EditorBrowsable (EditorBrowsableState.Advanced)]
1541 protected virtual object LoadPageStateFromPersistenceMedium ()
1543 PageStatePersister persister = this.PageStatePersister;
1544 if (persister == null)
1547 return new Pair (persister.ViewState, persister.ControlState);
1550 internal void LoadPageViewState()
1552 Pair sState = LoadPageStateFromPersistenceMedium () as Pair;
1553 if (sState != null) {
1556 LoadPageControlState (sState.Second);
1558 Pair vsr = sState.First as Pair;
1560 LoadViewStateRecursive (vsr.First);
1561 _requiresPostBackCopy = vsr.Second as ArrayList;
1567 internal void SavePageViewState ()
1569 if (!handleViewState)
1573 object controlState = SavePageControlState ();
1576 object viewState = SaveViewStateRecursive ();
1577 object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
1580 if (viewState != null || reqPostback != null)
1581 vsr = new Pair (viewState, reqPostback);
1582 Pair pair = new Pair ();
1586 pair.Second = controlState;
1590 if (pair.First == null && pair.Second == null)
1591 SavePageStateToPersistenceMedium (null);
1593 SavePageStateToPersistenceMedium (pair);
1597 public virtual void Validate ()
1599 is_validated = true;
1600 ValidateCollection (_validators);
1604 internal bool AreValidatorsUplevel () {
1605 return AreValidatorsUplevel (String.Empty);
1608 internal bool AreValidatorsUplevel (string valGroup)
1610 internal virtual bool AreValidatorsUplevel ()
1613 bool uplevel = false;
1615 foreach (IValidator v in Validators) {
1616 BaseValidator bv = v as BaseValidator;
1617 if (bv == null) continue;
1620 if (valGroup != bv.ValidationGroup)
1623 if (bv.GetRenderUplevel()) {
1632 bool ValidateCollection (ValidatorCollection validators)
1635 if (!_eventValidation)
1639 if (validators == null || validators.Count == 0)
1642 bool all_valid = true;
1643 foreach (IValidator v in validators){
1645 if (v.IsValid == false)
1652 [EditorBrowsable (EditorBrowsableState.Advanced)]
1653 public virtual void VerifyRenderingInServerForm (Control control)
1655 if (_context == null)
1662 throw new HttpException ("Control '" +
1665 control.GetType ().Name +
1666 "' must be placed inside a form tag with runat=server.");
1669 protected override void FrameworkInitialize ()
1671 base.FrameworkInitialize ();
1673 InitializeStyleSheet ();
1684 ClientScriptManager ClientScript {
1685 get { return scriptManager; }
1690 static readonly object InitCompleteEvent = new object ();
1691 static readonly object LoadCompleteEvent = new object ();
1692 static readonly object PreInitEvent = new object ();
1693 static readonly object PreLoadEvent = new object ();
1694 static readonly object PreRenderCompleteEvent = new object ();
1695 static readonly object SaveStateCompleteEvent = new object ();
1697 const int initcomplete_mask = 1;
1698 const int loadcomplete_mask = 1 << 1;
1699 const int preinit_mask = 1 << 2;
1700 const int preload_mask = 1 << 3;
1701 const int prerendercomplete_mask = 1 << 4;
1702 const int savestatecomplete_mask = 1 << 5;
1704 [EditorBrowsable (EditorBrowsableState.Advanced)]
1705 public event EventHandler InitComplete {
1707 event_mask |= initcomplete_mask;
1708 Events.AddHandler (InitCompleteEvent, value);
1710 remove { Events.RemoveHandler (InitCompleteEvent, value); }
1713 [EditorBrowsable (EditorBrowsableState.Advanced)]
1714 public event EventHandler LoadComplete {
1716 event_mask |= loadcomplete_mask;
1717 Events.AddHandler (LoadCompleteEvent, value);
1719 remove { Events.RemoveHandler (LoadCompleteEvent, value); }
1722 public event EventHandler PreInit {
1724 event_mask |= preinit_mask;
1725 Events.AddHandler (PreInitEvent, value);
1727 remove { Events.RemoveHandler (PreInitEvent, value); }
1730 [EditorBrowsable (EditorBrowsableState.Advanced)]
1731 public event EventHandler PreLoad {
1733 event_mask |= preload_mask;
1734 Events.AddHandler (PreLoadEvent, value);
1736 remove { Events.RemoveHandler (PreLoadEvent, value); }
1739 [EditorBrowsable (EditorBrowsableState.Advanced)]
1740 public event EventHandler PreRenderComplete {
1742 event_mask |= prerendercomplete_mask;
1743 Events.AddHandler (PreRenderCompleteEvent, value);
1745 remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
1748 [EditorBrowsable (EditorBrowsableState.Advanced)]
1749 public event EventHandler SaveStateComplete {
1751 event_mask |= savestatecomplete_mask;
1752 Events.AddHandler (SaveStateCompleteEvent, value);
1754 remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
1757 protected virtual void OnInitComplete (EventArgs e)
1759 if ((event_mask & initcomplete_mask) != 0) {
1760 EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
1761 if (eh != null) eh (this, e);
1765 protected virtual void OnLoadComplete (EventArgs e)
1767 if ((event_mask & loadcomplete_mask) != 0) {
1768 EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
1769 if (eh != null) eh (this, e);
1773 protected virtual void OnPreInit (EventArgs e)
1775 if ((event_mask & preinit_mask) != 0) {
1776 EventHandler eh = (EventHandler) (Events [PreInitEvent]);
1777 if (eh != null) eh (this, e);
1781 protected virtual void OnPreLoad (EventArgs e)
1783 if ((event_mask & preload_mask) != 0) {
1784 EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
1785 if (eh != null) eh (this, e);
1789 protected virtual void OnPreRenderComplete (EventArgs e)
1791 if ((event_mask & prerendercomplete_mask) != 0) {
1792 EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
1793 if (eh != null) eh (this, e);
1798 if (!Form.DetermineRenderUplevel ())
1801 /* figure out if we have some control we're going to focus */
1802 if (String.IsNullOrEmpty (_focusedControlID)) {
1803 _focusedControlID = Form.DefaultFocus;
1804 if (String.IsNullOrEmpty (_focusedControlID))
1805 _focusedControlID = Form.DefaultButton;
1808 if (!String.IsNullOrEmpty (_focusedControlID) || Form.SubmitDisabledControls) {
1810 ClientScript.RegisterWebFormClientScript ();
1812 if (!String.IsNullOrEmpty (_focusedControlID)) {
1813 ClientScript.RegisterStartupScript ("HtmlForm-DefaultButton-StartupScript",
1814 String.Format ("<script type=\"text/javascript\">\n" +
1816 "WebForm_AutoFocus('{0}');// -->\n" +
1817 "</script>\n", _focusedControlID));
1820 if (Form.SubmitDisabledControls) {
1821 ClientScript.RegisterOnSubmitStatement ("HtmlForm-SubmitDisabledControls-SubmitStatement",
1822 "WebForm_ReEnableControls(this);");
1827 protected virtual void OnSaveStateComplete (EventArgs e)
1829 if ((event_mask & savestatecomplete_mask) != 0) {
1830 EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
1831 if (eh != null) eh (this, e);
1835 public HtmlForm Form {
1836 get { return _form; }
1839 internal void RegisterForm (HtmlForm form)
1844 [BrowsableAttribute (false)]
1845 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1846 public Page PreviousPage {
1848 if (_doLoadPreviousPage) {
1849 _doLoadPreviousPage = false;
1850 LoadPreviousPageReference ();
1852 return previousPage;
1857 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1858 [BrowsableAttribute (false)]
1859 public bool IsCallback {
1860 get { return isCallback; }
1863 [BrowsableAttribute (false)]
1864 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1865 public bool IsCrossPagePostBack {
1866 get { return isCrossPagePostBack; }
1869 public new virtual char IdSeparator {
1871 //TODO: why override?
1872 return base.IdSeparator;
1876 string ProcessCallbackData ()
1878 string callbackTarget = _requestValueCollection [CallbackSourceID];
1879 if (callbackTarget == null || callbackTarget.Length == 0)
1880 throw new HttpException ("Callback target not provided.");
1882 Control targetControl = FindControl (callbackTarget);
1883 ICallbackEventHandler target = targetControl as ICallbackEventHandler;
1885 throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
1887 string callbackEventError = String.Empty;
1888 string callBackResult;
1889 string callbackArgument = _requestValueCollection [CallbackArgumentID];
1892 target.RaiseCallbackEvent (callbackArgument);
1894 catch (Exception ex) {
1895 callbackEventError = String.Format ("e{0}", ex.Message);
1899 callBackResult = target.GetCallbackResult ();
1901 catch (Exception ex) {
1902 return String.Format ("e{0}", ex.Message);
1905 string eventValidation = ClientScript.GetEventValidationStateFormatted ();
1906 return String.Format ("{0}{1}|{2}{3}", callbackEventError, eventValidation == null ? 0 : eventValidation.Length, eventValidation, callBackResult);
1909 [BrowsableAttribute (false)]
1910 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
1911 public HtmlHead Header {
1912 get { return htmlHeader; }
1915 internal void SetHeader (HtmlHead header)
1917 htmlHeader = header;
1918 if (_title != null) {
1919 htmlHeader.Title = _title;
1924 [MonoTODO("Not Implemented")]
1925 protected bool AsyncMode {
1927 throw new NotImplementedException ();
1930 throw new NotImplementedException ();
1934 [MonoTODO ("Not Implemented")]
1935 public TimeSpan AsyncTimeout {
1937 throw new NotImplementedException ();
1940 throw new NotImplementedException ();
1944 [MonoTODO ("Not Implemented")]
1945 public bool IsAsync {
1947 throw new NotImplementedException ();
1951 [MonoTODO ("Not Implemented")]
1952 protected internal virtual string UniqueFilePathSuffix {
1954 throw new NotImplementedException ();
1958 [MonoTODO ("Not Implemented")]
1959 public int MaxPageStateFieldLength {
1961 throw new NotImplementedException ();
1964 throw new NotImplementedException ();
1968 [MonoTODO ("Not Implemented")]
1969 public ViewStateEncryptionMode ViewStateEncryptionMode {
1971 throw new NotImplementedException ();
1974 throw new NotImplementedException ();
1978 [MonoTODO ("Not Implemented")]
1979 public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler)
1981 throw new NotImplementedException ();
1984 [MonoTODO ("Not Implemented")]
1985 public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, Object state)
1987 throw new NotImplementedException ();
1990 [MonoTODO ("Not Implemented")]
1991 public void ExecuteRegisteredAsyncTasks ()
1993 throw new NotImplementedException ();
1996 [MonoTODO ("Not Implemented")]
1997 public static HtmlTextWriter CreateHtmlTextWriterFromType (TextWriter tw, Type writerType)
1999 throw new NotImplementedException ();
2002 [MonoTODO ("Not Implemented")]
2003 public void RegisterRequiresViewStateEncryption ()
2005 throw new NotImplementedException ();
2008 void ApplyMasterPage ()
2010 if (masterPageFile != null && masterPageFile.Length > 0) {
2011 ArrayList appliedMasterPageFiles = new ArrayList ();
2013 if (Master != null) {
2014 MasterPage.ApplyMasterPageRecursive (Master, appliedMasterPageFiles);
2018 Controls.Add (Master);
2023 [DefaultValueAttribute ("")]
2024 public virtual string MasterPageFile {
2025 get { return masterPageFile; }
2027 masterPageFile = value;
2032 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
2033 [BrowsableAttribute (false)]
2034 public MasterPage Master {
2036 if (Context == null || String.IsNullOrEmpty (masterPageFile))
2039 if (masterPage == null)
2040 masterPage = MasterPage.CreateMasterPage (this, Context, masterPageFile, contentTemplates);
2046 public void SetFocus (string clientID)
2048 if (String.IsNullOrEmpty (clientID))
2049 throw new ArgumentNullException ("control");
2051 if (_lifeCycle > PageLifeCycle.PreRender)
2052 throw new InvalidOperationException ("SetFocus can only be called before and during PreRender.");
2055 throw new InvalidOperationException ("A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.");
2057 _focusedControlID = clientID;
2060 public void SetFocus (Control control)
2062 if (control == null)
2063 throw new ArgumentNullException ("control");
2065 SetFocus (control.ClientID);
2068 [EditorBrowsable (EditorBrowsableState.Advanced)]
2069 public void RegisterRequiresControlState (Control control)
2071 if (control == null)
2072 throw new ArgumentNullException ("control");
2074 if (RequiresControlState (control))
2077 if (requireStateControls == null)
2078 requireStateControls = new ArrayList ();
2079 int n = requireStateControls.Add (control);
2081 if (_savedControlState == null || n >= _savedControlState.Length)
2084 for (Control parent = control.Parent; parent != null; parent = parent.Parent)
2085 if (parent.IsChildControlStateCleared)
2088 object state = _savedControlState [n];
2090 control.LoadControlState (state);
2093 public bool RequiresControlState (Control control)
2095 if (requireStateControls == null) return false;
2096 return requireStateControls.Contains (control);
2099 [EditorBrowsable (EditorBrowsableState.Advanced)]
2100 public void UnregisterRequiresControlState (Control control)
2102 if (requireStateControls != null)
2103 requireStateControls.Remove (control);
2106 public ValidatorCollection GetValidators (string validationGroup)
2108 string valgr = validationGroup;
2110 valgr = String.Empty;
2112 if (_validatorsByGroup == null) _validatorsByGroup = new Hashtable ();
2113 ValidatorCollection col = _validatorsByGroup [valgr] as ValidatorCollection;
2115 col = new ValidatorCollection ();
2116 _validatorsByGroup [valgr] = col;
2121 public virtual void Validate (string validationGroup)
2123 is_validated = true;
2124 if (validationGroup == null)
2125 ValidateCollection (_validatorsByGroup [String.Empty] as ValidatorCollection);
2126 else if (_validatorsByGroup != null) {
2127 ValidateCollection (_validatorsByGroup [validationGroup] as ValidatorCollection);
2131 object SavePageControlState ()
2133 if (requireStateControls == null) return null;
2134 object[] state = new object [requireStateControls.Count];
2136 bool allNull = true;
2137 for (int n=0; n<state.Length; n++) {
2138 state [n] = ((Control) requireStateControls [n]).SaveControlState ();
2139 if (state [n] != null) allNull = false;
2141 if (allNull) return null;
2145 void LoadPageControlState (object data)
2147 _savedControlState = (object []) data;
2149 if (requireStateControls == null) return;
2151 int max = Math.Min (requireStateControls.Count, _savedControlState != null ? _savedControlState.Length : requireStateControls.Count);
2152 for (int n=0; n < max; n++) {
2153 Control ctl = (Control) requireStateControls [n];
2154 ctl.LoadControlState (_savedControlState != null ? _savedControlState [n] : null);
2158 void LoadPreviousPageReference ()
2160 if (_requestValueCollection != null) {
2161 string prevPage = _requestValueCollection [PreviousPageID];
2162 if (prevPage != null) {
2163 previousPage = (Page) PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
2164 previousPage.ProcessCrossPagePostBack (_context);
2170 Hashtable contentTemplates;
2171 [EditorBrowsable (EditorBrowsableState.Never)]
2172 protected internal void AddContentTemplate (string templateName, ITemplate template)
2174 if (contentTemplates == null)
2175 contentTemplates = new Hashtable ();
2176 contentTemplates [templateName] = template;
2179 PageTheme _pageTheme;
2180 internal PageTheme PageTheme {
2181 get { return _pageTheme; }
2184 PageTheme _styleSheetPageTheme;
2185 internal PageTheme StyleSheetPageTheme {
2186 get { return _styleSheetPageTheme; }
2191 internal void PushDataItemContext (object o) {
2192 if (dataItemCtx == null)
2193 dataItemCtx = new Stack ();
2195 dataItemCtx.Push (o);
2198 internal void PopDataItemContext () {
2199 if (dataItemCtx == null)
2200 throw new InvalidOperationException ();
2205 public object GetDataItem() {
2206 if (dataItemCtx == null || dataItemCtx.Count == 0)
2207 throw new InvalidOperationException ("No data item");
2209 return dataItemCtx.Peek ();
2212 protected internal override void OnInit (EventArgs e)
2216 ArrayList themes = new ArrayList();
2218 if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
2219 themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
2220 if (PageTheme != null && PageTheme.GetStyleSheets () != null)
2221 themes.AddRange (PageTheme.GetStyleSheets ());
2223 if (themes.Count > 0 && Header == null)
2224 throw new InvalidOperationException ("Using themed css files requires a header control on the page.");
2226 foreach (string lss in themes) {
2227 HtmlLink hl = new HtmlLink ();
2228 hl.Href = ResolveUrl (lss);
2229 hl.Attributes["type"] = "text/css";
2230 hl.Attributes["rel"] = "stylesheet";
2231 Header.Controls.Add (hl);
2238 [MonoTODO ("Not implemented. Only used by .net aspx parser")]
2239 protected object GetWrappedFileDependencies (string [] list)
2244 [MonoTODO ("Does nothing. Used by .net aspx parser")]
2245 protected virtual void InitializeCulture ()
2249 [MonoTODO ("Does nothing. Used by .net aspx parser")]
2250 protected internal void AddWrappedFileDependencies (object virtualFileDependencies)