Page.cs 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602
  1. //
  2. // System.Web.UI.Page.cs
  3. //
  4. // Authors:
  5. // Duncan Mak ([email protected])
  6. // Gonzalo Paniagua ([email protected])
  7. // Andreas Nahr ([email protected])
  8. // Marek Habersack ([email protected])
  9. //
  10. // (C) 2002,2003 Ximian, Inc. (http://www.ximian.com)
  11. // Copyright (C) 2003-2010 Novell, Inc (http://www.novell.com)
  12. //
  13. // Permission is hereby granted, free of charge, to any person obtaining
  14. // a copy of this software and associated documentation files (the
  15. // "Software"), to deal in the Software without restriction, including
  16. // without limitation the rights to use, copy, modify, merge, publish,
  17. // distribute, sublicense, and/or sell copies of the Software, and to
  18. // permit persons to whom the Software is furnished to do so, subject to
  19. // the following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be
  22. // included in all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  28. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  29. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  30. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  31. //
  32. using System;
  33. using System.Collections;
  34. using System.Collections.Generic;
  35. using System.Collections.Specialized;
  36. using System.ComponentModel;
  37. using System.ComponentModel.Design;
  38. using System.ComponentModel.Design.Serialization;
  39. using System.Globalization;
  40. using System.IO;
  41. using System.Security.Cryptography;
  42. using System.Security.Permissions;
  43. using System.Security.Principal;
  44. using System.Text;
  45. using System.Threading;
  46. using System.Web;
  47. using System.Web.Caching;
  48. using System.Web.Compilation;
  49. using System.Web.Configuration;
  50. using System.Web.SessionState;
  51. using System.Web.Util;
  52. using System.Web.UI.Adapters;
  53. using System.Web.UI.HtmlControls;
  54. using System.Web.UI.WebControls;
  55. using System.Reflection;
  56. namespace System.Web.UI
  57. {
  58. // CAS
  59. [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  60. [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  61. [DefaultEvent ("Load"), DesignerCategory ("ASPXCodeBehind")]
  62. [ToolboxItem (false)]
  63. [Designer ("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VisualStudio_Web, typeof (IRootDesigner))]
  64. public partial class Page : TemplateControl, IHttpHandler
  65. {
  66. static string machineKeyConfigPath = "system.web/machineKey";
  67. bool _eventValidation = true;
  68. object [] _savedControlState;
  69. bool _doLoadPreviousPage;
  70. string _focusedControlID;
  71. bool _hasEnabledControlArray;
  72. bool _viewState;
  73. bool _viewStateMac = true;
  74. string _errorPage;
  75. bool is_validated;
  76. bool _smartNavigation;
  77. int _transactionMode;
  78. ValidatorCollection _validators;
  79. bool renderingForm;
  80. string _savedViewState;
  81. ArrayList _requiresPostBack;
  82. ArrayList _requiresPostBackCopy;
  83. ArrayList requiresPostDataChanged;
  84. IPostBackEventHandler requiresRaiseEvent;
  85. IPostBackEventHandler formPostedRequiresRaiseEvent;
  86. NameValueCollection secondPostData;
  87. bool requiresPostBackScript;
  88. bool postBackScriptRendered;
  89. bool requiresFormScriptDeclaration;
  90. bool formScriptDeclarationRendered;
  91. bool handleViewState;
  92. string viewStateUserKey;
  93. NameValueCollection _requestValueCollection;
  94. string clientTarget;
  95. ClientScriptManager scriptManager;
  96. bool allow_load; // true when the Form collection belongs to this page (GetTypeHashCode)
  97. PageStatePersister page_state_persister;
  98. CultureInfo _appCulture;
  99. CultureInfo _appUICulture;
  100. // The initial context
  101. HttpContext _context;
  102. // cached from the initial context
  103. HttpApplicationState _application;
  104. HttpResponse _response;
  105. HttpRequest _request;
  106. Cache _cache;
  107. HttpSessionState _session;
  108. [EditorBrowsable (EditorBrowsableState.Never)]
  109. public const string postEventArgumentID = "__EVENTARGUMENT";
  110. [EditorBrowsable (EditorBrowsableState.Never)]
  111. public const string postEventSourceID = "__EVENTTARGET";
  112. const string ScrollPositionXID = "__SCROLLPOSITIONX";
  113. const string ScrollPositionYID = "__SCROLLPOSITIONY";
  114. const string EnabledControlArrayID = "__enabledControlArray";
  115. internal const string LastFocusID = "__LASTFOCUS";
  116. internal const string CallbackArgumentID = "__CALLBACKARGUMENT";
  117. internal const string CallbackSourceID = "__CALLBACKTARGET";
  118. internal const string PreviousPageID = "__PREVIOUSPAGE";
  119. int maxPageStateFieldLength = -1;
  120. string uniqueFilePathSuffix;
  121. HtmlHead htmlHeader;
  122. MasterPage masterPage;
  123. string masterPageFile;
  124. Page previousPage;
  125. bool isCrossPagePostBack;
  126. bool isPostBack;
  127. bool isCallback;
  128. List <Control> requireStateControls;
  129. HtmlForm _form;
  130. string _title;
  131. string _theme;
  132. string _styleSheetTheme;
  133. Hashtable items;
  134. bool _maintainScrollPositionOnPostBack;
  135. bool asyncMode = false;
  136. TimeSpan asyncTimeout;
  137. const double DefaultAsyncTimeout = 45.0;
  138. List<PageAsyncTask> parallelTasks;
  139. List<PageAsyncTask> serialTasks;
  140. ViewStateEncryptionMode viewStateEncryptionMode;
  141. bool controlRegisteredForViewStateEncryption = false;
  142. #region Constructors
  143. public Page ()
  144. {
  145. scriptManager = new ClientScriptManager (this);
  146. Page = this;
  147. ID = "__Page";
  148. PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
  149. if (ps != null) {
  150. asyncTimeout = ps.AsyncTimeout;
  151. viewStateEncryptionMode = ps.ViewStateEncryptionMode;
  152. _viewState = ps.EnableViewState;
  153. } else {
  154. asyncTimeout = TimeSpan.FromSeconds (DefaultAsyncTimeout);
  155. viewStateEncryptionMode = ViewStateEncryptionMode.Auto;
  156. _viewState = true;
  157. }
  158. }
  159. #endregion
  160. #region Properties
  161. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  162. [Browsable (false)]
  163. public HttpApplicationState Application {
  164. get { return _application; }
  165. }
  166. [EditorBrowsable (EditorBrowsableState.Never)]
  167. protected bool AspCompatMode {
  168. get { return false; }
  169. set { throw new NotImplementedException (); }
  170. }
  171. [EditorBrowsable (EditorBrowsableState.Never)]
  172. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  173. [BrowsableAttribute (false)]
  174. public bool Buffer {
  175. get { return Response.BufferOutput; }
  176. set { Response.BufferOutput = value; }
  177. }
  178. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  179. [Browsable (false)]
  180. public Cache Cache {
  181. get {
  182. if (_cache == null)
  183. throw new HttpException ("Cache is not available.");
  184. return _cache;
  185. }
  186. }
  187. [EditorBrowsableAttribute (EditorBrowsableState.Advanced)]
  188. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  189. [Browsable (false), DefaultValue ("")]
  190. [WebSysDescription ("Value do override the automatic browser detection and force the page to use the specified browser.")]
  191. public string ClientTarget {
  192. get { return (clientTarget == null) ? "" : clientTarget; }
  193. set {
  194. clientTarget = value;
  195. if (value == "")
  196. clientTarget = null;
  197. }
  198. }
  199. [EditorBrowsable (EditorBrowsableState.Never)]
  200. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  201. [BrowsableAttribute (false)]
  202. public int CodePage {
  203. get { return Response.ContentEncoding.CodePage; }
  204. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  205. }
  206. [EditorBrowsable (EditorBrowsableState.Never)]
  207. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  208. [BrowsableAttribute (false)]
  209. public string ContentType {
  210. get { return Response.ContentType; }
  211. set { Response.ContentType = value; }
  212. }
  213. protected internal override HttpContext Context {
  214. get {
  215. if (_context == null)
  216. return HttpContext.Current;
  217. return _context;
  218. }
  219. }
  220. [EditorBrowsable (EditorBrowsableState.Advanced)]
  221. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  222. [BrowsableAttribute (false)]
  223. public string Culture {
  224. get { return Thread.CurrentThread.CurrentCulture.Name; }
  225. set { Thread.CurrentThread.CurrentCulture = GetPageCulture (value, Thread.CurrentThread.CurrentCulture); }
  226. }
  227. public virtual bool EnableEventValidation {
  228. get { return _eventValidation; }
  229. set {
  230. if (IsInited)
  231. throw new InvalidOperationException ("The 'EnableEventValidation' property can be set only in the Page_init, the Page directive or in the <pages> configuration section.");
  232. _eventValidation = value;
  233. }
  234. }
  235. [Browsable (false)]
  236. public override bool EnableViewState {
  237. get { return _viewState; }
  238. set { _viewState = value; }
  239. }
  240. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  241. [BrowsableAttribute (false)]
  242. [EditorBrowsable (EditorBrowsableState.Never)]
  243. public bool EnableViewStateMac {
  244. get { return _viewStateMac; }
  245. set { _viewStateMac = value; }
  246. }
  247. internal bool EnableViewStateMacInternal {
  248. get { return _viewStateMac; }
  249. set { _viewStateMac = value; }
  250. }
  251. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  252. [Browsable (false), DefaultValue ("")]
  253. [WebSysDescription ("The URL of a page used for error redirection.")]
  254. public string ErrorPage {
  255. get { return _errorPage; }
  256. set {
  257. HttpContext ctx = Context;
  258. _errorPage = value;
  259. if (ctx != null)
  260. ctx.ErrorPage = value;
  261. }
  262. }
  263. [Obsolete]
  264. [EditorBrowsable (EditorBrowsableState.Never)]
  265. protected ArrayList FileDependencies {
  266. set {
  267. if (Response != null)
  268. Response.AddFileDependencies (value);
  269. }
  270. }
  271. [Browsable (false)]
  272. [EditorBrowsable (EditorBrowsableState.Never)]
  273. public override string ID {
  274. get { return base.ID; }
  275. set { base.ID = value; }
  276. }
  277. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  278. [Browsable (false)]
  279. public bool IsPostBack {
  280. get { return isPostBack; }
  281. }
  282. [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
  283. public bool IsReusable {
  284. get { return false; }
  285. }
  286. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  287. [Browsable (false)]
  288. public bool IsValid {
  289. get {
  290. if (!is_validated)
  291. throw new HttpException (Locale.GetText ("Page.IsValid cannot be called before validation has taken place. It should be queried in the event handler for a control that has CausesValidation=True and initiated the postback, or after a call to Page.Validate."));
  292. foreach (IValidator val in Validators)
  293. if (!val.IsValid)
  294. return false;
  295. return true;
  296. }
  297. }
  298. public IDictionary Items {
  299. get {
  300. if (items == null)
  301. items = new Hashtable ();
  302. return items;
  303. }
  304. }
  305. [EditorBrowsable (EditorBrowsableState.Never)]
  306. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  307. [BrowsableAttribute (false)]
  308. public int LCID {
  309. get { return Thread.CurrentThread.CurrentCulture.LCID; }
  310. set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
  311. }
  312. [Browsable (false)]
  313. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  314. public bool MaintainScrollPositionOnPostBack {
  315. get { return _maintainScrollPositionOnPostBack; }
  316. set { _maintainScrollPositionOnPostBack = value; }
  317. }
  318. public PageAdapter PageAdapter {
  319. get {
  320. return Adapter as PageAdapter;
  321. }
  322. }
  323. string _validationStartupScript;
  324. string _validationOnSubmitStatement;
  325. string _validationInitializeScript;
  326. string _webFormScriptReference;
  327. internal string WebFormScriptReference {
  328. get {
  329. if (_webFormScriptReference == null)
  330. _webFormScriptReference = IsMultiForm ? theForm : "window";
  331. return _webFormScriptReference;
  332. }
  333. }
  334. internal string ValidationStartupScript {
  335. get {
  336. if (_validationStartupScript == null) {
  337. _validationStartupScript =
  338. @"
  339. " + WebFormScriptReference + @".Page_ValidationActive = false;
  340. " + WebFormScriptReference + @".ValidatorOnLoad();
  341. " + WebFormScriptReference + @".ValidatorOnSubmit = function () {
  342. if (this.Page_ValidationActive) {
  343. return this.ValidatorCommonOnSubmit();
  344. }
  345. return true;
  346. };
  347. ";
  348. }
  349. return _validationStartupScript;
  350. }
  351. }
  352. internal string ValidationOnSubmitStatement {
  353. get {
  354. if (_validationOnSubmitStatement == null)
  355. _validationOnSubmitStatement = "if (!" + WebFormScriptReference + ".ValidatorOnSubmit()) return false;";
  356. return _validationOnSubmitStatement;
  357. }
  358. }
  359. internal string ValidationInitializeScript {
  360. get {
  361. if (_validationInitializeScript == null)
  362. _validationInitializeScript = "WebFormValidation_Initialize(" + WebFormScriptReference + ");";
  363. return _validationInitializeScript;
  364. }
  365. }
  366. internal IScriptManager ScriptManager {
  367. get { return (IScriptManager) Items [typeof (IScriptManager)]; }
  368. }
  369. #if !TARGET_J2EE
  370. internal string theForm {
  371. get {
  372. return "theForm";
  373. }
  374. }
  375. internal bool IsMultiForm {
  376. get { return false; }
  377. }
  378. #endif
  379. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  380. [Browsable (false)]
  381. public HttpRequest Request {
  382. get {
  383. if (_request == null)
  384. throw new HttpException("Request is not available in this context.");
  385. return _request;
  386. }
  387. }
  388. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  389. [Browsable (false)]
  390. public HttpResponse Response {
  391. get {
  392. if (_response == null)
  393. throw new HttpException ("Response is not available in this context.");
  394. return _response;
  395. }
  396. }
  397. [EditorBrowsable (EditorBrowsableState.Never)]
  398. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  399. [BrowsableAttribute (false)]
  400. public string ResponseEncoding {
  401. get { return Response.ContentEncoding.WebName; }
  402. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  403. }
  404. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  405. [Browsable (false)]
  406. public HttpServerUtility Server {
  407. get { return Context.Server; }
  408. }
  409. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  410. [Browsable (false)]
  411. public virtual HttpSessionState Session {
  412. get {
  413. if (_session != null)
  414. return _session;
  415. try {
  416. _session = Context.Session;
  417. } catch {
  418. // ignore, should not throw
  419. }
  420. if (_session == null)
  421. throw new HttpException ("Session state can only be used " +
  422. "when enableSessionState is set to true, either " +
  423. "in a configuration file or in the Page directive.");
  424. return _session;
  425. }
  426. }
  427. [FilterableAttribute (false)]
  428. [Obsolete]
  429. [Browsable (false)]
  430. public bool SmartNavigation {
  431. get { return _smartNavigation; }
  432. set { _smartNavigation = value; }
  433. }
  434. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  435. [Filterable (false)]
  436. [Browsable (false)]
  437. public virtual string StyleSheetTheme {
  438. get { return _styleSheetTheme; }
  439. set { _styleSheetTheme = value; }
  440. }
  441. [Browsable (false)]
  442. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  443. public virtual string Theme {
  444. get { return _theme; }
  445. set { _theme = value; }
  446. }
  447. void InitializeStyleSheet ()
  448. {
  449. if (_styleSheetTheme == null) {
  450. PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
  451. if (ps != null)
  452. _styleSheetTheme = ps.StyleSheetTheme;
  453. }
  454. #if TARGET_JVM
  455. if (_styleSheetTheme != null && _styleSheetTheme != "")
  456. _styleSheetPageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_styleSheetTheme, Context);
  457. #else
  458. if (!String.IsNullOrEmpty (_styleSheetTheme)) {
  459. string virtualPath = "~/App_Themes/" + _styleSheetTheme;
  460. _styleSheetPageTheme = BuildManager.CreateInstanceFromVirtualPath (virtualPath, typeof (PageTheme)) as PageTheme;
  461. }
  462. #endif
  463. }
  464. void InitializeTheme ()
  465. {
  466. if (_theme == null) {
  467. PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
  468. if (ps != null)
  469. _theme = ps.Theme;
  470. }
  471. #if TARGET_JVM
  472. if (_theme != null && _theme != "") {
  473. _pageTheme = ThemeDirectoryCompiler.GetCompiledInstance (_theme, Context);
  474. _pageTheme.SetPage (this);
  475. }
  476. #else
  477. if (!String.IsNullOrEmpty (_theme)) {
  478. string virtualPath = "~/App_Themes/" + _theme;
  479. _pageTheme = BuildManager.CreateInstanceFromVirtualPath (virtualPath, typeof (PageTheme)) as PageTheme;
  480. if (_pageTheme != null)
  481. _pageTheme.SetPage (this);
  482. }
  483. #endif
  484. }
  485. [Localizable (true)]
  486. [Bindable (true)]
  487. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  488. public string Title {
  489. get {
  490. if (_title == null) {
  491. if (htmlHeader != null && htmlHeader.Title != null)
  492. return htmlHeader.Title;
  493. return String.Empty;
  494. }
  495. return _title;
  496. }
  497. set {
  498. if (htmlHeader != null)
  499. htmlHeader.Title = value;
  500. else
  501. _title = value;
  502. }
  503. }
  504. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  505. [Browsable (false)]
  506. public TraceContext Trace {
  507. get { return Context.Trace; }
  508. }
  509. [EditorBrowsable (EditorBrowsableState.Never)]
  510. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  511. [BrowsableAttribute (false)]
  512. public bool TraceEnabled {
  513. get { return Trace.IsEnabled; }
  514. set { Trace.IsEnabled = value; }
  515. }
  516. [EditorBrowsable (EditorBrowsableState.Never)]
  517. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  518. [BrowsableAttribute (false)]
  519. public TraceMode TraceModeValue {
  520. get { return Trace.TraceMode; }
  521. set { Trace.TraceMode = value; }
  522. }
  523. [EditorBrowsable (EditorBrowsableState.Never)]
  524. protected int TransactionMode {
  525. get { return _transactionMode; }
  526. set { _transactionMode = value; }
  527. }
  528. [EditorBrowsable (EditorBrowsableState.Advanced)]
  529. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  530. [BrowsableAttribute (false)]
  531. public string UICulture {
  532. get { return Thread.CurrentThread.CurrentUICulture.Name; }
  533. set { Thread.CurrentThread.CurrentUICulture = GetPageCulture (value, Thread.CurrentThread.CurrentUICulture); }
  534. }
  535. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  536. [Browsable (false)]
  537. public IPrincipal User {
  538. get { return Context.User; }
  539. }
  540. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  541. [Browsable (false)]
  542. public ValidatorCollection Validators {
  543. get {
  544. if (_validators == null)
  545. _validators = new ValidatorCollection ();
  546. return _validators;
  547. }
  548. }
  549. [MonoTODO ("Use this when encrypting/decrypting ViewState")]
  550. [Browsable (false)]
  551. public string ViewStateUserKey {
  552. get { return viewStateUserKey; }
  553. set { viewStateUserKey = value; }
  554. }
  555. [Browsable (false)]
  556. public override bool Visible {
  557. get { return base.Visible; }
  558. set { base.Visible = value; }
  559. }
  560. #endregion
  561. #region Methods
  562. CultureInfo GetPageCulture (string culture, CultureInfo deflt)
  563. {
  564. if (culture == null)
  565. return deflt;
  566. CultureInfo ret = null;
  567. if (culture.StartsWith ("auto", StringComparison.InvariantCultureIgnoreCase)) {
  568. #if TARGET_J2EE
  569. if (!Context.IsServletRequest)
  570. return deflt;
  571. #endif
  572. string[] languages = Request.UserLanguages;
  573. try {
  574. if (languages != null && languages.Length > 0)
  575. ret = CultureInfo.CreateSpecificCulture (languages[0]);
  576. } catch {
  577. }
  578. if (ret == null)
  579. ret = deflt;
  580. } else
  581. ret = CultureInfo.CreateSpecificCulture (culture);
  582. return ret;
  583. }
  584. [EditorBrowsable (EditorBrowsableState.Never)]
  585. protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
  586. AsyncCallback cb,
  587. object extraData)
  588. {
  589. throw new NotImplementedException ();
  590. }
  591. [EditorBrowsable (EditorBrowsableState.Never)]
  592. protected void AspCompatEndProcessRequest (IAsyncResult result)
  593. {
  594. throw new NotImplementedException ();
  595. }
  596. [EditorBrowsable (EditorBrowsableState.Advanced)]
  597. protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
  598. {
  599. if (Request.BrowserMightHaveSpecialWriter)
  600. return Request.Browser.CreateHtmlTextWriter(tw);
  601. else
  602. return new HtmlTextWriter (tw);
  603. }
  604. [EditorBrowsable (EditorBrowsableState.Never)]
  605. public void DesignerInitialize ()
  606. {
  607. InitRecursive (null);
  608. }
  609. [EditorBrowsable (EditorBrowsableState.Advanced)]
  610. protected internal virtual NameValueCollection DeterminePostBackMode ()
  611. {
  612. // if request was transfered from other page such Transfer
  613. if (_context.IsProcessingInclude)
  614. return null;
  615. HttpRequest req = Request;
  616. if (req == null)
  617. return null;
  618. NameValueCollection coll = null;
  619. if (0 == String.Compare (Request.HttpMethod, "POST", true, Helpers.InvariantCulture)
  620. #if TARGET_J2EE
  621. || !_context.IsServletRequest
  622. #endif
  623. )
  624. coll = req.Form;
  625. else {
  626. string query = Request.QueryStringRaw;
  627. if (query == null || query.Length == 0)
  628. return null;
  629. coll = req.QueryString;
  630. }
  631. WebROCollection c = (WebROCollection) coll;
  632. allow_load = !c.GotID;
  633. if (allow_load)
  634. c.ID = GetTypeHashCode ();
  635. else
  636. allow_load = (c.ID == GetTypeHashCode ());
  637. if (coll != null && coll ["__VIEWSTATE"] == null && coll ["__EVENTTARGET"] == null)
  638. return null;
  639. #if TARGET_J2EE
  640. if (getFacesContext () != null && _context.Handler != _context.CurrentHandler) {
  641. // check if it is PreviousPage
  642. string prevViewId = coll [PreviousPageID];
  643. if (!String.IsNullOrEmpty (prevViewId)) {
  644. string appPath = VirtualPathUtility.RemoveTrailingSlash (Request.ApplicationPath);
  645. prevViewId = prevViewId.Substring (appPath.Length);
  646. isCrossPagePostBack = String.Compare (prevViewId, getFacesContext ().getExternalContext ().getRequestPathInfo (), StringComparison.OrdinalIgnoreCase) == 0;
  647. }
  648. }
  649. #endif
  650. return coll;
  651. }
  652. public override Control FindControl (string id) {
  653. if (id == ID)
  654. return this;
  655. else
  656. return base.FindControl (id);
  657. }
  658. Control FindControl (string id, bool decode) {
  659. #if TARGET_J2EE
  660. if (decode)
  661. id = DecodeNamespace (id);
  662. #endif
  663. return FindControl (id);
  664. }
  665. [Obsolete]
  666. [EditorBrowsable (EditorBrowsableState.Advanced)]
  667. public string GetPostBackClientEvent (Control control, string argument)
  668. {
  669. return scriptManager.GetPostBackEventReference (control, argument);
  670. }
  671. [Obsolete]
  672. [EditorBrowsable (EditorBrowsableState.Advanced)]
  673. public string GetPostBackClientHyperlink (Control control, string argument)
  674. {
  675. return scriptManager.GetPostBackClientHyperlink (control, argument);
  676. }
  677. [Obsolete]
  678. [EditorBrowsable (EditorBrowsableState.Advanced)]
  679. public string GetPostBackEventReference (Control control)
  680. {
  681. return scriptManager.GetPostBackEventReference (control, "");
  682. }
  683. [Obsolete]
  684. [EditorBrowsable (EditorBrowsableState.Advanced)]
  685. public string GetPostBackEventReference (Control control, string argument)
  686. {
  687. return scriptManager.GetPostBackEventReference (control, argument);
  688. }
  689. internal void RequiresFormScriptDeclaration ()
  690. {
  691. requiresFormScriptDeclaration = true;
  692. }
  693. internal void RequiresPostBackScript ()
  694. {
  695. if (requiresPostBackScript)
  696. return;
  697. ClientScript.RegisterHiddenField (postEventSourceID, String.Empty);
  698. ClientScript.RegisterHiddenField (postEventArgumentID, String.Empty);
  699. requiresPostBackScript = true;
  700. RequiresFormScriptDeclaration ();
  701. }
  702. [EditorBrowsable (EditorBrowsableState.Never)]
  703. public virtual int GetTypeHashCode ()
  704. {
  705. return 0;
  706. }
  707. [MonoTODO("The following properties of OutputCacheParameters are silently ignored: CacheProfile, SqlDependency")]
  708. protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings)
  709. {
  710. if (cacheSettings.Enabled) {
  711. InitOutputCache(cacheSettings.Duration,
  712. cacheSettings.VaryByContentEncoding,
  713. cacheSettings.VaryByHeader,
  714. cacheSettings.VaryByCustom,
  715. cacheSettings.Location,
  716. cacheSettings.VaryByParam);
  717. HttpResponse response = Response;
  718. HttpCachePolicy cache = response != null ? response.Cache : null;
  719. if (cache != null && cacheSettings.NoStore)
  720. cache.SetNoStore ();
  721. }
  722. }
  723. [MonoTODO ("varyByContentEncoding is not currently used")]
  724. protected virtual void InitOutputCache(int duration,
  725. string varyByContentEncoding,
  726. string varyByHeader,
  727. string varyByCustom,
  728. OutputCacheLocation location,
  729. string varyByParam)
  730. {
  731. HttpResponse response = Response;
  732. HttpCachePolicy cache = response.Cache;
  733. bool set_vary = false;
  734. HttpContext ctx = Context;
  735. DateTime timestamp = ctx != null ? ctx.Timestamp : DateTime.Now;
  736. switch (location) {
  737. case OutputCacheLocation.Any:
  738. cache.SetCacheability (HttpCacheability.Public);
  739. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  740. cache.SetLastModified (timestamp);
  741. set_vary = true;
  742. break;
  743. case OutputCacheLocation.Client:
  744. cache.SetCacheability (HttpCacheability.Private);
  745. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  746. cache.SetLastModified (timestamp);
  747. break;
  748. case OutputCacheLocation.Downstream:
  749. cache.SetCacheability (HttpCacheability.Public);
  750. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  751. cache.SetLastModified (timestamp);
  752. break;
  753. case OutputCacheLocation.Server:
  754. cache.SetCacheability (HttpCacheability.Server);
  755. set_vary = true;
  756. break;
  757. case OutputCacheLocation.None:
  758. break;
  759. }
  760. if (set_vary) {
  761. if (varyByCustom != null)
  762. cache.SetVaryByCustom (varyByCustom);
  763. if (varyByParam != null && varyByParam.Length > 0) {
  764. string[] prms = varyByParam.Split (';');
  765. foreach (string p in prms)
  766. cache.VaryByParams [p.Trim ()] = true;
  767. cache.VaryByParams.IgnoreParams = false;
  768. } else {
  769. cache.VaryByParams.IgnoreParams = true;
  770. }
  771. if (varyByHeader != null && varyByHeader.Length > 0) {
  772. string[] hdrs = varyByHeader.Split (';');
  773. foreach (string h in hdrs)
  774. cache.VaryByHeaders [h.Trim ()] = true;
  775. }
  776. if (PageAdapter != null) {
  777. if (PageAdapter.CacheVaryByParams != null) {
  778. foreach (string p in PageAdapter.CacheVaryByParams)
  779. cache.VaryByParams [p] = true;
  780. }
  781. if (PageAdapter.CacheVaryByHeaders != null) {
  782. foreach (string h in PageAdapter.CacheVaryByHeaders)
  783. cache.VaryByHeaders [h] = true;
  784. }
  785. }
  786. }
  787. response.IsCached = true;
  788. cache.Duration = duration;
  789. cache.SetExpires (timestamp.AddSeconds (duration));
  790. }
  791. [EditorBrowsable (EditorBrowsableState.Never)]
  792. protected virtual void InitOutputCache (int duration,
  793. string varyByHeader,
  794. string varyByCustom,
  795. OutputCacheLocation location,
  796. string varyByParam)
  797. {
  798. InitOutputCache (duration, null, varyByHeader, varyByCustom, location, varyByParam);
  799. }
  800. [Obsolete]
  801. public bool IsClientScriptBlockRegistered (string key)
  802. {
  803. return scriptManager.IsClientScriptBlockRegistered (key);
  804. }
  805. [Obsolete]
  806. public bool IsStartupScriptRegistered (string key)
  807. {
  808. return scriptManager.IsStartupScriptRegistered (key);
  809. }
  810. public string MapPath (string virtualPath)
  811. {
  812. return Request.MapPath (virtualPath);
  813. }
  814. protected internal override void Render (HtmlTextWriter writer)
  815. {
  816. if (MaintainScrollPositionOnPostBack) {
  817. ClientScript.RegisterWebFormClientScript ();
  818. ClientScript.RegisterHiddenField (ScrollPositionXID, Request [ScrollPositionXID]);
  819. ClientScript.RegisterHiddenField (ScrollPositionYID, Request [ScrollPositionYID]);
  820. StringBuilder script = new StringBuilder ();
  821. script.AppendLine ("<script type=\"text/javascript\">");
  822. script.AppendLine (ClientScriptManager.SCRIPT_BLOCK_START);
  823. script.AppendLine (theForm + ".oldSubmit = " + theForm + ".submit;");
  824. script.AppendLine (theForm + ".submit = function () { " + WebFormScriptReference + ".WebForm_SaveScrollPositionSubmit(); }");
  825. script.AppendLine (theForm + ".oldOnSubmit = " + theForm + ".onsubmit;");
  826. script.AppendLine (theForm + ".onsubmit = function () { " + WebFormScriptReference + ".WebForm_SaveScrollPositionOnSubmit(); }");
  827. if (IsPostBack) {
  828. script.AppendLine (theForm + ".oldOnLoad = window.onload;");
  829. script.AppendLine ("window.onload = function () { " + WebFormScriptReference + ".WebForm_RestoreScrollPosition (); };");
  830. }
  831. script.AppendLine (ClientScriptManager.SCRIPT_BLOCK_END);
  832. script.AppendLine ("</script>");
  833. ClientScript.RegisterStartupScript (typeof (Page), "MaintainScrollPositionOnPostBackStartup", script.ToString());
  834. }
  835. #if TARGET_J2EE
  836. if (bool.Parse (WebConfigurationManager.AppSettings [RenderBodyContentOnlyKey] ?? "false")) {
  837. for (Control c = this.Form; c != null; c = c.Parent) {
  838. HtmlGenericControl ch = (c as HtmlGenericControl);
  839. if (ch != null && ch.TagName == "body") {
  840. ch.RenderChildren (writer);
  841. return;
  842. }
  843. }
  844. }
  845. #endif
  846. base.Render (writer);
  847. }
  848. void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
  849. {
  850. writer.WriteLine ();
  851. ClientScriptManager.WriteBeginScriptBlock (writer);
  852. RenderClientScriptFormDeclaration (writer, formUniqueID);
  853. writer.WriteLine (WebFormScriptReference + "._form = " + theForm + ";");
  854. writer.WriteLine (WebFormScriptReference + ".__doPostBack = function (eventTarget, eventArgument) {");
  855. writer.WriteLine ("\tif(" + theForm + ".onsubmit && " + theForm + ".onsubmit() == false) return;");
  856. writer.WriteLine ("\t" + theForm + "." + postEventSourceID + ".value = eventTarget;");
  857. writer.WriteLine ("\t" + theForm + "." + postEventArgumentID + ".value = eventArgument;");
  858. writer.WriteLine ("\t" + theForm + ".submit();");
  859. writer.WriteLine ("}");
  860. ClientScriptManager.WriteEndScriptBlock (writer);
  861. }
  862. void RenderClientScriptFormDeclaration (HtmlTextWriter writer, string formUniqueID)
  863. {
  864. if (formScriptDeclarationRendered)
  865. return;
  866. if (PageAdapter != null) {
  867. writer.WriteLine ("\tvar {0} = {1};\n", theForm, PageAdapter.GetPostBackFormReference(formUniqueID));
  868. } else {
  869. writer.WriteLine ("\tvar {0};\n\tif (document.getElementById) {{ {0} = document.getElementById ('{1}'); }}", theForm, formUniqueID);
  870. writer.WriteLine ("\telse {{ {0} = document.{1}; }}", theForm, formUniqueID);
  871. }
  872. #if TARGET_J2EE
  873. // TODO implement callback on portlet
  874. string serverUrl = Request.RawUrl;
  875. writer.WriteLine ("\t{0}.serverURL = {1};", theForm, ClientScriptManager.GetScriptLiteral (serverUrl));
  876. writer.WriteLine ("\twindow.TARGET_J2EE = true;");
  877. writer.WriteLine ("\twindow.IsMultiForm = {0};", IsMultiForm ? "true" : "false");
  878. #endif
  879. formScriptDeclarationRendered = true;
  880. }
  881. internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
  882. {
  883. if (renderingForm)
  884. throw new HttpException ("Only 1 HtmlForm is allowed per page.");
  885. renderingForm = true;
  886. writer.WriteLine ();
  887. if (requiresFormScriptDeclaration || (scriptManager != null && scriptManager.ScriptsPresent) || PageAdapter != null) {
  888. ClientScriptManager.WriteBeginScriptBlock (writer);
  889. RenderClientScriptFormDeclaration (writer, formUniqueID);
  890. ClientScriptManager.WriteEndScriptBlock (writer);
  891. }
  892. if (handleViewState)
  893. #if TARGET_J2EE
  894. if (getFacesContext () != null) {
  895. javax.faces.application.ViewHandler viewHandler = getFacesContext ().getApplication ().getViewHandler ();
  896. javax.faces.context.ResponseWriter oldFacesWriter = SetupResponseWriter (writer);
  897. try {
  898. viewHandler.writeState (getFacesContext ());
  899. }
  900. finally {
  901. getFacesContext ().setResponseWriter (oldFacesWriter);
  902. }
  903. } else
  904. #endif
  905. scriptManager.RegisterHiddenField ("__VIEWSTATE", _savedViewState);
  906. scriptManager.WriteHiddenFields (writer);
  907. if (requiresPostBackScript) {
  908. RenderPostBackScript (writer, formUniqueID);
  909. postBackScriptRendered = true;
  910. }
  911. scriptManager.WriteWebFormClientScript (writer);
  912. scriptManager.WriteClientScriptBlocks (writer);
  913. }
  914. internal IStateFormatter GetFormatter ()
  915. {
  916. return new ObjectStateFormatter (this);
  917. }
  918. internal string GetSavedViewState ()
  919. {
  920. return _savedViewState;
  921. }
  922. internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
  923. {
  924. scriptManager.SaveEventValidationState ();
  925. scriptManager.WriteExpandoAttributes (writer);
  926. scriptManager.WriteHiddenFields (writer);
  927. if (!postBackScriptRendered && requiresPostBackScript)
  928. RenderPostBackScript (writer, formUniqueID);
  929. scriptManager.WriteWebFormClientScript (writer);
  930. scriptManager.WriteArrayDeclares (writer);
  931. scriptManager.WriteStartupScriptBlocks (writer);
  932. renderingForm = false;
  933. postBackScriptRendered = false;
  934. }
  935. void ProcessPostData (NameValueCollection data, bool second)
  936. {
  937. NameValueCollection requestValues = _requestValueCollection == null ?
  938. new NameValueCollection () :
  939. _requestValueCollection;
  940. if (data != null && data.Count > 0) {
  941. Hashtable used = new Hashtable ();
  942. foreach (string id in data.AllKeys) {
  943. if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID || id == ClientScriptManager.EventStateFieldName)
  944. continue;
  945. if (used.ContainsKey (id))
  946. continue;
  947. used.Add (id, id);
  948. Control ctrl = FindControl (id, true);
  949. if (ctrl != null) {
  950. IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
  951. IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
  952. if (pbdh == null) {
  953. if (pbeh != null)
  954. formPostedRequiresRaiseEvent = pbeh;
  955. continue;
  956. }
  957. if (pbdh.LoadPostData (id, requestValues) == true) {
  958. if (requiresPostDataChanged == null)
  959. requiresPostDataChanged = new ArrayList ();
  960. requiresPostDataChanged.Add (pbdh);
  961. }
  962. if (_requiresPostBackCopy != null)
  963. _requiresPostBackCopy.Remove (id);
  964. } else if (!second) {
  965. if (secondPostData == null)
  966. secondPostData = new NameValueCollection ();
  967. secondPostData.Add (id, data [id]);
  968. }
  969. }
  970. }
  971. ArrayList list1 = null;
  972. if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
  973. string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
  974. foreach (string id in handlers) {
  975. IPostBackDataHandler pbdh = FindControl (id, true) as IPostBackDataHandler;
  976. if (pbdh != null) {
  977. _requiresPostBackCopy.Remove (id);
  978. if (pbdh.LoadPostData (id, requestValues)) {
  979. if (requiresPostDataChanged == null)
  980. requiresPostDataChanged = new ArrayList ();
  981. requiresPostDataChanged.Add (pbdh);
  982. }
  983. } else if (!second) {
  984. if (list1 == null)
  985. list1 = new ArrayList ();
  986. list1.Add (id);
  987. }
  988. }
  989. }
  990. _requiresPostBackCopy = second ? null : list1;
  991. if (second)
  992. secondPostData = null;
  993. }
  994. [EditorBrowsable (EditorBrowsableState.Never)]
  995. public virtual void ProcessRequest (HttpContext context)
  996. {
  997. SetContext (context);
  998. #if TARGET_J2EE
  999. bool wasException = false;
  1000. IHttpHandler jsfHandler = getFacesContext () != null ? EnterThread () : null;
  1001. #endif
  1002. if (clientTarget != null)
  1003. Request.ClientTarget = clientTarget;
  1004. WireupAutomaticEvents ();
  1005. //-- Control execution lifecycle in the docs
  1006. // Save culture information because it can be modified in FrameworkInitialize()
  1007. _appCulture = Thread.CurrentThread.CurrentCulture;
  1008. _appUICulture = Thread.CurrentThread.CurrentUICulture;
  1009. FrameworkInitialize ();
  1010. context.ErrorPage = _errorPage;
  1011. try {
  1012. InternalProcessRequest ();
  1013. #if TARGET_J2EE
  1014. } catch (Exception ex) {
  1015. wasException = true;
  1016. HandleException (ex);
  1017. #else
  1018. } catch (ThreadAbortException taex) {
  1019. if (FlagEnd.Value == taex.ExceptionState)
  1020. Thread.ResetAbort ();
  1021. else
  1022. throw;
  1023. } catch (Exception e) {
  1024. ProcessException (e);
  1025. #endif
  1026. } finally {
  1027. #if TARGET_J2EE
  1028. if (getFacesContext () != null)
  1029. ExitThread (jsfHandler);
  1030. else if (!wasException)
  1031. #endif
  1032. ProcessUnload ();
  1033. }
  1034. }
  1035. void ProcessException (Exception e) {
  1036. // We want to remove that error, as we're rethrowing to stop
  1037. // further processing.
  1038. Trace.Warn ("Unhandled Exception", e.ToString (), e);
  1039. _context.AddError (e); // OnError might access LastError
  1040. OnError (EventArgs.Empty);
  1041. if (_context.HasError (e)) {
  1042. _context.ClearError (e);
  1043. #if TARGET_JVM
  1044. vmw.common.TypeUtils.Throw (e);
  1045. #else
  1046. throw new HttpUnhandledException (null, e);
  1047. #endif
  1048. }
  1049. }
  1050. void ProcessUnload () {
  1051. try {
  1052. RenderTrace ();
  1053. UnloadRecursive (true);
  1054. } catch {}
  1055. #if TARGET_J2EE
  1056. if (getFacesContext () != null) {
  1057. if(IsCrossPagePostBack)
  1058. _context.Items [CrossPagePostBack] = this;
  1059. }
  1060. #endif
  1061. if (Thread.CurrentThread.CurrentCulture.Equals (_appCulture) == false)
  1062. Thread.CurrentThread.CurrentCulture = _appCulture;
  1063. if (Thread.CurrentThread.CurrentUICulture.Equals (_appUICulture) == false)
  1064. Thread.CurrentThread.CurrentUICulture = _appUICulture;
  1065. _appCulture = null;
  1066. _appUICulture = null;
  1067. }
  1068. delegate void ProcessRequestDelegate (HttpContext context);
  1069. sealed class DummyAsyncResult : IAsyncResult
  1070. {
  1071. readonly object state;
  1072. readonly WaitHandle asyncWaitHandle;
  1073. readonly bool completedSynchronously;
  1074. readonly bool isCompleted;
  1075. public DummyAsyncResult (bool isCompleted, bool completedSynchronously, object state)
  1076. {
  1077. this.isCompleted = isCompleted;
  1078. this.completedSynchronously = completedSynchronously;
  1079. this.state = state;
  1080. if (isCompleted) {
  1081. asyncWaitHandle = new ManualResetEvent (true);
  1082. }
  1083. else {
  1084. asyncWaitHandle = new ManualResetEvent (false);
  1085. }
  1086. }
  1087. #region IAsyncResult Members
  1088. public object AsyncState {
  1089. get { return state; }
  1090. }
  1091. public WaitHandle AsyncWaitHandle {
  1092. get { return asyncWaitHandle; }
  1093. }
  1094. public bool CompletedSynchronously {
  1095. get { return completedSynchronously; }
  1096. }
  1097. public bool IsCompleted {
  1098. get { return isCompleted; }
  1099. }
  1100. #endregion
  1101. }
  1102. protected IAsyncResult AsyncPageBeginProcessRequest (HttpContext context, AsyncCallback callback, object extraData)
  1103. {
  1104. ProcessRequest (context);
  1105. DummyAsyncResult asyncResult = new DummyAsyncResult (true, true, extraData);
  1106. if (callback != null) {
  1107. callback (asyncResult);
  1108. }
  1109. return asyncResult;
  1110. }
  1111. protected void AsyncPageEndProcessRequest (IAsyncResult result)
  1112. {
  1113. }
  1114. void InternalProcessRequest ()
  1115. {
  1116. if (PageAdapter != null)
  1117. _requestValueCollection = PageAdapter.DeterminePostBackMode();
  1118. else
  1119. _requestValueCollection = this.DeterminePostBackMode();
  1120. // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
  1121. if (_requestValueCollection != null) {
  1122. if (!isCrossPagePostBack && _requestValueCollection [PreviousPageID] != null && _requestValueCollection [PreviousPageID] != Request.FilePath) {
  1123. _doLoadPreviousPage = true;
  1124. } else {
  1125. isCallback = _requestValueCollection [CallbackArgumentID] != null;
  1126. // LAMESPEC: on Callback IsPostBack is set to false, but true.
  1127. //isPostBack = !isCallback;
  1128. isPostBack = true;
  1129. }
  1130. string lastFocus = _requestValueCollection [LastFocusID];
  1131. if (!String.IsNullOrEmpty (lastFocus))
  1132. _focusedControlID = UniqueID2ClientID (lastFocus);
  1133. }
  1134. if (!isCrossPagePostBack) {
  1135. if (_context.PreviousHandler is Page)
  1136. previousPage = (Page) _context.PreviousHandler;
  1137. }
  1138. Trace.Write ("aspx.page", "Begin PreInit");
  1139. OnPreInit (EventArgs.Empty);
  1140. Trace.Write ("aspx.page", "End PreInit");
  1141. InitializeTheme ();
  1142. ApplyMasterPage ();
  1143. Trace.Write ("aspx.page", "Begin Init");
  1144. InitRecursive (null);
  1145. Trace.Write ("aspx.page", "End Init");
  1146. Trace.Write ("aspx.page", "Begin InitComplete");
  1147. OnInitComplete (EventArgs.Empty);
  1148. Trace.Write ("aspx.page", "End InitComplete");
  1149. renderingForm = false;
  1150. #if TARGET_J2EE
  1151. if (getFacesContext () != null)
  1152. if (IsPostBack || IsCallback)
  1153. return;
  1154. #endif
  1155. RestorePageState ();
  1156. ProcessPostData ();
  1157. ProcessRaiseEvents ();
  1158. if (ProcessLoadComplete ())
  1159. return;
  1160. #if TARGET_J2EE
  1161. if (getFacesContext () != null) {
  1162. getFacesContext ().renderResponse ();
  1163. return;
  1164. }
  1165. #endif
  1166. RenderPage ();
  1167. }
  1168. void RestorePageState ()
  1169. {
  1170. if (IsPostBack || IsCallback) {
  1171. if (_requestValueCollection != null)
  1172. scriptManager.RestoreEventValidationState (
  1173. _requestValueCollection [ClientScriptManager.EventStateFieldName]);
  1174. Trace.Write ("aspx.page", "Begin LoadViewState");
  1175. LoadPageViewState ();
  1176. Trace.Write ("aspx.page", "End LoadViewState");
  1177. }
  1178. }
  1179. void ProcessPostData ()
  1180. {
  1181. if (IsPostBack || IsCallback) {
  1182. Trace.Write ("aspx.page", "Begin ProcessPostData");
  1183. ProcessPostData (_requestValueCollection, false);
  1184. Trace.Write ("aspx.page", "End ProcessPostData");
  1185. }
  1186. ProcessLoad ();
  1187. if (IsPostBack || IsCallback) {
  1188. Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
  1189. ProcessPostData (secondPostData, true);
  1190. Trace.Write ("aspx.page", "End ProcessPostData Second Try");
  1191. }
  1192. }
  1193. void ProcessLoad ()
  1194. {
  1195. Trace.Write ("aspx.page", "Begin PreLoad");
  1196. OnPreLoad (EventArgs.Empty);
  1197. Trace.Write ("aspx.page", "End PreLoad");
  1198. Trace.Write ("aspx.page", "Begin Load");
  1199. LoadRecursive ();
  1200. Trace.Write ("aspx.page", "End Load");
  1201. }
  1202. void ProcessRaiseEvents ()
  1203. {
  1204. if (IsPostBack || IsCallback) {
  1205. Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
  1206. RaiseChangedEvents ();
  1207. Trace.Write ("aspx.page", "End Raise ChangedEvents");
  1208. Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
  1209. RaisePostBackEvents ();
  1210. Trace.Write ("aspx.page", "End Raise PostBackEvent");
  1211. }
  1212. }
  1213. bool ProcessLoadComplete ()
  1214. {
  1215. Trace.Write ("aspx.page", "Begin LoadComplete");
  1216. OnLoadComplete (EventArgs.Empty);
  1217. Trace.Write ("aspx.page", "End LoadComplete");
  1218. if (IsCrossPagePostBack)
  1219. return true;
  1220. if (IsCallback) {
  1221. #if TARGET_J2EE
  1222. if (getFacesContext () != null) {
  1223. _callbackTarget = GetCallbackTarget ();
  1224. ProcessRaiseCallbackEvent (_callbackTarget, ref _callbackEventError);
  1225. return true;
  1226. }
  1227. #endif
  1228. string result = ProcessCallbackData ();
  1229. HtmlTextWriter callbackOutput = new HtmlTextWriter (Response.Output);
  1230. callbackOutput.Write (result);
  1231. callbackOutput.Flush ();
  1232. return true;
  1233. }
  1234. Trace.Write ("aspx.page", "Begin PreRender");
  1235. PreRenderRecursiveInternal ();
  1236. Trace.Write ("aspx.page", "End PreRender");
  1237. ExecuteRegisteredAsyncTasks ();
  1238. Trace.Write ("aspx.page", "Begin PreRenderComplete");
  1239. OnPreRenderComplete (EventArgs.Empty);
  1240. Trace.Write ("aspx.page", "End PreRenderComplete");
  1241. Trace.Write ("aspx.page", "Begin SaveViewState");
  1242. SavePageViewState ();
  1243. Trace.Write ("aspx.page", "End SaveViewState");
  1244. Trace.Write ("aspx.page", "Begin SaveStateComplete");
  1245. OnSaveStateComplete (EventArgs.Empty);
  1246. Trace.Write ("aspx.page", "End SaveStateComplete");
  1247. return false;
  1248. }
  1249. internal void RenderPage ()
  1250. {
  1251. scriptManager.ResetEventValidationState ();
  1252. //--
  1253. Trace.Write ("aspx.page", "Begin Render");
  1254. HtmlTextWriter output = CreateHtmlTextWriter (Response.Output);
  1255. RenderControl (output);
  1256. Trace.Write ("aspx.page", "End Render");
  1257. }
  1258. internal void SetContext (HttpContext context)
  1259. {
  1260. _context = context;
  1261. _application = context.Application;
  1262. _response = context.Response;
  1263. _request = context.Request;
  1264. _cache = context.Cache;
  1265. }
  1266. void RenderTrace ()
  1267. {
  1268. TraceManager traceManager = HttpRuntime.TraceManager;
  1269. if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
  1270. return;
  1271. Trace.SaveData ();
  1272. if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput)
  1273. return;
  1274. if (!traceManager.LocalOnly || Context.Request.IsLocal) {
  1275. HtmlTextWriter output = new HtmlTextWriter (Response.Output);
  1276. Trace.Render (output);
  1277. }
  1278. }
  1279. void RaisePostBackEvents ()
  1280. {
  1281. Control targetControl;
  1282. if (requiresRaiseEvent != null) {
  1283. RaisePostBackEvent (requiresRaiseEvent, null);
  1284. return;
  1285. }
  1286. if (formPostedRequiresRaiseEvent != null) {
  1287. RaisePostBackEvent (formPostedRequiresRaiseEvent, null);
  1288. return;
  1289. }
  1290. NameValueCollection postdata = _requestValueCollection;
  1291. if (postdata == null)
  1292. return;
  1293. string eventTarget = postdata [postEventSourceID];
  1294. if (eventTarget == null || eventTarget.Length == 0) {
  1295. if (formPostedRequiresRaiseEvent != null)
  1296. RaisePostBackEvent (formPostedRequiresRaiseEvent, null);
  1297. else
  1298. Validate ();
  1299. return;
  1300. }
  1301. targetControl = FindControl (eventTarget, true);
  1302. IPostBackEventHandler target = targetControl as IPostBackEventHandler;
  1303. if (target == null)
  1304. return;
  1305. string eventArgument = postdata [postEventArgumentID];
  1306. RaisePostBackEvent (target, eventArgument);
  1307. }
  1308. internal void RaiseChangedEvents ()
  1309. {
  1310. if (requiresPostDataChanged == null)
  1311. return;
  1312. foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
  1313. ipdh.RaisePostDataChangedEvent ();
  1314. requiresPostDataChanged = null;
  1315. }
  1316. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1317. protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
  1318. {
  1319. sourceControl.RaisePostBackEvent (eventArgument);
  1320. }
  1321. [Obsolete]
  1322. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1323. public void RegisterArrayDeclaration (string arrayName, string arrayValue)
  1324. {
  1325. scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
  1326. }
  1327. [Obsolete]
  1328. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1329. public virtual void RegisterClientScriptBlock (string key, string script)
  1330. {
  1331. scriptManager.RegisterClientScriptBlock (key, script);
  1332. }
  1333. [Obsolete]
  1334. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1335. public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
  1336. {
  1337. scriptManager.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
  1338. }
  1339. [MonoTODO("Not implemented, Used in HtmlForm")]
  1340. internal void RegisterClientScriptFile (string a, string b, string c)
  1341. {
  1342. throw new NotImplementedException ();
  1343. }
  1344. [Obsolete]
  1345. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1346. public void RegisterOnSubmitStatement (string key, string script)
  1347. {
  1348. scriptManager.RegisterOnSubmitStatement (key, script);
  1349. }
  1350. internal string GetSubmitStatements ()
  1351. {
  1352. return scriptManager.WriteSubmitStatements ();
  1353. }
  1354. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1355. public void RegisterRequiresPostBack (Control control)
  1356. {
  1357. if (!(control is IPostBackDataHandler))
  1358. throw new HttpException ("The control to register does not implement the IPostBackDataHandler interface.");
  1359. if (_requiresPostBack == null)
  1360. _requiresPostBack = new ArrayList ();
  1361. if (_requiresPostBack.Contains (control.UniqueID))
  1362. return;
  1363. _requiresPostBack.Add (control.UniqueID);
  1364. }
  1365. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1366. public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
  1367. {
  1368. requiresRaiseEvent = control;
  1369. }
  1370. [Obsolete]
  1371. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1372. public virtual void RegisterStartupScript (string key, string script)
  1373. {
  1374. scriptManager.RegisterStartupScript (key, script);
  1375. }
  1376. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1377. public void RegisterViewStateHandler ()
  1378. {
  1379. handleViewState = true;
  1380. }
  1381. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1382. protected virtual void SavePageStateToPersistenceMedium (object viewState)
  1383. {
  1384. PageStatePersister persister = this.PageStatePersister;
  1385. if (persister == null)
  1386. return;
  1387. Pair pair = viewState as Pair;
  1388. if (pair != null) {
  1389. persister.ViewState = pair.First;
  1390. persister.ControlState = pair.Second;
  1391. } else
  1392. persister.ViewState = viewState;
  1393. persister.Save ();
  1394. }
  1395. internal string RawViewState {
  1396. get {
  1397. NameValueCollection postdata = _requestValueCollection;
  1398. string view_state;
  1399. if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
  1400. return null;
  1401. if (view_state == "")
  1402. return null;
  1403. return view_state;
  1404. }
  1405. set { _savedViewState = value; }
  1406. }
  1407. protected virtual PageStatePersister PageStatePersister {
  1408. get {
  1409. if (page_state_persister == null && PageAdapter != null)
  1410. page_state_persister = PageAdapter.GetStatePersister();
  1411. if (page_state_persister == null)
  1412. page_state_persister = new HiddenFieldPageStatePersister (this);
  1413. return page_state_persister;
  1414. }
  1415. }
  1416. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1417. protected virtual object LoadPageStateFromPersistenceMedium ()
  1418. {
  1419. PageStatePersister persister = this.PageStatePersister;
  1420. if (persister == null)
  1421. return null;
  1422. persister.Load ();
  1423. return new Pair (persister.ViewState, persister.ControlState);
  1424. }
  1425. internal void LoadPageViewState ()
  1426. {
  1427. Pair sState = LoadPageStateFromPersistenceMedium () as Pair;
  1428. if (sState != null) {
  1429. if (allow_load || isCrossPagePostBack) {
  1430. LoadPageControlState (sState.Second);
  1431. Pair vsr = sState.First as Pair;
  1432. if (vsr != null) {
  1433. LoadViewStateRecursive (vsr.First);
  1434. _requiresPostBackCopy = vsr.Second as ArrayList;
  1435. }
  1436. }
  1437. }
  1438. }
  1439. internal void SavePageViewState ()
  1440. {
  1441. if (!handleViewState)
  1442. return;
  1443. object controlState = SavePageControlState ();
  1444. Pair vsr = null;
  1445. object viewState = null;
  1446. if (EnableViewState)
  1447. viewState = SaveViewStateRecursive ();
  1448. object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
  1449. if (viewState != null || reqPostback != null)
  1450. vsr = new Pair (viewState, reqPostback);
  1451. Pair pair = new Pair ();
  1452. pair.First = vsr;
  1453. pair.Second = controlState;
  1454. if (pair.First == null && pair.Second == null)
  1455. SavePageStateToPersistenceMedium (null);
  1456. else
  1457. SavePageStateToPersistenceMedium (pair);
  1458. }
  1459. public virtual void Validate ()
  1460. {
  1461. is_validated = true;
  1462. ValidateCollection (_validators);
  1463. }
  1464. internal bool AreValidatorsUplevel ()
  1465. {
  1466. return AreValidatorsUplevel (String.Empty);
  1467. }
  1468. internal bool AreValidatorsUplevel (string valGroup)
  1469. {
  1470. bool uplevel = false;
  1471. foreach (IValidator v in Validators) {
  1472. BaseValidator bv = v as BaseValidator;
  1473. if (bv == null)
  1474. continue;
  1475. if (valGroup != bv.ValidationGroup)
  1476. continue;
  1477. if (bv.GetRenderUplevel()) {
  1478. uplevel = true;
  1479. break;
  1480. }
  1481. }
  1482. return uplevel;
  1483. }
  1484. bool ValidateCollection (ValidatorCollection validators)
  1485. {
  1486. if (validators == null || validators.Count == 0)
  1487. return true;
  1488. bool all_valid = true;
  1489. foreach (IValidator v in validators){
  1490. v.Validate ();
  1491. if (v.IsValid == false)
  1492. all_valid = false;
  1493. }
  1494. return all_valid;
  1495. }
  1496. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1497. public virtual void VerifyRenderingInServerForm (Control control)
  1498. {
  1499. if (Context == null)
  1500. return;
  1501. if (IsCallback)
  1502. return;
  1503. if (!renderingForm)
  1504. throw new HttpException ("Control '" +
  1505. control.ClientID +
  1506. "' of type '" +
  1507. control.GetType ().Name +
  1508. "' must be placed inside a form tag with runat=server.");
  1509. }
  1510. protected override void FrameworkInitialize ()
  1511. {
  1512. base.FrameworkInitialize ();
  1513. InitializeStyleSheet ();
  1514. }
  1515. #endregion
  1516. public ClientScriptManager ClientScript {
  1517. get { return scriptManager; }
  1518. }
  1519. internal static readonly object InitCompleteEvent = new object ();
  1520. internal static readonly object LoadCompleteEvent = new object ();
  1521. internal static readonly object PreInitEvent = new object ();
  1522. internal static readonly object PreLoadEvent = new object ();
  1523. internal static readonly object PreRenderCompleteEvent = new object ();
  1524. internal static readonly object SaveStateCompleteEvent = new object ();
  1525. int event_mask;
  1526. const int initcomplete_mask = 1;
  1527. const int loadcomplete_mask = 1 << 1;
  1528. const int preinit_mask = 1 << 2;
  1529. const int preload_mask = 1 << 3;
  1530. const int prerendercomplete_mask = 1 << 4;
  1531. const int savestatecomplete_mask = 1 << 5;
  1532. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1533. public event EventHandler InitComplete {
  1534. add {
  1535. event_mask |= initcomplete_mask;
  1536. Events.AddHandler (InitCompleteEvent, value);
  1537. }
  1538. remove { Events.RemoveHandler (InitCompleteEvent, value); }
  1539. }
  1540. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1541. public event EventHandler LoadComplete {
  1542. add {
  1543. event_mask |= loadcomplete_mask;
  1544. Events.AddHandler (LoadCompleteEvent, value);
  1545. }
  1546. remove { Events.RemoveHandler (LoadCompleteEvent, value); }
  1547. }
  1548. public event EventHandler PreInit {
  1549. add {
  1550. event_mask |= preinit_mask;
  1551. Events.AddHandler (PreInitEvent, value);
  1552. }
  1553. remove { Events.RemoveHandler (PreInitEvent, value); }
  1554. }
  1555. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1556. public event EventHandler PreLoad {
  1557. add {
  1558. event_mask |= preload_mask;
  1559. Events.AddHandler (PreLoadEvent, value);
  1560. }
  1561. remove { Events.RemoveHandler (PreLoadEvent, value); }
  1562. }
  1563. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1564. public event EventHandler PreRenderComplete {
  1565. add {
  1566. event_mask |= prerendercomplete_mask;
  1567. Events.AddHandler (PreRenderCompleteEvent, value);
  1568. }
  1569. remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
  1570. }
  1571. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1572. public event EventHandler SaveStateComplete {
  1573. add {
  1574. event_mask |= savestatecomplete_mask;
  1575. Events.AddHandler (SaveStateCompleteEvent, value);
  1576. }
  1577. remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
  1578. }
  1579. protected virtual void OnInitComplete (EventArgs e)
  1580. {
  1581. if ((event_mask & initcomplete_mask) != 0) {
  1582. EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
  1583. if (eh != null) eh (this, e);
  1584. }
  1585. }
  1586. protected virtual void OnLoadComplete (EventArgs e)
  1587. {
  1588. if ((event_mask & loadcomplete_mask) != 0) {
  1589. EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
  1590. if (eh != null) eh (this, e);
  1591. }
  1592. }
  1593. protected virtual void OnPreInit (EventArgs e)
  1594. {
  1595. if ((event_mask & preinit_mask) != 0) {
  1596. EventHandler eh = (EventHandler) (Events [PreInitEvent]);
  1597. if (eh != null) eh (this, e);
  1598. }
  1599. }
  1600. protected virtual void OnPreLoad (EventArgs e)
  1601. {
  1602. if ((event_mask & preload_mask) != 0) {
  1603. EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
  1604. if (eh != null) eh (this, e);
  1605. }
  1606. }
  1607. protected virtual void OnPreRenderComplete (EventArgs e)
  1608. {
  1609. if ((event_mask & prerendercomplete_mask) != 0) {
  1610. EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
  1611. if (eh != null) eh (this, e);
  1612. }
  1613. if (Form == null)
  1614. return;
  1615. if (!Form.DetermineRenderUplevel ())
  1616. return;
  1617. string defaultButtonId = Form.DefaultButton;
  1618. /* figure out if we have some control we're going to focus */
  1619. if (String.IsNullOrEmpty (_focusedControlID)) {
  1620. _focusedControlID = Form.DefaultFocus;
  1621. if (String.IsNullOrEmpty (_focusedControlID))
  1622. _focusedControlID = defaultButtonId;
  1623. }
  1624. if (!String.IsNullOrEmpty (_focusedControlID)) {
  1625. ClientScript.RegisterWebFormClientScript ();
  1626. ClientScript.RegisterStartupScript (
  1627. typeof(Page),
  1628. "HtmlForm-DefaultButton-StartupScript",
  1629. "\n" + WebFormScriptReference + ".WebForm_AutoFocus('" + _focusedControlID + "');\n", true);
  1630. }
  1631. if (Form.SubmitDisabledControls && _hasEnabledControlArray) {
  1632. ClientScript.RegisterWebFormClientScript ();
  1633. ClientScript.RegisterOnSubmitStatement (
  1634. typeof (Page),
  1635. "HtmlForm-SubmitDisabledControls-SubmitStatement",
  1636. WebFormScriptReference + ".WebForm_ReEnableControls();");
  1637. }
  1638. }
  1639. internal void RegisterEnabledControl (Control control)
  1640. {
  1641. if (Form == null || !Page.Form.SubmitDisabledControls || !Page.Form.DetermineRenderUplevel ())
  1642. return;
  1643. _hasEnabledControlArray = true;
  1644. Page.ClientScript.RegisterArrayDeclaration (EnabledControlArrayID, String.Concat ("'", control.ClientID, "'"));
  1645. }
  1646. protected virtual void OnSaveStateComplete (EventArgs e)
  1647. {
  1648. if ((event_mask & savestatecomplete_mask) != 0) {
  1649. EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
  1650. if (eh != null) eh (this, e);
  1651. }
  1652. }
  1653. public HtmlForm Form {
  1654. get { return _form; }
  1655. }
  1656. internal void RegisterForm (HtmlForm form)
  1657. {
  1658. _form = form;
  1659. }
  1660. public string ClientQueryString {
  1661. get { return Request.UrlComponents.Query; }
  1662. }
  1663. [BrowsableAttribute (false)]
  1664. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1665. public Page PreviousPage {
  1666. get {
  1667. if (_doLoadPreviousPage) {
  1668. _doLoadPreviousPage = false;
  1669. LoadPreviousPageReference ();
  1670. }
  1671. return previousPage;
  1672. }
  1673. }
  1674. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1675. [BrowsableAttribute (false)]
  1676. public bool IsCallback {
  1677. get { return isCallback; }
  1678. }
  1679. [BrowsableAttribute (false)]
  1680. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1681. public bool IsCrossPagePostBack {
  1682. get { return isCrossPagePostBack; }
  1683. }
  1684. public new virtual char IdSeparator {
  1685. get {
  1686. //TODO: why override?
  1687. return base.IdSeparator;
  1688. }
  1689. }
  1690. string ProcessCallbackData ()
  1691. {
  1692. ICallbackEventHandler target = GetCallbackTarget ();
  1693. string callbackEventError = String.Empty;
  1694. ProcessRaiseCallbackEvent (target, ref callbackEventError);
  1695. return ProcessGetCallbackResult (target, callbackEventError);
  1696. }
  1697. ICallbackEventHandler GetCallbackTarget ()
  1698. {
  1699. string callbackTarget = _requestValueCollection [CallbackSourceID];
  1700. if (callbackTarget == null || callbackTarget.Length == 0)
  1701. throw new HttpException ("Callback target not provided.");
  1702. Control targetControl = FindControl (callbackTarget, true);
  1703. ICallbackEventHandler target = targetControl as ICallbackEventHandler;
  1704. if (target == null)
  1705. throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
  1706. return target;
  1707. }
  1708. void ProcessRaiseCallbackEvent (ICallbackEventHandler target, ref string callbackEventError)
  1709. {
  1710. string callbackArgument = _requestValueCollection [CallbackArgumentID];
  1711. try {
  1712. target.RaiseCallbackEvent (callbackArgument);
  1713. } catch (Exception ex) {
  1714. callbackEventError = String.Concat ("e", RuntimeHelpers.DebuggingEnabled ? ex.ToString () : ex.Message);
  1715. }
  1716. }
  1717. string ProcessGetCallbackResult (ICallbackEventHandler target, string callbackEventError)
  1718. {
  1719. string callBackResult;
  1720. try {
  1721. callBackResult = target.GetCallbackResult ();
  1722. } catch (Exception ex) {
  1723. return String.Concat ("e", RuntimeHelpers.DebuggingEnabled ? ex.ToString () : ex.Message);
  1724. }
  1725. string eventValidation = ClientScript.GetEventValidationStateFormatted ();
  1726. return callbackEventError + (eventValidation == null ? "0" : eventValidation.Length.ToString ()) + "|" +
  1727. eventValidation + callBackResult;
  1728. }
  1729. [BrowsableAttribute (false)]
  1730. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1731. public HtmlHead Header {
  1732. get { return htmlHeader; }
  1733. }
  1734. internal void SetHeader (HtmlHead header)
  1735. {
  1736. htmlHeader = header;
  1737. if (_title != null) {
  1738. htmlHeader.Title = _title;
  1739. _title = null;
  1740. }
  1741. }
  1742. protected bool AsyncMode {
  1743. get { return asyncMode; }
  1744. set { asyncMode = value; }
  1745. }
  1746. public TimeSpan AsyncTimeout {
  1747. get { return asyncTimeout; }
  1748. set { asyncTimeout = value; }
  1749. }
  1750. public bool IsAsync {
  1751. get { return AsyncMode; }
  1752. }
  1753. protected internal virtual string UniqueFilePathSuffix {
  1754. get {
  1755. if (String.IsNullOrEmpty (uniqueFilePathSuffix))
  1756. uniqueFilePathSuffix = "__ufps=" + AppRelativeVirtualPath.GetHashCode ().ToString ("x");
  1757. return uniqueFilePathSuffix;
  1758. }
  1759. }
  1760. [MonoTODO ("Actually use the value in code.")]
  1761. public int MaxPageStateFieldLength {
  1762. get { return maxPageStateFieldLength; }
  1763. set { maxPageStateFieldLength = value; }
  1764. }
  1765. public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler)
  1766. {
  1767. AddOnPreRenderCompleteAsync (beginHandler, endHandler, null);
  1768. }
  1769. public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, Object state)
  1770. {
  1771. if (!IsAsync) {
  1772. throw new InvalidOperationException ("AddOnPreRenderCompleteAsync called and Page.IsAsync == false");
  1773. }
  1774. if (IsPrerendered) {
  1775. throw new InvalidOperationException ("AddOnPreRenderCompleteAsync can only be called before and during PreRender.");
  1776. }
  1777. if (beginHandler == null) {
  1778. throw new ArgumentNullException ("beginHandler");
  1779. }
  1780. if (endHandler == null) {
  1781. throw new ArgumentNullException ("endHandler");
  1782. }
  1783. RegisterAsyncTask (new PageAsyncTask (beginHandler, endHandler, null, state, false));
  1784. }
  1785. List<PageAsyncTask> ParallelTasks {
  1786. get {
  1787. if (parallelTasks == null)
  1788. parallelTasks = new List<PageAsyncTask>();
  1789. return parallelTasks;
  1790. }
  1791. }
  1792. List<PageAsyncTask> SerialTasks {
  1793. get {
  1794. if (serialTasks == null)
  1795. serialTasks = new List<PageAsyncTask> ();
  1796. return serialTasks;
  1797. }
  1798. }
  1799. public void RegisterAsyncTask (PageAsyncTask task)
  1800. {
  1801. if (task == null)
  1802. throw new ArgumentNullException ("task");
  1803. if (task.ExecuteInParallel)
  1804. ParallelTasks.Add (task);
  1805. else
  1806. SerialTasks.Add (task);
  1807. }
  1808. public void ExecuteRegisteredAsyncTasks ()
  1809. {
  1810. if ((parallelTasks == null || parallelTasks.Count == 0) &&
  1811. (serialTasks == null || serialTasks.Count == 0)){
  1812. return;
  1813. }
  1814. if (parallelTasks != null) {
  1815. DateTime startExecution = DateTime.Now;
  1816. List<PageAsyncTask> localParallelTasks = parallelTasks;
  1817. parallelTasks = null; // Shouldn't execute tasks twice
  1818. List<IAsyncResult> asyncResults = new List<IAsyncResult>();
  1819. foreach (PageAsyncTask parallelTask in localParallelTasks) {
  1820. IAsyncResult result = parallelTask.BeginHandler (this, EventArgs.Empty, new AsyncCallback (EndAsyncTaskCallback), parallelTask.State);
  1821. if (result.CompletedSynchronously)
  1822. parallelTask.EndHandler (result);
  1823. else
  1824. asyncResults.Add (result);
  1825. }
  1826. if (asyncResults.Count > 0) {
  1827. #if TARGET_JVM
  1828. TimeSpan timeout = AsyncTimeout;
  1829. long t1 = DateTime.Now.Ticks;
  1830. bool signalled = true;
  1831. for (int i = 0; i < asyncResults.Count; i++) {
  1832. if (asyncResults [i].IsCompleted)
  1833. continue;
  1834. if (signalled)
  1835. signalled = asyncResults [i].AsyncWaitHandle.WaitOne (timeout, false);
  1836. if (signalled) {
  1837. long t2 = DateTime.Now.Ticks;
  1838. timeout = AsyncTimeout - TimeSpan.FromTicks (t2 - t1);
  1839. if (timeout.Ticks <= 0)
  1840. signalled = false;
  1841. } else
  1842. localParallelTasks [i].TimeoutHandler (asyncResults [i]);
  1843. }
  1844. #else
  1845. WaitHandle [] waitArray = new WaitHandle [asyncResults.Count];
  1846. int i = 0;
  1847. for (i = 0; i < asyncResults.Count; i++) {
  1848. waitArray [i] = asyncResults [i].AsyncWaitHandle;
  1849. }
  1850. bool allSignalled = WaitHandle.WaitAll (waitArray, AsyncTimeout, false);
  1851. if (!allSignalled) {
  1852. for (i = 0; i < asyncResults.Count; i++) {
  1853. if (!asyncResults [i].IsCompleted) {
  1854. localParallelTasks [i].TimeoutHandler (asyncResults [i]);
  1855. }
  1856. }
  1857. }
  1858. #endif
  1859. }
  1860. DateTime endWait = DateTime.Now;
  1861. TimeSpan elapsed = endWait - startExecution;
  1862. if (elapsed <= AsyncTimeout)
  1863. AsyncTimeout -= elapsed;
  1864. else
  1865. AsyncTimeout = TimeSpan.FromTicks(0);
  1866. }
  1867. if (serialTasks != null) {
  1868. List<PageAsyncTask> localSerialTasks = serialTasks;
  1869. serialTasks = null; // Shouldn't execute tasks twice
  1870. foreach (PageAsyncTask serialTask in localSerialTasks) {
  1871. DateTime startExecution = DateTime.Now;
  1872. IAsyncResult result = serialTask.BeginHandler (this, EventArgs.Empty, new AsyncCallback (EndAsyncTaskCallback), serialTask);
  1873. if (result.CompletedSynchronously)
  1874. serialTask.EndHandler (result);
  1875. else {
  1876. bool done = result.AsyncWaitHandle.WaitOne (AsyncTimeout, false);
  1877. if (!done && !result.IsCompleted) {
  1878. serialTask.TimeoutHandler (result);
  1879. }
  1880. }
  1881. DateTime endWait = DateTime.Now;
  1882. TimeSpan elapsed = endWait - startExecution;
  1883. if (elapsed <= AsyncTimeout)
  1884. AsyncTimeout -= elapsed;
  1885. else
  1886. AsyncTimeout = TimeSpan.FromTicks (0);
  1887. }
  1888. }
  1889. AsyncTimeout = TimeSpan.FromSeconds (DefaultAsyncTimeout);
  1890. }
  1891. void EndAsyncTaskCallback (IAsyncResult result)
  1892. {
  1893. PageAsyncTask task = (PageAsyncTask)result.AsyncState;
  1894. task.EndHandler (result);
  1895. }
  1896. public static HtmlTextWriter CreateHtmlTextWriterFromType (TextWriter tw, Type writerType)
  1897. {
  1898. Type htmlTextWriterType = typeof (HtmlTextWriter);
  1899. if (!htmlTextWriterType.IsAssignableFrom (writerType)) {
  1900. throw new HttpException (String.Format ("Type '{0}' cannot be assigned to HtmlTextWriter", writerType.FullName));
  1901. }
  1902. ConstructorInfo constructor = writerType.GetConstructor (new Type [] { typeof (TextWriter) });
  1903. if (constructor == null) {
  1904. throw new HttpException (String.Format ("Type '{0}' does not have a consturctor that takes a TextWriter as parameter", writerType.FullName));
  1905. }
  1906. return (HtmlTextWriter) Activator.CreateInstance(writerType, tw);
  1907. }
  1908. public ViewStateEncryptionMode ViewStateEncryptionMode {
  1909. get { return viewStateEncryptionMode; }
  1910. set { viewStateEncryptionMode = value; }
  1911. }
  1912. public void RegisterRequiresViewStateEncryption ()
  1913. {
  1914. controlRegisteredForViewStateEncryption = true;
  1915. }
  1916. static byte [] AES_IV = null;
  1917. static byte [] TripleDES_IV = null;
  1918. static object locker = new object ();
  1919. static bool isEncryptionInitialized = false;
  1920. static void InitializeEncryption ()
  1921. {
  1922. if (isEncryptionInitialized)
  1923. return;
  1924. lock (locker) {
  1925. if (isEncryptionInitialized)
  1926. return;
  1927. string iv_string = "0BA48A9E-736D-40f8-954B-B2F62241F282";
  1928. AES_IV = new byte [16];
  1929. TripleDES_IV = new byte [8];
  1930. int i;
  1931. for (i = 0; i < AES_IV.Length; i++) {
  1932. AES_IV [i] = (byte) iv_string [i];
  1933. }
  1934. for (i = 0; i < TripleDES_IV.Length; i++) {
  1935. TripleDES_IV [i] = (byte) iv_string [i];
  1936. }
  1937. isEncryptionInitialized = true;
  1938. }
  1939. }
  1940. internal ICryptoTransform GetCryptoTransform (CryptoStreamMode cryptoStreamMode)
  1941. {
  1942. ICryptoTransform transform = null;
  1943. MachineKeySection config = (MachineKeySection) WebConfigurationManager.GetSection (machineKeyConfigPath);
  1944. byte [] vk = MachineKeySectionUtils.ValidationKeyBytes (config);
  1945. switch (config.Validation) {
  1946. case MachineKeyValidation.SHA1:
  1947. transform = SHA1.Create ();
  1948. break;
  1949. case MachineKeyValidation.MD5:
  1950. transform = MD5.Create ();
  1951. break;
  1952. case MachineKeyValidation.AES:
  1953. InitializeEncryption ();
  1954. if (cryptoStreamMode == CryptoStreamMode.Read){
  1955. transform = Rijndael.Create().CreateDecryptor(vk, AES_IV);
  1956. } else {
  1957. transform = Rijndael.Create().CreateEncryptor(vk, AES_IV);
  1958. }
  1959. break;
  1960. case MachineKeyValidation.TripleDES:
  1961. InitializeEncryption ();
  1962. if (cryptoStreamMode == CryptoStreamMode.Read){
  1963. transform = TripleDES.Create().CreateDecryptor(vk, TripleDES_IV);
  1964. } else {
  1965. transform = TripleDES.Create().CreateEncryptor(vk, TripleDES_IV);
  1966. }
  1967. break;
  1968. }
  1969. return transform;
  1970. }
  1971. internal bool NeedViewStateEncryption {
  1972. get {
  1973. return (ViewStateEncryptionMode == ViewStateEncryptionMode.Always ||
  1974. (ViewStateEncryptionMode == ViewStateEncryptionMode.Auto &&
  1975. controlRegisteredForViewStateEncryption));
  1976. }
  1977. }
  1978. void ApplyMasterPage ()
  1979. {
  1980. if (masterPageFile != null && masterPageFile.Length > 0) {
  1981. ArrayList appliedMasterPageFiles = new ArrayList ();
  1982. if (Master != null) {
  1983. MasterPage.ApplyMasterPageRecursive (Master, appliedMasterPageFiles);
  1984. Master.Page = this;
  1985. Controls.Clear ();
  1986. Controls.Add (Master);
  1987. }
  1988. }
  1989. }
  1990. [DefaultValueAttribute ("")]
  1991. public virtual string MasterPageFile {
  1992. get { return masterPageFile; }
  1993. set {
  1994. masterPageFile = value;
  1995. masterPage = null;
  1996. }
  1997. }
  1998. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1999. [BrowsableAttribute (false)]
  2000. public MasterPage Master {
  2001. get {
  2002. if (Context == null || String.IsNullOrEmpty (masterPageFile))
  2003. return null;
  2004. if (masterPage == null)
  2005. masterPage = MasterPage.CreateMasterPage (this, Context, masterPageFile, contentTemplates);
  2006. return masterPage;
  2007. }
  2008. }
  2009. public void SetFocus (string clientID)
  2010. {
  2011. if (String.IsNullOrEmpty (clientID))
  2012. throw new ArgumentNullException ("control");
  2013. if (IsPrerendered)
  2014. throw new InvalidOperationException ("SetFocus can only be called before and during PreRender.");
  2015. if(Form==null)
  2016. throw new InvalidOperationException ("A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.");
  2017. _focusedControlID = clientID;
  2018. }
  2019. public void SetFocus (Control control)
  2020. {
  2021. if (control == null)
  2022. throw new ArgumentNullException ("control");
  2023. SetFocus (control.ClientID);
  2024. }
  2025. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2026. public void RegisterRequiresControlState (Control control)
  2027. {
  2028. if (control == null)
  2029. throw new ArgumentNullException ("control");
  2030. if (RequiresControlState (control))
  2031. return;
  2032. if (requireStateControls == null)
  2033. requireStateControls = new List <Control> ();
  2034. requireStateControls.Add (control);
  2035. int n = requireStateControls.Count - 1;
  2036. if (_savedControlState == null || n >= _savedControlState.Length)
  2037. return;
  2038. for (Control parent = control.Parent; parent != null; parent = parent.Parent)
  2039. if (parent.IsChildControlStateCleared)
  2040. return;
  2041. object state = _savedControlState [n];
  2042. if (state != null)
  2043. control.LoadControlState (state);
  2044. }
  2045. public bool RequiresControlState (Control control)
  2046. {
  2047. if (requireStateControls == null)
  2048. return false;
  2049. return requireStateControls.Contains (control);
  2050. }
  2051. [EditorBrowsable (EditorBrowsableState.Advanced)]
  2052. public void UnregisterRequiresControlState (Control control)
  2053. {
  2054. if (requireStateControls != null)
  2055. requireStateControls.Remove (control);
  2056. }
  2057. public ValidatorCollection GetValidators (string validationGroup)
  2058. {
  2059. if (validationGroup == String.Empty)
  2060. validationGroup = null;
  2061. ValidatorCollection col = new ValidatorCollection ();
  2062. if (_validators == null)
  2063. return col;
  2064. foreach (IValidator v in _validators)
  2065. if (BelongsToGroup(v, validationGroup))
  2066. col.Add(v);
  2067. return col;
  2068. }
  2069. bool BelongsToGroup(IValidator v, string validationGroup)
  2070. {
  2071. BaseValidator validator = v as BaseValidator;
  2072. if (validationGroup == null)
  2073. return validator == null || String.IsNullOrEmpty (validator.ValidationGroup);
  2074. else
  2075. return validator != null && validator.ValidationGroup == validationGroup;
  2076. }
  2077. public virtual void Validate (string validationGroup)
  2078. {
  2079. is_validated = true;
  2080. ValidateCollection (GetValidators (validationGroup));
  2081. }
  2082. object SavePageControlState ()
  2083. {
  2084. int count = requireStateControls == null ? 0 : requireStateControls.Count;
  2085. if (count == 0)
  2086. return null;
  2087. object state;
  2088. object[] controlStates = new object [count];
  2089. object[] adapterState = new object [count];
  2090. Control control;
  2091. ControlAdapter adapter;
  2092. bool allNull = true;
  2093. TraceContext trace = (Context != null && Context.Trace.IsEnabled) ? Context.Trace : null;
  2094. for (int n = 0; n < count; n++) {
  2095. control = requireStateControls [n];
  2096. state = controlStates [n] = control.SaveControlState ();
  2097. if (state != null)
  2098. allNull = false;
  2099. if (trace != null)
  2100. trace.SaveControlState (control, state);
  2101. adapter = control.Adapter;
  2102. if (adapter != null) {
  2103. adapterState [n] = adapter.SaveAdapterControlState ();
  2104. if (adapterState [n] != null) allNull = false;
  2105. }
  2106. }
  2107. if (allNull)
  2108. return null;
  2109. else
  2110. return new Pair (controlStates, adapterState);
  2111. }
  2112. void LoadPageControlState (object data)
  2113. {
  2114. _savedControlState = null;
  2115. if (data == null) return;
  2116. Pair statePair = (Pair)data;
  2117. _savedControlState = (object[]) statePair.First;
  2118. object[] adapterState = (object[]) statePair.Second;
  2119. if (requireStateControls == null) return;
  2120. int min = Math.Min (requireStateControls.Count, _savedControlState != null ? _savedControlState.Length : requireStateControls.Count);
  2121. for (int n=0; n < min; n++) {
  2122. Control ctl = (Control) requireStateControls [n];
  2123. ctl.LoadControlState (_savedControlState != null ? _savedControlState [n] : null);
  2124. if (ctl.Adapter != null)
  2125. ctl.Adapter.LoadAdapterControlState (adapterState != null ? adapterState [n] : null);
  2126. }
  2127. }
  2128. void LoadPreviousPageReference ()
  2129. {
  2130. if (_requestValueCollection != null) {
  2131. string prevPage = _requestValueCollection [PreviousPageID];
  2132. if (prevPage != null) {
  2133. #if TARGET_J2EE
  2134. if (getFacesContext () != null) {
  2135. IHttpHandler handler = Context.ApplicationInstance.GetHandler (Context, prevPage);
  2136. Server.Execute (handler, null, true, _context.Request.CurrentExecutionFilePath, null, false, false);
  2137. if (_context.Items.Contains (CrossPagePostBack)) {
  2138. previousPage = (Page) _context.Items [CrossPagePostBack];
  2139. _context.Items.Remove (CrossPagePostBack);
  2140. }
  2141. return;
  2142. }
  2143. #else
  2144. IHttpHandler handler;
  2145. handler = BuildManager.CreateInstanceFromVirtualPath (prevPage, typeof (IHttpHandler)) as IHttpHandler;
  2146. previousPage = (Page) handler;
  2147. previousPage.isCrossPagePostBack = true;
  2148. Server.Execute (handler, null, true, _context.Request.CurrentExecutionFilePath, null, false, false);
  2149. #endif
  2150. }
  2151. }
  2152. }
  2153. Hashtable contentTemplates;
  2154. [EditorBrowsable (EditorBrowsableState.Never)]
  2155. protected internal void AddContentTemplate (string templateName, ITemplate template)
  2156. {
  2157. if (contentTemplates == null)
  2158. contentTemplates = new Hashtable ();
  2159. contentTemplates [templateName] = template;
  2160. }
  2161. PageTheme _pageTheme;
  2162. internal PageTheme PageTheme {
  2163. get { return _pageTheme; }
  2164. }
  2165. PageTheme _styleSheetPageTheme;
  2166. internal PageTheme StyleSheetPageTheme {
  2167. get { return _styleSheetPageTheme; }
  2168. }
  2169. Stack dataItemCtx;
  2170. internal void PushDataItemContext (object o) {
  2171. if (dataItemCtx == null)
  2172. dataItemCtx = new Stack ();
  2173. dataItemCtx.Push (o);
  2174. }
  2175. internal void PopDataItemContext () {
  2176. if (dataItemCtx == null)
  2177. throw new InvalidOperationException ();
  2178. dataItemCtx.Pop ();
  2179. }
  2180. public object GetDataItem() {
  2181. if (dataItemCtx == null || dataItemCtx.Count == 0)
  2182. throw new InvalidOperationException ("No data item");
  2183. return dataItemCtx.Peek ();
  2184. }
  2185. protected internal override void OnInit (EventArgs e)
  2186. {
  2187. base.OnInit (e);
  2188. ArrayList themes = new ArrayList();
  2189. if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
  2190. themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
  2191. if (PageTheme != null && PageTheme.GetStyleSheets () != null)
  2192. themes.AddRange (PageTheme.GetStyleSheets ());
  2193. if (themes.Count > 0 && Header == null)
  2194. throw new InvalidOperationException ("Using themed css files requires a header control on the page.");
  2195. foreach (string lss in themes) {
  2196. HtmlLink hl = new HtmlLink ();
  2197. hl.Href = lss;
  2198. hl.Attributes["type"] = "text/css";
  2199. hl.Attributes["rel"] = "stylesheet";
  2200. Header.Controls.Add (hl);
  2201. }
  2202. }
  2203. [MonoTODO ("Not implemented. Only used by .net aspx parser")]
  2204. protected object GetWrappedFileDependencies (string [] list)
  2205. {
  2206. return list;
  2207. }
  2208. [MonoTODO ("Does nothing. Used by .net aspx parser")]
  2209. protected virtual void InitializeCulture ()
  2210. {
  2211. }
  2212. [MonoTODO ("Does nothing. Used by .net aspx parser")]
  2213. protected internal void AddWrappedFileDependencies (object virtualFileDependencies)
  2214. {
  2215. }
  2216. }
  2217. }