| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180 |
- //
- // System.Web.UI.Page.cs
- //
- // Authors:
- // Duncan Mak ([email protected])
- // Gonzalo Paniagua ([email protected])
- // Andreas Nahr ([email protected])
- //
- // (C) 2002,2003 Ximian, Inc. (http://www.ximian.com)
- // Copyright (C) 2003,2005 Novell, Inc (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System;
- using System.Collections;
- using System.Collections.Specialized;
- using System.ComponentModel;
- using System.ComponentModel.Design;
- using System.ComponentModel.Design.Serialization;
- using System.Globalization;
- using System.IO;
- using System.Security.Cryptography;
- using System.Security.Permissions;
- using System.Security.Principal;
- using System.Text;
- using System.Threading;
- using System.Web;
- using System.Web.Caching;
- using System.Web.Configuration;
- using System.Web.SessionState;
- using System.Web.Util;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- #if NET_2_0
- using System.Web.UI.Adapters;
- #endif
- namespace System.Web.UI
- {
- // CAS
- [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
- [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
- #if !NET_2_0
- [RootDesignerSerializer ("Microsoft.VSDesigner.WebForms.RootCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design, true)]
- #endif
- [DefaultEvent ("Load"), DesignerCategory ("ASPXCodeBehind")]
- [ToolboxItem (false)]
- #if NET_2_0
- [Designer ("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VisualStudio_Web, typeof (IRootDesigner))]
- #else
- [Designer ("Microsoft.VSDesigner.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VSDesigner, typeof (IRootDesigner))]
- #endif
- public class Page : TemplateControl, IHttpHandler
- {
- #if NET_2_0
- private PageLifeCycle _lifeCycle = PageLifeCycle.Unknown;
- private bool _eventValidation = true;
- private object [] _savedControlState;
- private bool _doLoadPreviousPage;
- string _focusedControlID;
- #endif
- private bool _viewState = true;
- private bool _viewStateMac;
- private string _errorPage;
- private bool is_validated;
- private bool _smartNavigation;
- private int _transactionMode;
- private HttpContext _context;
- private ValidatorCollection _validators;
- private bool renderingForm;
- private string _savedViewState;
- private ArrayList _requiresPostBack;
- private ArrayList _requiresPostBackCopy;
- private ArrayList requiresPostDataChanged;
- private IPostBackEventHandler requiresRaiseEvent;
- private NameValueCollection secondPostData;
- private bool requiresPostBackScript;
- private bool postBackScriptRendered;
- bool handleViewState;
- string viewStateUserKey;
- NameValueCollection _requestValueCollection;
- string clientTarget;
- ClientScriptManager scriptManager;
- bool allow_load; // true when the Form collection belongs to this page (GetTypeHashCode)
- PageStatePersister page_state_persister;
- [EditorBrowsable (EditorBrowsableState.Never)]
- #if NET_2_0
- public
- #else
- protected
- #endif
- const string postEventArgumentID = "__EVENTARGUMENT";
- [EditorBrowsable (EditorBrowsableState.Never)]
- #if NET_2_0
- public
- #else
- protected
- #endif
- const string postEventSourceID = "__EVENTTARGET";
- #if NET_2_0
- const string ScrollPositionXID = "__SCROLLPOSITIONX";
- const string ScrollPositionYID = "__SCROLLPOSITIONY";
- #endif
- #if NET_2_0
- internal const string CallbackArgumentID = "__CALLBACKARGUMENT";
- internal const string CallbackSourceID = "__CALLBACKTARGET";
- internal const string PreviousPageID = "__PREVIOUSPAGE";
-
- HtmlHead htmlHeader;
-
- MasterPage masterPage;
- string masterPageFile;
-
- Page previousPage;
- bool isCrossPagePostBack;
- bool isPostBack;
- bool isCallback;
- ArrayList requireStateControls;
- Hashtable _validatorsByGroup;
- HtmlForm _form;
- string _title;
- string _theme;
- string _styleSheetTheme;
- Hashtable items;
- bool _maintainScrollPositionOnPostBack;
- #endif
- #region Constructor
- public Page ()
- {
- scriptManager = new ClientScriptManager (this);
- Page = this;
- ID = "__Page";
- }
- #endregion
- #region Properties
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- public HttpApplicationState Application
- {
- get {
- if (_context == null)
- return null;
- return _context.Application;
- }
- }
- [EditorBrowsable (EditorBrowsableState.Never)]
- protected bool AspCompatMode
- {
- #if NET_2_0
- get { return false; }
- #endif
- set { throw new NotImplementedException (); }
- }
- [EditorBrowsable (EditorBrowsableState.Never)]
- #if NET_2_0
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public bool Buffer
- {
- get { return Response.BufferOutput; }
- set { Response.BufferOutput = value; }
- }
- #else
- protected bool Buffer
- {
- set { Response.BufferOutput = value; }
- }
- #endif
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- public Cache Cache
- {
- get {
- if (_context == null)
- throw new HttpException ("No cache available without a context.");
- return _context.Cache;
- }
- }
- #if NET_2_0
- [EditorBrowsableAttribute (EditorBrowsableState.Advanced)]
- #endif
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false), DefaultValue ("")]
- [WebSysDescription ("Value do override the automatic browser detection and force the page to use the specified browser.")]
- public string ClientTarget
- {
- get { return (clientTarget == null) ? "" : clientTarget; }
- set {
- clientTarget = value;
- if (value == "")
- clientTarget = null;
- }
- }
- [EditorBrowsable (EditorBrowsableState.Never)]
- #if NET_2_0
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public int CodePage
- {
- get { return Response.ContentEncoding.CodePage; }
- set { Response.ContentEncoding = Encoding.GetEncoding (value); }
- }
- #else
- protected int CodePage
- {
- set { Response.ContentEncoding = Encoding.GetEncoding (value); }
- }
- #endif
- [EditorBrowsable (EditorBrowsableState.Never)]
- #if NET_2_0
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public string ContentType
- {
- get { return Response.ContentType; }
- set { Response.ContentType = value; }
- }
- #else
- protected string ContentType
- {
- set { Response.ContentType = value; }
- }
- #endif
- protected override HttpContext Context
- {
- get {
- if (_context == null)
- return HttpContext.Current;
- return _context;
- }
- }
- #if NET_2_0
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public string Culture
- {
- get { return Thread.CurrentThread.CurrentCulture.Name; }
- set { Thread.CurrentThread.CurrentCulture = GetPageCulture (value, Thread.CurrentThread.CurrentCulture); }
- }
- #else
- [EditorBrowsable (EditorBrowsableState.Never)]
- protected string Culture
- {
- set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
- }
- #endif
- #if NET_2_0
- public virtual bool EnableEventValidation {
- get { return _eventValidation; }
- set {
- if (_lifeCycle > PageLifeCycle.Init)
- throw new InvalidOperationException ("The 'EnableEventValidation' property can be set only in the Page_init, the Page directive or in the <pages> configuration section.");
- _eventValidation = value;
- }
- }
- internal PageLifeCycle LifeCycle {
- get { return _lifeCycle; }
- }
- #endif
- [Browsable (false)]
- public override bool EnableViewState
- {
- get { return _viewState; }
- set { _viewState = value; }
- }
- #if NET_2_0
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- #endif
- [EditorBrowsable (EditorBrowsableState.Never)]
- #if NET_2_0
- public
- #else
- protected
- #endif
- bool EnableViewStateMac
- {
- get { return _viewStateMac; }
- set { _viewStateMac = value; }
- }
- #if NET_1_1
- internal bool EnableViewStateMacInternal {
- get { return _viewStateMac; }
- set { _viewStateMac = value; }
- }
- #endif
-
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false), DefaultValue ("")]
- [WebSysDescription ("The URL of a page used for error redirection.")]
- public string ErrorPage
- {
- get { return _errorPage; }
- set {
- _errorPage = value;
- if (_context != null)
- _context.ErrorPage = value;
- }
- }
- #if NET_2_0
- [Obsolete]
- #endif
- [EditorBrowsable (EditorBrowsableState.Never)]
- protected ArrayList FileDependencies
- {
- set {
- if (Response != null)
- Response.AddFileDependencies (value);
- }
- }
- [Browsable (false)]
- #if NET_2_0
- [EditorBrowsable (EditorBrowsableState.Never)]
- #endif
- public override string ID
- {
- get { return base.ID; }
- set { base.ID = value; }
- }
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- public bool IsPostBack
- {
- get {
- #if NET_2_0
- return isPostBack;
- #else
- return _requestValueCollection != null;
- #endif
- }
- }
- [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
- public bool IsReusable {
- get { return false; }
- }
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- public bool IsValid {
- get {
- if (!is_validated)
- throw new HttpException (Locale.GetText ("Page hasn't been validated."));
- #if NET_2_0
- foreach (IValidator val in Validators)
- if (!val.IsValid)
- return false;
- return true;
- #else
- return ValidateCollection (_validators);
- #endif
- }
- }
- #if NET_2_0
- public IDictionary Items {
- get {
- if (items == null)
- items = new Hashtable ();
- return items;
- }
- }
- #endif
- [EditorBrowsable (EditorBrowsableState.Never)]
- #if NET_2_0
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public int LCID {
- get { return Thread.CurrentThread.CurrentCulture.LCID; }
- set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
- }
- #else
- protected int LCID {
- set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
- }
- #endif
- #if NET_2_0
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public bool MaintainScrollPositionOnPostBack {
- get { return _maintainScrollPositionOnPostBack; }
- set { _maintainScrollPositionOnPostBack = value; }
- }
- #endif
- #if NET_2_0
- public PageAdapter PageAdapter {
- get {
- return (PageAdapter)Adapter;
- }
- }
- #endif
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- public HttpRequest Request
- {
- get {
- if (_context != null)
- return _context.Request;
- throw new HttpException("Request is not available without context");
- }
- }
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- public HttpResponse Response
- {
- get {
- if (_context != null)
- return _context.Response;
- throw new HttpException ("Response is not available without context");
- }
- }
- [EditorBrowsable (EditorBrowsableState.Never)]
- #if NET_2_0
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public string ResponseEncoding
- {
- get { return Response.ContentEncoding.WebName; }
- set { Response.ContentEncoding = Encoding.GetEncoding (value); }
- }
- #else
- protected string ResponseEncoding
- {
- set { Response.ContentEncoding = Encoding.GetEncoding (value); }
- }
- #endif
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- public HttpServerUtility Server
- {
- get {
- return Context.Server;
- }
- }
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- public virtual HttpSessionState Session
- {
- get {
- if (_context == null)
- _context = HttpContext.Current;
- if (_context == null)
- throw new HttpException ("Session is not available without context");
- if (_context.Session == null)
- throw new HttpException ("Session state can only be used " +
- "when enableSessionState is set to true, either " +
- "in a configuration file or in the Page directive.");
- return _context.Session;
- }
- }
- #if NET_2_0
- [FilterableAttribute (false)]
- [Obsolete]
- #endif
- [Browsable (false)]
- public bool SmartNavigation
- {
- get { return _smartNavigation; }
- set { _smartNavigation = value; }
- }
- #if NET_2_0
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Filterable (false)]
- [Browsable (false)]
- public virtual string StyleSheetTheme {
- get { return _styleSheetTheme; }
- set { _styleSheetTheme = value; }
- }
- [Browsable (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public virtual string Theme {
- get { return _theme; }
- set { _theme = value; }
- }
- void InitializeStyleSheet ()
- {
- if (_styleSheetTheme == null) {
- PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
- if (ps != null)
- _styleSheetTheme = ps.StyleSheetTheme;
- }
- if (_styleSheetTheme != null && _styleSheetTheme != "")
- _styleSheetPageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_styleSheetTheme, _context);
- }
- void InitializeTheme ()
- {
- if (_theme == null) {
- PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
- if (ps != null)
- _theme = ps.Theme;
- }
- if (_theme != null && _theme != "") {
- _pageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_theme, _context);
- }
- }
- #endif
- #if NET_2_0
- [Localizable (true)]
- [Bindable (true)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public string Title {
- get {
- if (_title == null)
- return htmlHeader.Title;
- return _title;
- }
- set {
- if (htmlHeader != null)
- htmlHeader.Title = value;
- else
- _title = value;
- }
- }
- #endif
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- public TraceContext Trace
- {
- get { return Context.Trace; }
- }
- [EditorBrowsable (EditorBrowsableState.Never)]
- #if NET_2_0
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public bool TraceEnabled
- {
- get { return Trace.IsEnabled; }
- set { Trace.IsEnabled = value; }
- }
- #else
- protected bool TraceEnabled
- {
- set { Trace.IsEnabled = value; }
- }
- #endif
- [EditorBrowsable (EditorBrowsableState.Never)]
- #if NET_2_0
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public TraceMode TraceModeValue
- {
- get { return Trace.TraceMode; }
- set { Trace.TraceMode = value; }
- }
- #else
- protected TraceMode TraceModeValue
- {
- set { Trace.TraceMode = value; }
- }
- #endif
- [EditorBrowsable (EditorBrowsableState.Never)]
- protected int TransactionMode
- {
- #if NET_2_0
- get { return _transactionMode; }
- #endif
- set { _transactionMode = value; }
- }
- #if NET_2_0
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public string UICulture
- {
- get { return Thread.CurrentThread.CurrentUICulture.Name; }
- set { Thread.CurrentThread.CurrentUICulture = GetPageCulture (value, Thread.CurrentThread.CurrentUICulture); }
- }
- #else
- [EditorBrowsable (EditorBrowsableState.Never)]
- protected string UICulture
- {
- set { Thread.CurrentThread.CurrentUICulture = new CultureInfo (value); }
- }
- #endif
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- public IPrincipal User
- {
- get { return Context.User; }
- }
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [Browsable (false)]
- public ValidatorCollection Validators
- {
- get {
- if (_validators == null)
- _validators = new ValidatorCollection ();
- return _validators;
- }
- }
- [MonoTODO ("Use this when encrypting/decrypting ViewState")]
- [Browsable (false)]
- public string ViewStateUserKey {
- get { return viewStateUserKey; }
- set { viewStateUserKey = value; }
- }
- [Browsable (false)]
- public override bool Visible
- {
- get { return base.Visible; }
- set { base.Visible = value; }
- }
- #endregion
- #region Methods
- #if NET_2_0
- CultureInfo GetPageCulture (string culture, CultureInfo deflt)
- {
- if (culture == null)
- return deflt;
- CultureInfo ret = null;
- if (culture.StartsWith ("auto")) {
- string[] languages = Request.UserLanguages;
- try {
- if (languages != null && languages.Length > 0)
- ret = new CultureInfo (languages[0]);
- } catch {
- }
-
- if (ret == null)
- ret = deflt;
- } else
- ret = new CultureInfo (culture);
- return ret;
- }
- #endif
- [EditorBrowsable (EditorBrowsableState.Never)]
- protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
- AsyncCallback cb,
- object extraData)
- {
- throw new NotImplementedException ();
- }
- [EditorBrowsable (EditorBrowsableState.Never)]
- protected void AspCompatEndProcessRequest (IAsyncResult result)
- {
- throw new NotImplementedException ();
- }
-
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
- {
- return new HtmlTextWriter (tw);
- }
- [EditorBrowsable (EditorBrowsableState.Never)]
- public void DesignerInitialize ()
- {
- InitRecursive (null);
- }
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- protected virtual NameValueCollection DeterminePostBackMode ()
- {
- if (_context == null)
- return null;
- HttpRequest req = _context.Request;
- if (req == null)
- return null;
- NameValueCollection coll = null;
- if (0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture)) {
- coll = req.Form;
- WebROCollection c = (WebROCollection) coll;
- allow_load = !c.GotID;
- if (allow_load) {
- c.ID = GetTypeHashCode ();
- } else {
- allow_load = (c.ID == GetTypeHashCode ());
- }
- } else {
- coll = req.QueryString;
- }
- if (coll != null && coll ["__VIEWSTATE"] == null && coll ["__EVENTTARGET"] == null)
- return null;
- return coll;
- }
- #if NET_2_0
- public override Control FindControl (string id) {
- if (id == ID)
- return this;
- else
- return base.FindControl (id);
- }
- #endif
- #if NET_2_0
- [Obsolete]
- #endif
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public string GetPostBackClientEvent (Control control, string argument)
- {
- return scriptManager.GetPostBackEventReference (control, argument);
- }
- #if NET_2_0
- [Obsolete]
- #endif
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public string GetPostBackClientHyperlink (Control control, string argument)
- {
- return scriptManager.GetPostBackClientHyperlink (control, argument);
- }
- #if NET_2_0
- [Obsolete]
- #endif
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public string GetPostBackEventReference (Control control)
- {
- return scriptManager.GetPostBackEventReference (control, "");
- }
- #if NET_2_0
- [Obsolete]
- #endif
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public string GetPostBackEventReference (Control control, string argument)
- {
- return scriptManager.GetPostBackEventReference (control, argument);
- }
- internal void RequiresPostBackScript ()
- {
- requiresPostBackScript = true;
- }
- [EditorBrowsable (EditorBrowsableState.Never)]
- public virtual int GetTypeHashCode ()
- {
- return 0;
- }
- #if NET_2_0
- [MonoTODO("The following properties of OutputCacheParameters are silently ignored: CacheProfile, NoStore, SqlDependency")]
- protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings)
- {
- if (cacheSettings.Enabled)
- InitOutputCache(cacheSettings.Duration,
- cacheSettings.VaryByHeader,
- cacheSettings.VaryByCustom,
- cacheSettings.Location,
- cacheSettings.VaryByParam);
- }
- #endif
- [EditorBrowsable (EditorBrowsableState.Never)]
- protected virtual void InitOutputCache (int duration,
- string varyByHeader,
- string varyByCustom,
- OutputCacheLocation location,
- string varyByParam)
- {
- HttpCachePolicy cache = _context.Response.Cache;
- bool set_vary = false;
- switch (location) {
- case OutputCacheLocation.Any:
- cache.SetCacheability (HttpCacheability.Public);
- cache.SetMaxAge (new TimeSpan (0, 0, duration));
- cache.SetLastModified (_context.Timestamp);
- set_vary = true;
- break;
- case OutputCacheLocation.Client:
- cache.SetCacheability (HttpCacheability.Private);
- cache.SetMaxAge (new TimeSpan (0, 0, duration));
- cache.SetLastModified (_context.Timestamp);
- break;
- case OutputCacheLocation.Downstream:
- cache.SetCacheability (HttpCacheability.Public);
- cache.SetMaxAge (new TimeSpan (0, 0, duration));
- cache.SetLastModified (_context.Timestamp);
- break;
- case OutputCacheLocation.Server:
- cache.SetCacheability (HttpCacheability.Server);
- set_vary = true;
- break;
- case OutputCacheLocation.None:
- break;
- }
- if (set_vary) {
- if (varyByCustom != null)
- cache.SetVaryByCustom (varyByCustom);
- if (varyByParam != null && varyByParam.Length > 0) {
- string[] prms = varyByParam.Split (';');
- foreach (string p in prms)
- cache.VaryByParams [p.Trim ()] = true;
- cache.VaryByParams.IgnoreParams = false;
- } else {
- cache.VaryByParams.IgnoreParams = true;
- }
-
- if (varyByHeader != null && varyByHeader.Length > 0) {
- string[] hdrs = varyByHeader.Split (';');
- foreach (string h in hdrs)
- cache.VaryByHeaders [h.Trim ()] = true;
- }
- }
-
- cache.Duration = duration;
- cache.SetExpires (_context.Timestamp.AddSeconds (duration));
- }
- #if NET_2_0
- [Obsolete]
- #else
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- #endif
- public bool IsClientScriptBlockRegistered (string key)
- {
- return scriptManager.IsClientScriptBlockRegistered (key);
- }
- #if NET_2_0
- [Obsolete]
- #else
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- #endif
- public bool IsStartupScriptRegistered (string key)
- {
- return scriptManager.IsStartupScriptRegistered (key);
- }
- public string MapPath (string virtualPath)
- {
- return Request.MapPath (virtualPath);
- }
- #if NET_2_0
- protected internal override void Render (HtmlTextWriter writer) {
- if (MaintainScrollPositionOnPostBack) {
- RequiresPostBackScript ();
- string scriptUrl = ClientScript.GetWebResourceUrl (typeof (Page), "MaintainScrollPositionOnPostBack.js");
- ClientScript.RegisterClientScriptInclude (typeof (Page), "MaintainScrollPositionOnPostBack.js", scriptUrl);
- ClientScript.RegisterHiddenField (ScrollPositionXID, Request [ScrollPositionXID]);
- ClientScript.RegisterHiddenField (ScrollPositionYID, Request [ScrollPositionYID]);
-
- StringBuilder script = new StringBuilder ();
- script.AppendLine ("<script type=\"text/javascript\">");
- script.AppendLine ("<!--");
- script.AppendLine ("theForm.oldSubmit = theForm.submit");
- script.AppendLine ("theForm.submit = WebForm_SaveScrollPositionSubmit");
- script.AppendLine ("theForm.oldOnSubmit = theForm.onsubmit");
- script.AppendLine ("theForm.onsubmit = WebForm_SaveScrollPositionOnSubmit");
- if (IsPostBack) {
- script.AppendLine ("theForm.oldOnLoad = window.onload");
- script.AppendLine ("window.onload = WebForm_RestoreScrollPosition");
- }
- script.AppendLine ("// -->");
- script.AppendLine ("</script>");
-
- ClientScript.RegisterStartupScript (typeof (Page), "MaintainScrollPositionOnPostBackStartup", script.ToString());
- }
- base.Render (writer);
- }
- #endif
- private void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
- {
- writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventSourceID);
- writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventArgumentID);
- writer.WriteLine ();
- writer.WriteLine ("<script language=\"javascript\">");
- writer.WriteLine ("<!--");
- writer.WriteLine ("\tvar theForm;\n\tif (document.getElementById) {{ theForm = document.getElementById ('{0}'); }}", formUniqueID);
- writer.WriteLine ("\telse {{ theForm = document.{0}; }}", formUniqueID);
- writer.WriteLine ("\tfunction __doPostBack(eventTarget, eventArgument) {");
- writer.WriteLine ("\t\tif(!ValidatorOnSubmit()) return;");
- writer.WriteLine ("\t\ttheForm.{0}.value = eventTarget;", postEventSourceID);
- writer.WriteLine ("\t\ttheForm.{0}.value = eventArgument;", postEventArgumentID);
- writer.WriteLine ("\t\ttheForm.submit();");
- writer.WriteLine ("\t}");
- writer.WriteLine ("// -->");
- writer.WriteLine ("</script>");
- }
- internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
- {
- if (renderingForm)
- throw new HttpException ("Only 1 HtmlForm is allowed per page.");
- renderingForm = true;
- writer.WriteLine ();
- scriptManager.WriteHiddenFields (writer);
- if (requiresPostBackScript) {
- RenderPostBackScript (writer, formUniqueID);
- postBackScriptRendered = true;
- }
- if (handleViewState)
- writer.WriteLine ("<input type=\"hidden\" name=\"__VIEWSTATE\" value=\"{0}\" />", _savedViewState);
- scriptManager.WriteClientScriptBlocks (writer);
- }
- internal IStateFormatter GetFormatter ()
- {
- return new ObjectStateFormatter (this);
- }
- internal object GetSavedViewState ()
- {
- return _savedViewState;
- }
- internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
- {
- scriptManager.WriteArrayDeclares (writer);
- if (!postBackScriptRendered && requiresPostBackScript)
- RenderPostBackScript (writer, formUniqueID);
-
- #if NET_2_0
- scriptManager.SaveEventValidationState ();
- scriptManager.WriteExpandoAttributes (writer);
- #endif
- scriptManager.WriteHiddenFields (writer);
- scriptManager.WriteClientScriptIncludes (writer);
- scriptManager.WriteStartupScriptBlocks (writer);
- renderingForm = false;
- postBackScriptRendered = false;
- }
- private void ProcessPostData (NameValueCollection data, bool second)
- {
- if (data != null) {
- Hashtable used = new Hashtable ();
- foreach (string id in data.AllKeys){
- if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID)
- continue;
- string real_id = id;
- int dot = real_id.IndexOf ('.');
- if (dot >= 1)
- real_id = real_id.Substring (0, dot);
-
- if (real_id == null || used.ContainsKey (real_id))
- continue;
- used.Add (real_id, real_id);
- Control ctrl = FindControl (real_id);
- if (ctrl != null){
- IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
- IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
- if (pbdh == null) {
- if (pbeh != null)
- RegisterRequiresRaiseEvent (pbeh);
- continue;
- }
-
- if (pbdh.LoadPostData (real_id, data) == true) {
- if (requiresPostDataChanged == null)
- requiresPostDataChanged = new ArrayList ();
- requiresPostDataChanged.Add (pbdh);
- }
-
- if (_requiresPostBackCopy != null)
- _requiresPostBackCopy.Remove (real_id);
- } else if (!second) {
- if (secondPostData == null)
- secondPostData = new NameValueCollection ();
- secondPostData.Add (real_id, data [id]);
- }
- }
- }
- ArrayList list1 = null;
- if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
- string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
- foreach (string id in handlers) {
- IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
- if (pbdh != null) {
- _requiresPostBackCopy.Remove (id);
- if (pbdh.LoadPostData (id, data)) {
- if (requiresPostDataChanged == null)
- requiresPostDataChanged = new ArrayList ();
-
- requiresPostDataChanged.Add (pbdh);
- }
- } else if (!second) {
- if (list1 == null)
- list1 = new ArrayList ();
- list1.Add (id);
- }
- }
- }
- _requiresPostBackCopy = second ? null : list1;
- if (second)
- secondPostData = null;
- }
- [EditorBrowsable (EditorBrowsableState.Never)]
- #if NET_2_0 || TARGET_JVM
- public virtual void ProcessRequest (HttpContext context)
- #else
- public void ProcessRequest (HttpContext context)
- #endif
- {
- #if NET_2_0
- _lifeCycle = PageLifeCycle.Unknown;
- #endif
- _context = context;
- if (clientTarget != null)
- Request.ClientTarget = clientTarget;
- WireupAutomaticEvents ();
- //-- Control execution lifecycle in the docs
- // Save culture information because it can be modified in FrameworkInitialize()
- CultureInfo culture = Thread.CurrentThread.CurrentCulture;
- CultureInfo uiculture = Thread.CurrentThread.CurrentUICulture;
- FrameworkInitialize ();
- context.ErrorPage = _errorPage;
- try {
- InternalProcessRequest ();
- } catch (ThreadAbortException) {
- // Do nothing, just ignore it by now.
- } catch (Exception e) {
- context.AddError (e); // OnError might access LastError
- OnError (EventArgs.Empty);
- context.ClearError (e);
- // We want to remove that error, as we're rethrowing to stop
- // further processing.
- Trace.Warn ("Unhandled Exception", e.ToString (), e);
- throw;
- } finally {
- try {
- #if NET_2_0
- _lifeCycle = PageLifeCycle.Unload;
- #endif
- RenderTrace ();
- UnloadRecursive (true);
- #if NET_2_0
- _lifeCycle = PageLifeCycle.End;
- #endif
- } catch {}
- if (Thread.CurrentThread.CurrentCulture.Equals (culture) == false)
- Thread.CurrentThread.CurrentCulture = culture;
- if (Thread.CurrentThread.CurrentUICulture.Equals (uiculture) == false)
- Thread.CurrentThread.CurrentUICulture = uiculture;
- }
- }
-
- #if NET_2_0
- internal void ProcessCrossPagePostBack (HttpContext context)
- {
- isCrossPagePostBack = true;
- ProcessRequest (context);
- }
- #endif
- void InternalProcessRequest ()
- {
- _requestValueCollection = this.DeterminePostBackMode();
- #if NET_2_0
- _lifeCycle = PageLifeCycle.Start;
- // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
- if (_requestValueCollection != null) {
- if (!isCrossPagePostBack && _requestValueCollection [PreviousPageID] != null && _requestValueCollection [PreviousPageID] != Request.FilePath) {
- _doLoadPreviousPage = true;
- }
- else {
- isCallback = _requestValueCollection [CallbackArgumentID] != null;
- isPostBack = !isCallback;
- }
- }
-
- // if request was transfered from other page - track Prev. Page
- previousPage = _context.LastPage;
- _context.LastPage = this;
- InitializeCulture ();
- _lifeCycle = PageLifeCycle.PreInit;
- OnPreInit (EventArgs.Empty);
- InitializeTheme ();
- ApplyMasterPage ();
- _lifeCycle = PageLifeCycle.Init;
- #endif
- Trace.Write ("aspx.page", "Begin Init");
- InitRecursive (null);
- Trace.Write ("aspx.page", "End Init");
- #if NET_2_0
- _lifeCycle = PageLifeCycle.InitComplete;
- OnInitComplete (EventArgs.Empty);
- #endif
-
- renderingForm = false;
- #if NET_2_0
- if (IsPostBack || IsCallback) {
- _lifeCycle = PageLifeCycle.PreLoad;
- if (_requestValueCollection != null)
- scriptManager.RestoreEventValidationState (_requestValueCollection [scriptManager.EventStateFieldName]);
- #else
- if (IsPostBack) {
- #endif
- Trace.Write ("aspx.page", "Begin LoadViewState");
- LoadPageViewState ();
- Trace.Write ("aspx.page", "End LoadViewState");
- Trace.Write ("aspx.page", "Begin ProcessPostData");
- ProcessPostData (_requestValueCollection, false);
- Trace.Write ("aspx.page", "End ProcessPostData");
- }
- #if NET_2_0
- OnPreLoad (EventArgs.Empty);
- _lifeCycle = PageLifeCycle.Load;
- #endif
- LoadRecursive ();
- #if NET_2_0
- if (IsPostBack || IsCallback) {
- _lifeCycle = PageLifeCycle.ControlEvents;
- #else
- if (IsPostBack) {
- #endif
- Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
- ProcessPostData (secondPostData, true);
- Trace.Write ("aspx.page", "End ProcessPostData Second Try");
- Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
- RaiseChangedEvents ();
- Trace.Write ("aspx.page", "End Raise ChangedEvents");
- Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
- RaisePostBackEvents ();
- Trace.Write ("aspx.page", "End Raise PostBackEvent");
- }
-
- #if NET_2_0
- _lifeCycle = PageLifeCycle.LoadComplete;
- OnLoadComplete (EventArgs.Empty);
- if (IsCrossPagePostBack)
- return;
- if (IsCallback) {
- string result = ProcessCallbackData ();
- HtmlTextWriter callbackOutput = new HtmlTextWriter (_context.Response.Output);
- callbackOutput.Write (result);
- callbackOutput.Flush ();
- return;
- }
- _lifeCycle = PageLifeCycle.PreRender;
- #endif
-
- Trace.Write ("aspx.page", "Begin PreRender");
- PreRenderRecursiveInternal ();
- Trace.Write ("aspx.page", "End PreRender");
-
- #if NET_2_0
- _lifeCycle = PageLifeCycle.PreRenderComplete;
- OnPreRenderComplete (EventArgs.Empty);
- #endif
- Trace.Write ("aspx.page", "Begin SaveViewState");
- SavePageViewState ();
- Trace.Write ("aspx.page", "End SaveViewState");
-
- #if NET_2_0
- _lifeCycle = PageLifeCycle.SaveStateComplete;
- OnSaveStateComplete (EventArgs.Empty);
- _lifeCycle = PageLifeCycle.Render;
- #endif
-
- //--
- Trace.Write ("aspx.page", "Begin Render");
- HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
- RenderControl (output);
- Trace.Write ("aspx.page", "End Render");
- }
- private void RenderTrace ()
- {
- TraceManager traceManager = HttpRuntime.TraceManager;
- if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
- return;
-
- Trace.SaveData ();
- if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput)
- return;
- if (!traceManager.LocalOnly || Context.Request.IsLocal) {
- HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
- Trace.Render (output);
- }
- }
-
- #if NET_2_0
- bool CheckForValidationSupport (Control targetControl)
- {
- if (targetControl == null)
- return false;
- Type type = targetControl.GetType ();
- object[] attributes = type.GetCustomAttributes (true);
- foreach (object attr in attributes)
- if (attr is SupportsEventValidationAttribute)
- return true;
- return false;
- }
- #endif
-
- void RaisePostBackEvents ()
- {
- #if NET_2_0
- Control targetControl;
- #endif
- if (requiresRaiseEvent != null) {
- #if NET_2_0
- targetControl = requiresRaiseEvent as Control;
- if (targetControl != null && CheckForValidationSupport (targetControl))
- scriptManager.ValidateEvent (targetControl.UniqueID, null);
- #endif
- RaisePostBackEvent (requiresRaiseEvent, null);
- return;
- }
- NameValueCollection postdata = _requestValueCollection;
- if (postdata == null)
- return;
- string eventTarget = postdata [postEventSourceID];
- if (eventTarget == null || eventTarget.Length == 0) {
- Validate ();
- return;
- }
- #if NET_2_0
- targetControl = FindControl (eventTarget);
- IPostBackEventHandler target = targetControl as IPostBackEventHandler;
- #else
- IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
- #endif
-
- if (target == null)
- return;
- string eventArgument = postdata [postEventArgumentID];
- #if NET_2_0
- if (CheckForValidationSupport (targetControl))
- scriptManager.ValidateEvent (targetControl.UniqueID, eventArgument);
- #endif
- RaisePostBackEvent (target, eventArgument);
- }
- internal void RaiseChangedEvents ()
- {
- if (requiresPostDataChanged == null)
- return;
- foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
- ipdh.RaisePostDataChangedEvent ();
- requiresPostDataChanged = null;
- }
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
- {
- sourceControl.RaisePostBackEvent (eventArgument);
- }
-
- #if NET_2_0
- [Obsolete]
- #endif
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public void RegisterArrayDeclaration (string arrayName, string arrayValue)
- {
- scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
- }
- #if NET_2_0
- [Obsolete]
- #endif
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public virtual void RegisterClientScriptBlock (string key, string script)
- {
- scriptManager.RegisterClientScriptBlock (key, script);
- }
- #if NET_2_0
- [Obsolete]
- #endif
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
- {
- scriptManager.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
- }
- [MonoTODO("Not implemented, Used in HtmlForm")]
- internal void RegisterClientScriptFile (string a, string b, string c)
- {
- throw new NotImplementedException ();
- }
- #if NET_2_0
- [Obsolete]
- #endif
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public void RegisterOnSubmitStatement (string key, string script)
- {
- scriptManager.RegisterOnSubmitStatement (key, script);
- }
- internal string GetSubmitStatements ()
- {
- return scriptManager.WriteSubmitStatements ();
- }
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public void RegisterRequiresPostBack (Control control)
- {
- if (_requiresPostBack == null)
- _requiresPostBack = new ArrayList ();
- if (_requiresPostBack.Contains (control.UniqueID))
- return;
- _requiresPostBack.Add (control.UniqueID);
- }
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
- {
- requiresRaiseEvent = control;
- }
- #if NET_2_0
- [Obsolete]
- #endif
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public virtual void RegisterStartupScript (string key, string script)
- {
- scriptManager.RegisterStartupScript (key, script);
- }
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public void RegisterViewStateHandler ()
- {
- handleViewState = true;
- }
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- protected virtual void SavePageStateToPersistenceMedium (object viewState)
- {
- PageStatePersister persister = this.PageStatePersister;
- if (persister == null)
- return;
- Pair pair = viewState as Pair;
- if (pair != null) {
- persister.ViewState = pair.First;
- persister.ControlState = pair.Second;
- } else
- persister.ViewState = viewState;
- persister.Save ();
- }
- internal string RawViewState {
- get {
- NameValueCollection postdata = _requestValueCollection;
- string view_state;
- if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
- return null;
- if (view_state == "")
- return null;
- return view_state;
- }
- set { _savedViewState = value; }
- }
- #if NET_2_0
- protected virtual
- #else
- internal
- #endif
- PageStatePersister PageStatePersister {
- get {
- if (page_state_persister == null)
- page_state_persister = new HiddenFieldPageStatePersister (this);
- return page_state_persister;
- }
- }
-
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- protected virtual object LoadPageStateFromPersistenceMedium ()
- {
- PageStatePersister persister = this.PageStatePersister;
- if (persister == null)
- return null;
- persister.Load ();
- return new Pair (persister.ViewState, persister.ControlState);
- }
- internal void LoadPageViewState()
- {
- Pair sState = LoadPageStateFromPersistenceMedium () as Pair;
- if (sState != null) {
- if (allow_load) {
- #if NET_2_0
- LoadPageControlState (sState.Second);
- #endif
- Pair vsr = sState.First as Pair;
- if (vsr != null) {
- LoadViewStateRecursive (vsr.First);
- _requiresPostBackCopy = vsr.Second as ArrayList;
- }
- }
- }
- }
- internal void SavePageViewState ()
- {
- if (!handleViewState)
- return;
- #if NET_2_0
- object controlState = SavePageControlState ();
- #endif
- object viewState = SaveViewStateRecursive ();
- object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
- Pair vsr = null;
- if (viewState != null || reqPostback != null)
- vsr = new Pair (viewState, reqPostback);
- Pair pair = new Pair ();
- pair.First = vsr;
- #if NET_2_0
- pair.Second = controlState;
- #else
- pair.Second = null;
- #endif
- if (pair.First == null && pair.Second == null)
- SavePageStateToPersistenceMedium (null);
- else
- SavePageStateToPersistenceMedium (pair);
- }
- public virtual void Validate ()
- {
- is_validated = true;
- ValidateCollection (_validators);
- }
- #if NET_2_0
- internal bool AreValidatorsUplevel () {
- return AreValidatorsUplevel (String.Empty);
- }
- internal bool AreValidatorsUplevel (string valGroup)
- #else
- internal virtual bool AreValidatorsUplevel ()
- #endif
- {
- bool uplevel = false;
- foreach (IValidator v in Validators) {
- BaseValidator bv = v as BaseValidator;
- if (bv == null) continue;
- #if NET_2_0
- if (valGroup != bv.ValidationGroup)
- continue;
- #endif
- if (bv.GetRenderUplevel()) {
- uplevel = true;
- break;
- }
- }
- return uplevel;
- }
- bool ValidateCollection (ValidatorCollection validators)
- {
- #if NET_2_0
- if (!_eventValidation)
- return true;
- #endif
- if (validators == null || validators.Count == 0)
- return true;
- bool all_valid = true;
- foreach (IValidator v in validators){
- v.Validate ();
- if (v.IsValid == false)
- all_valid = false;
- }
- return all_valid;
- }
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public virtual void VerifyRenderingInServerForm (Control control)
- {
- if (_context == null)
- return;
- if (!renderingForm)
- throw new HttpException ("Control '" +
- control.ClientID +
- "' of type '" +
- control.GetType ().Name +
- "' must be placed inside a form tag with runat=server.");
- }
- protected override void FrameworkInitialize ()
- {
- base.FrameworkInitialize ();
- #if NET_2_0
- InitializeStyleSheet ();
- #endif
- }
- #endregion
-
- #if NET_2_0
- public
- #else
- internal
- #endif
- ClientScriptManager ClientScript {
- get { return scriptManager; }
- }
-
- #if NET_2_0
-
- static readonly object InitCompleteEvent = new object ();
- static readonly object LoadCompleteEvent = new object ();
- static readonly object PreInitEvent = new object ();
- static readonly object PreLoadEvent = new object ();
- static readonly object PreRenderCompleteEvent = new object ();
- static readonly object SaveStateCompleteEvent = new object ();
- int event_mask;
- const int initcomplete_mask = 1;
- const int loadcomplete_mask = 1 << 1;
- const int preinit_mask = 1 << 2;
- const int preload_mask = 1 << 3;
- const int prerendercomplete_mask = 1 << 4;
- const int savestatecomplete_mask = 1 << 5;
-
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public event EventHandler InitComplete {
- add {
- event_mask |= initcomplete_mask;
- Events.AddHandler (InitCompleteEvent, value);
- }
- remove { Events.RemoveHandler (InitCompleteEvent, value); }
- }
-
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public event EventHandler LoadComplete {
- add {
- event_mask |= loadcomplete_mask;
- Events.AddHandler (LoadCompleteEvent, value);
- }
- remove { Events.RemoveHandler (LoadCompleteEvent, value); }
- }
-
- public event EventHandler PreInit {
- add {
- event_mask |= preinit_mask;
- Events.AddHandler (PreInitEvent, value);
- }
- remove { Events.RemoveHandler (PreInitEvent, value); }
- }
-
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public event EventHandler PreLoad {
- add {
- event_mask |= preload_mask;
- Events.AddHandler (PreLoadEvent, value);
- }
- remove { Events.RemoveHandler (PreLoadEvent, value); }
- }
-
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public event EventHandler PreRenderComplete {
- add {
- event_mask |= prerendercomplete_mask;
- Events.AddHandler (PreRenderCompleteEvent, value);
- }
- remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
- }
-
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public event EventHandler SaveStateComplete {
- add {
- event_mask |= savestatecomplete_mask;
- Events.AddHandler (SaveStateCompleteEvent, value);
- }
- remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
- }
-
- protected virtual void OnInitComplete (EventArgs e)
- {
- if ((event_mask & initcomplete_mask) != 0) {
- EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
- if (eh != null) eh (this, e);
- }
- }
-
- protected virtual void OnLoadComplete (EventArgs e)
- {
- if ((event_mask & loadcomplete_mask) != 0) {
- EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
- if (eh != null) eh (this, e);
- }
- }
-
- protected virtual void OnPreInit (EventArgs e)
- {
- if ((event_mask & preinit_mask) != 0) {
- EventHandler eh = (EventHandler) (Events [PreInitEvent]);
- if (eh != null) eh (this, e);
- }
- }
-
- protected virtual void OnPreLoad (EventArgs e)
- {
- if ((event_mask & preload_mask) != 0) {
- EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
- if (eh != null) eh (this, e);
- }
- }
-
- protected virtual void OnPreRenderComplete (EventArgs e)
- {
- if ((event_mask & prerendercomplete_mask) != 0) {
- EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
- if (eh != null) eh (this, e);
- }
- if (Form == null)
- return;
- if (!Form.DetermineRenderUplevel ())
- return;
- /* figure out if we have some control we're going to focus */
- if (String.IsNullOrEmpty (_focusedControlID)) {
- _focusedControlID = Form.DefaultFocus;
- if (String.IsNullOrEmpty (_focusedControlID))
- _focusedControlID = Form.DefaultButton;
- }
- if (!String.IsNullOrEmpty (_focusedControlID) || Form.SubmitDisabledControls) {
- RequiresPostBackScript ();
- ClientScript.RegisterWebFormClientScript ();
- if (!String.IsNullOrEmpty (_focusedControlID)) {
- ClientScript.RegisterStartupScript ("HtmlForm-DefaultButton-StartupScript",
- String.Format ("<script type=\"text/javascript\">\n" +
- "<!--\n" +
- "WebForm_AutoFocus('{0}');// -->\n" +
- "</script>\n", _focusedControlID));
- }
- if (Form.SubmitDisabledControls) {
- ClientScript.RegisterOnSubmitStatement ("HtmlForm-SubmitDisabledControls-SubmitStatement",
- "javascript: return WebForm_OnSubmit();");
- ClientScript.RegisterStartupScript ("HtmlForm-SubmitDisabledControls-StartupScript",
- @"<script language=""JavaScript"">
- <!--
- function WebForm_OnSubmit() {
- WebForm_ReEnableControls();
- return true;
- } // -->
- </script>");
- }
- }
- }
-
- protected virtual void OnSaveStateComplete (EventArgs e)
- {
- if ((event_mask & savestatecomplete_mask) != 0) {
- EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
- if (eh != null) eh (this, e);
- }
- }
-
- public HtmlForm Form {
- get { return _form; }
- }
-
- internal void RegisterForm (HtmlForm form)
- {
- _form = form;
- }
-
- [BrowsableAttribute (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public Page PreviousPage {
- get {
- if (_doLoadPreviousPage) {
- _doLoadPreviousPage = false;
- LoadPreviousPageReference ();
- }
- return previousPage;
- }
- }
-
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public bool IsCallback {
- get { return isCallback; }
- }
-
- [BrowsableAttribute (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public bool IsCrossPagePostBack {
- get { return isCrossPagePostBack; }
- }
-
- string ProcessCallbackData ()
- {
- string callbackTarget = _requestValueCollection [CallbackSourceID];
- if (callbackTarget == null || callbackTarget.Length == 0)
- throw new HttpException ("Callback target not provided.");
- Control targetControl = FindControl (callbackTarget);
- ICallbackEventHandler target = targetControl as ICallbackEventHandler;
- if (target == null)
- throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
- string callbackArgument = _requestValueCollection [CallbackArgumentID];
- target.RaiseCallbackEvent (callbackArgument);
- return target.GetCallbackResult ();
- }
- [BrowsableAttribute (false)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public HtmlHead Header {
- get { return htmlHeader; }
- }
-
- internal void SetHeader (HtmlHead header)
- {
- htmlHeader = header;
- if (_title != null) {
- htmlHeader.Title = _title;
- _title = null;
- }
- }
- [MonoTODO("Not Implemented")]
- protected bool AsyncMode {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
- [MonoTODO ("Not Implemented")]
- public TimeSpan AsyncTimeout {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
- [MonoTODO ("Not Implemented")]
- public bool IsAsync {
- get {
- throw new NotImplementedException ();
- }
- }
-
- [MonoTODO ("Not Implemented")]
- protected internal virtual string UniqueFilePathSuffix {
- get {
- throw new NotImplementedException ();
- }
- }
- [MonoTODO ("Not Implemented")]
- public int MaxPageStateFieldLength {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
- [MonoTODO ("Not Implemented")]
- public ViewStateEncryptionMode ViewStateEncryptionMode {
- get {
- throw new NotImplementedException ();
- }
- set {
- throw new NotImplementedException ();
- }
- }
- [MonoTODO ("Not Implemented")]
- public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO ("Not Implemented")]
- public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, Object state)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO ("Not Implemented")]
- public void ExecuteRegisteredAsyncTasks ()
- {
- throw new NotImplementedException ();
- }
- [MonoTODO ("Not Implemented")]
- public static HtmlTextWriter CreateHtmlTextWriterFromType (TextWriter tw, Type writerType)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO ("Not Implemented")]
- public void RegisterRequiresViewStateEncryption ()
- {
- throw new NotImplementedException ();
- }
- void ApplyMasterPage ()
- {
- if (masterPageFile != null && masterPageFile.Length > 0) {
- ArrayList appliedMasterPageFiles = new ArrayList ();
- if (Master != null) {
- MasterPage.ApplyMasterPageRecursive (Master, appliedMasterPageFiles);
- Master.Page = this;
- Controls.Clear ();
- Controls.Add (Master);
- }
- }
- }
- [DefaultValueAttribute ("")]
- public virtual string MasterPageFile {
- get { return masterPageFile; }
- set {
- masterPageFile = value;
- masterPage = null;
- }
- }
-
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public MasterPage Master {
- get {
- if (Context == null || String.IsNullOrEmpty (masterPageFile))
- return null;
- if (masterPage == null)
- masterPage = MasterPage.CreateMasterPage (this, Context, masterPageFile, contentTemplates);
- return masterPage;
- }
- }
-
- public void SetFocus (string clientID)
- {
- if (String.IsNullOrEmpty (clientID))
- throw new ArgumentNullException ("control");
- if (_lifeCycle > PageLifeCycle.PreRender)
- throw new InvalidOperationException ("SetFocus can only be called before and during PreRender.");
- if(Form==null)
- throw new InvalidOperationException ("A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.");
- _focusedControlID = clientID;
- }
- public void SetFocus (Control control)
- {
- if (control == null)
- throw new ArgumentNullException ("control");
- SetFocus (control.ClientID);
- }
-
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public void RegisterRequiresControlState (Control control)
- {
- if (control == null)
- throw new ArgumentNullException ("control");
- if (RequiresControlState (control))
- return;
- if (requireStateControls == null)
- requireStateControls = new ArrayList ();
- int n = requireStateControls.Add (control);
- if (_savedControlState == null || n >= _savedControlState.Length)
- return;
- for (Control parent = control.Parent; parent != null; parent = parent.Parent)
- if (parent.IsChildControlStateCleared)
- return;
- object state = _savedControlState [n];
- if (state != null)
- control.LoadControlState (state);
- }
-
- public bool RequiresControlState (Control control)
- {
- if (requireStateControls == null) return false;
- return requireStateControls.Contains (control);
- }
-
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public void UnregisterRequiresControlState (Control control)
- {
- if (requireStateControls != null)
- requireStateControls.Remove (control);
- }
-
- public ValidatorCollection GetValidators (string validationGroup)
- {
- string valgr = validationGroup;
- if (valgr == null)
- valgr = String.Empty;
- if (_validatorsByGroup == null) _validatorsByGroup = new Hashtable ();
- ValidatorCollection col = _validatorsByGroup [valgr] as ValidatorCollection;
- if (col == null) {
- col = new ValidatorCollection ();
- _validatorsByGroup [valgr] = col;
- }
- return col;
- }
-
- public virtual void Validate (string validationGroup)
- {
- is_validated = true;
- if (validationGroup == null)
- ValidateCollection (_validatorsByGroup [String.Empty] as ValidatorCollection);
- else if (_validatorsByGroup != null) {
- ValidateCollection (_validatorsByGroup [validationGroup] as ValidatorCollection);
- }
- }
- object SavePageControlState ()
- {
- if (requireStateControls == null) return null;
- object[] state = new object [requireStateControls.Count];
-
- bool allNull = true;
- for (int n=0; n<state.Length; n++) {
- state [n] = ((Control) requireStateControls [n]).SaveControlState ();
- if (state [n] != null) allNull = false;
- }
- if (allNull) return null;
- else return state;
- }
-
- void LoadPageControlState (object data)
- {
- _savedControlState = (object []) data;
-
- if (requireStateControls == null) return;
- int max = Math.Min (requireStateControls.Count, _savedControlState != null ? _savedControlState.Length : requireStateControls.Count);
- for (int n=0; n < max; n++) {
- Control ctl = (Control) requireStateControls [n];
- ctl.LoadControlState (_savedControlState != null ? _savedControlState [n] : null);
- }
- }
- void LoadPreviousPageReference ()
- {
- if (_requestValueCollection != null) {
- string prevPage = _requestValueCollection [PreviousPageID];
- if (prevPage != null) {
- previousPage = (Page) PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
- previousPage.ProcessCrossPagePostBack (_context);
- }
- }
- }
- Hashtable contentTemplates;
- [EditorBrowsable (EditorBrowsableState.Never)]
- protected internal void AddContentTemplate (string templateName, ITemplate template)
- {
- if (contentTemplates == null)
- contentTemplates = new Hashtable ();
- contentTemplates [templateName] = template;
- }
- PageTheme _pageTheme;
- internal PageTheme PageTheme {
- get { return _pageTheme; }
- }
- PageTheme _styleSheetPageTheme;
- internal PageTheme StyleSheetPageTheme {
- get { return _styleSheetPageTheme; }
- }
- Stack dataItemCtx;
-
- internal void PushDataItemContext (object o) {
- if (dataItemCtx == null)
- dataItemCtx = new Stack ();
-
- dataItemCtx.Push (o);
- }
-
- internal void PopDataItemContext () {
- if (dataItemCtx == null)
- throw new InvalidOperationException ();
-
- dataItemCtx.Pop ();
- }
-
- public object GetDataItem() {
- if (dataItemCtx == null || dataItemCtx.Count == 0)
- throw new InvalidOperationException ("No data item");
-
- return dataItemCtx.Peek ();
- }
- protected internal override void OnInit (EventArgs e)
- {
- base.OnInit (e);
- if (Header == null)
- return;
- ArrayList themes = new ArrayList();
- if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
- themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
- if (PageTheme != null && PageTheme.GetStyleSheets () != null)
- themes.AddRange (PageTheme.GetStyleSheets ());
- foreach (string lss in themes) {
- HtmlLink hl = new HtmlLink ();
- hl.Href = ResolveUrl (lss);
- hl.Attributes["type"] = "text/css";
- hl.Attributes["rel"] = "stylesheet";
- Header.Controls.Add (hl);
- }
- }
- #endif
- #if NET_2_0
- [MonoTODO ("Not implemented. Only used by .net aspx parser")]
- protected object GetWrappedFileDependencies (string [] list)
- {
- return null;
- }
- [MonoTODO ("Does nothing. Used by .net aspx parser")]
- protected virtual void InitializeCulture ()
- {
- }
- [MonoTODO ("Does nothing. Used by .net aspx parser")]
- protected internal void AddWrappedFileDependencies (object virtualFileDependencies)
- {
- }
- #endif
- }
- }
|