Page.cs 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013
  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. //
  9. // (C) 2002,2003 Ximian, Inc. (http://www.ximian.com)
  10. // Copyright (C) 2003,2005 Novell, Inc (http://www.novell.com)
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System;
  32. using System.Collections;
  33. using System.Collections.Specialized;
  34. using System.ComponentModel;
  35. using System.ComponentModel.Design;
  36. using System.ComponentModel.Design.Serialization;
  37. using System.Globalization;
  38. using System.IO;
  39. using System.Security.Cryptography;
  40. using System.Security.Permissions;
  41. using System.Security.Principal;
  42. using System.Text;
  43. using System.Threading;
  44. using System.Web;
  45. using System.Web.Caching;
  46. using System.Web.Configuration;
  47. using System.Web.SessionState;
  48. using System.Web.Util;
  49. using System.Web.UI.HtmlControls;
  50. using System.Web.UI.WebControls;
  51. #if NET_2_0
  52. using System.Web.UI.Adapters;
  53. #endif
  54. namespace System.Web.UI
  55. {
  56. // CAS
  57. [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  58. [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  59. #if !NET_2_0
  60. [RootDesignerSerializer ("Microsoft.VSDesigner.WebForms.RootCodeDomSerializer, " + Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + Consts.AssemblySystem_Design, true)]
  61. #endif
  62. [DefaultEvent ("Load"), DesignerCategory ("ASPXCodeBehind")]
  63. [ToolboxItem (false)]
  64. #if NET_2_0
  65. [Designer ("Microsoft.VisualStudio.Web.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VisualStudio_Web, typeof (IRootDesigner))]
  66. #else
  67. [Designer ("Microsoft.VSDesigner.WebForms.WebFormDesigner, " + Consts.AssemblyMicrosoft_VSDesigner, typeof (IRootDesigner))]
  68. #endif
  69. public class Page : TemplateControl, IHttpHandler
  70. {
  71. #if NET_2_0
  72. private PageLifeCycle _lifeCycle = PageLifeCycle.Unknown;
  73. private bool _eventValidation = true;
  74. private object [] _savedControlState;
  75. #endif
  76. private bool _viewState = true;
  77. private bool _viewStateMac;
  78. private string _errorPage;
  79. private bool is_validated;
  80. private bool _smartNavigation;
  81. private int _transactionMode;
  82. private HttpContext _context;
  83. private ValidatorCollection _validators;
  84. private bool renderingForm;
  85. private object _savedViewState;
  86. private ArrayList _requiresPostBack;
  87. private ArrayList _requiresPostBackCopy;
  88. private ArrayList requiresPostDataChanged;
  89. private IPostBackEventHandler requiresRaiseEvent;
  90. private NameValueCollection secondPostData;
  91. private bool requiresPostBackScript;
  92. private bool postBackScriptRendered;
  93. bool handleViewState;
  94. string viewStateUserKey;
  95. NameValueCollection _requestValueCollection;
  96. string clientTarget;
  97. ClientScriptManager scriptManager;
  98. bool allow_load; // true when the Form collection belongs to this page (GetTypeHashCode)
  99. [EditorBrowsable (EditorBrowsableState.Never)]
  100. #if NET_2_0
  101. public
  102. #else
  103. protected
  104. #endif
  105. const string postEventArgumentID = "__EVENTARGUMENT";
  106. [EditorBrowsable (EditorBrowsableState.Never)]
  107. #if NET_2_0
  108. public
  109. #else
  110. protected
  111. #endif
  112. const string postEventSourceID = "__EVENTTARGET";
  113. #if NET_2_0
  114. const string ScrollPositionXID = "__SCROLLPOSITIONX";
  115. const string ScrollPositionYID = "__SCROLLPOSITIONY";
  116. #endif
  117. #if NET_2_0
  118. internal const string CallbackArgumentID = "__CALLBACKARGUMENT";
  119. internal const string CallbackSourceID = "__CALLBACKTARGET";
  120. internal const string PreviousPageID = "__PREVIOUSPAGE";
  121. HtmlHead htmlHeader;
  122. MasterPage masterPage;
  123. string masterPageFile;
  124. Page previousPage;
  125. bool isCrossPagePostBack;
  126. bool isPostBack;
  127. bool isCallback;
  128. ArrayList requireStateControls;
  129. Hashtable _validatorsByGroup;
  130. HtmlForm _form;
  131. string _title;
  132. string _theme;
  133. string _styleSheetTheme;
  134. Hashtable items;
  135. bool _maintainScrollPositionOnPostBack;
  136. #endif
  137. #region Constructor
  138. public Page ()
  139. {
  140. scriptManager = new ClientScriptManager (this);
  141. Page = this;
  142. ID = "__Page";
  143. }
  144. #endregion
  145. #region Properties
  146. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  147. [Browsable (false)]
  148. public HttpApplicationState Application
  149. {
  150. get {
  151. if (_context == null)
  152. return null;
  153. return _context.Application;
  154. }
  155. }
  156. [EditorBrowsable (EditorBrowsableState.Never)]
  157. protected bool AspCompatMode
  158. {
  159. #if NET_2_0
  160. get { return false; }
  161. #endif
  162. set { throw new NotImplementedException (); }
  163. }
  164. [EditorBrowsable (EditorBrowsableState.Never)]
  165. #if NET_2_0
  166. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  167. [BrowsableAttribute (false)]
  168. public bool Buffer
  169. {
  170. get { return Response.BufferOutput; }
  171. set { Response.BufferOutput = value; }
  172. }
  173. #else
  174. protected bool Buffer
  175. {
  176. set { Response.BufferOutput = value; }
  177. }
  178. #endif
  179. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  180. [Browsable (false)]
  181. public Cache Cache
  182. {
  183. get {
  184. if (_context == null)
  185. throw new HttpException ("No cache available without a context.");
  186. return _context.Cache;
  187. }
  188. }
  189. #if NET_2_0
  190. [EditorBrowsableAttribute (EditorBrowsableState.Advanced)]
  191. #endif
  192. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  193. [Browsable (false), DefaultValue ("")]
  194. [WebSysDescription ("Value do override the automatic browser detection and force the page to use the specified browser.")]
  195. public string ClientTarget
  196. {
  197. get { return (clientTarget == null) ? "" : clientTarget; }
  198. set {
  199. clientTarget = value;
  200. if (value == "")
  201. clientTarget = null;
  202. }
  203. }
  204. [EditorBrowsable (EditorBrowsableState.Never)]
  205. #if NET_2_0
  206. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  207. [BrowsableAttribute (false)]
  208. public int CodePage
  209. {
  210. get { return Response.ContentEncoding.CodePage; }
  211. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  212. }
  213. #else
  214. protected int CodePage
  215. {
  216. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  217. }
  218. #endif
  219. [EditorBrowsable (EditorBrowsableState.Never)]
  220. #if NET_2_0
  221. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  222. [BrowsableAttribute (false)]
  223. public string ContentType
  224. {
  225. get { return Response.ContentType; }
  226. set { Response.ContentType = value; }
  227. }
  228. #else
  229. protected string ContentType
  230. {
  231. set { Response.ContentType = value; }
  232. }
  233. #endif
  234. protected override HttpContext Context
  235. {
  236. get {
  237. if (_context == null)
  238. return HttpContext.Current;
  239. return _context;
  240. }
  241. }
  242. #if NET_2_0
  243. [EditorBrowsable (EditorBrowsableState.Advanced)]
  244. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  245. [BrowsableAttribute (false)]
  246. public string Culture
  247. {
  248. get { return Thread.CurrentThread.CurrentCulture.Name; }
  249. set { Thread.CurrentThread.CurrentCulture = GetPageCulture (value, Thread.CurrentThread.CurrentCulture); }
  250. }
  251. #else
  252. [EditorBrowsable (EditorBrowsableState.Never)]
  253. protected string Culture
  254. {
  255. set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
  256. }
  257. #endif
  258. #if NET_2_0
  259. public virtual bool EnableEventValidation {
  260. get { return _eventValidation; }
  261. set {
  262. if (_lifeCycle > PageLifeCycle.Init)
  263. throw new InvalidOperationException ("The 'EnableEventValidation' property can be set only in the Page_init, the Page directive or in the <pages> configuration section.");
  264. _eventValidation = value;
  265. }
  266. }
  267. internal PageLifeCycle LifeCycle {
  268. get { return _lifeCycle; }
  269. }
  270. #endif
  271. [Browsable (false)]
  272. public override bool EnableViewState
  273. {
  274. get { return _viewState; }
  275. set { _viewState = value; }
  276. }
  277. #if NET_2_0
  278. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  279. [BrowsableAttribute (false)]
  280. #endif
  281. [EditorBrowsable (EditorBrowsableState.Never)]
  282. #if NET_2_0
  283. public
  284. #else
  285. protected
  286. #endif
  287. bool EnableViewStateMac
  288. {
  289. get { return _viewStateMac; }
  290. set { _viewStateMac = value; }
  291. }
  292. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  293. [Browsable (false), DefaultValue ("")]
  294. [WebSysDescription ("The URL of a page used for error redirection.")]
  295. public string ErrorPage
  296. {
  297. get { return _errorPage; }
  298. set {
  299. _errorPage = value;
  300. if (_context != null)
  301. _context.ErrorPage = value;
  302. }
  303. }
  304. #if NET_2_0
  305. [Obsolete]
  306. #endif
  307. [EditorBrowsable (EditorBrowsableState.Never)]
  308. protected ArrayList FileDependencies
  309. {
  310. set {
  311. if (Response != null)
  312. Response.AddFileDependencies (value);
  313. }
  314. }
  315. [Browsable (false)]
  316. #if NET_2_0
  317. [EditorBrowsable (EditorBrowsableState.Never)]
  318. #endif
  319. public override string ID
  320. {
  321. get { return base.ID; }
  322. set { base.ID = value; }
  323. }
  324. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  325. [Browsable (false)]
  326. public bool IsPostBack
  327. {
  328. get {
  329. #if NET_2_0
  330. return isPostBack;
  331. #else
  332. return _requestValueCollection != null;
  333. #endif
  334. }
  335. }
  336. [EditorBrowsable (EditorBrowsableState.Never), Browsable (false)]
  337. public bool IsReusable {
  338. get { return false; }
  339. }
  340. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  341. [Browsable (false)]
  342. public bool IsValid {
  343. get {
  344. if (!is_validated)
  345. throw new HttpException (Locale.GetText ("Page hasn't been validated."));
  346. #if NET_2_0
  347. foreach (IValidator val in Validators)
  348. if (!val.IsValid)
  349. return false;
  350. return true;
  351. #else
  352. return ValidateCollection (_validators);
  353. #endif
  354. }
  355. }
  356. #if NET_2_0
  357. public IDictionary Items {
  358. get {
  359. if (items == null)
  360. items = new Hashtable ();
  361. return items;
  362. }
  363. }
  364. #endif
  365. [EditorBrowsable (EditorBrowsableState.Never)]
  366. #if NET_2_0
  367. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  368. [BrowsableAttribute (false)]
  369. public int LCID {
  370. get { return Thread.CurrentThread.CurrentCulture.LCID; }
  371. set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
  372. }
  373. #else
  374. protected int LCID {
  375. set { Thread.CurrentThread.CurrentCulture = new CultureInfo (value); }
  376. }
  377. #endif
  378. #if NET_2_0
  379. [Browsable (false)]
  380. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  381. public bool MaintainScrollPositionOnPostBack {
  382. get { return _maintainScrollPositionOnPostBack; }
  383. set { _maintainScrollPositionOnPostBack = value; }
  384. }
  385. #endif
  386. #if NET_2_0
  387. public PageAdapter PageAdapter {
  388. get {
  389. return (PageAdapter)Adapter;
  390. }
  391. }
  392. #endif
  393. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  394. [Browsable (false)]
  395. public HttpRequest Request
  396. {
  397. get {
  398. if (_context != null)
  399. return _context.Request;
  400. throw new HttpException("Request is not available without context");
  401. }
  402. }
  403. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  404. [Browsable (false)]
  405. public HttpResponse Response
  406. {
  407. get {
  408. if (_context != null)
  409. return _context.Response;
  410. throw new HttpException ("Response is not available without context");
  411. }
  412. }
  413. [EditorBrowsable (EditorBrowsableState.Never)]
  414. #if NET_2_0
  415. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  416. [BrowsableAttribute (false)]
  417. public string ResponseEncoding
  418. {
  419. get { return Response.ContentEncoding.WebName; }
  420. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  421. }
  422. #else
  423. protected string ResponseEncoding
  424. {
  425. set { Response.ContentEncoding = Encoding.GetEncoding (value); }
  426. }
  427. #endif
  428. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  429. [Browsable (false)]
  430. public HttpServerUtility Server
  431. {
  432. get {
  433. return Context.Server;
  434. }
  435. }
  436. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  437. [Browsable (false)]
  438. public virtual HttpSessionState Session
  439. {
  440. get {
  441. if (_context == null)
  442. _context = HttpContext.Current;
  443. if (_context == null)
  444. throw new HttpException ("Session is not available without context");
  445. if (_context.Session == null)
  446. throw new HttpException ("Session state can only be used " +
  447. "when enableSessionState is set to true, either " +
  448. "in a configuration file or in the Page directive.");
  449. return _context.Session;
  450. }
  451. }
  452. #if NET_2_0
  453. [FilterableAttribute (false)]
  454. [Obsolete]
  455. #endif
  456. [Browsable (false)]
  457. public bool SmartNavigation
  458. {
  459. get { return _smartNavigation; }
  460. set { _smartNavigation = value; }
  461. }
  462. #if NET_2_0
  463. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  464. [Filterable (false)]
  465. [Browsable (false)]
  466. public virtual string StyleSheetTheme {
  467. get { return _styleSheetTheme; }
  468. set { _styleSheetTheme = value; }
  469. }
  470. [Browsable (false)]
  471. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  472. public virtual string Theme {
  473. get { return _theme; }
  474. set { _theme = value; }
  475. }
  476. void InitializeStyleSheet ()
  477. {
  478. if (_styleSheetTheme == null) {
  479. PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
  480. if (ps != null)
  481. _styleSheetTheme = ps.StyleSheetTheme;
  482. }
  483. if (_styleSheetTheme != null && _styleSheetTheme != "")
  484. _styleSheetPageTheme = ThemeDirectoryCompiler.GetCompiledInstance ("~/App_Themes/" + _styleSheetTheme + "/", _context);
  485. }
  486. void InitializeTheme ()
  487. {
  488. if (_theme == null) {
  489. PagesSection ps = WebConfigurationManager.GetSection ("system.web/pages") as PagesSection;
  490. if (ps != null)
  491. _theme = ps.Theme;
  492. }
  493. if (_theme != null && _theme != "") {
  494. _pageTheme = ThemeDirectoryCompiler.GetCompiledInstance ("~/App_Themes/" + _theme + "/", _context);
  495. }
  496. }
  497. #endif
  498. #if NET_2_0
  499. [Localizable (true)]
  500. [Bindable (true)]
  501. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  502. public string Title {
  503. get {
  504. if (_title == null)
  505. return htmlHeader.Title;
  506. return _title;
  507. }
  508. set {
  509. if (htmlHeader != null)
  510. htmlHeader.Title = value;
  511. else
  512. _title = value;
  513. }
  514. }
  515. #endif
  516. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  517. [Browsable (false)]
  518. public TraceContext Trace
  519. {
  520. get { return Context.Trace; }
  521. }
  522. [EditorBrowsable (EditorBrowsableState.Never)]
  523. #if NET_2_0
  524. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  525. [BrowsableAttribute (false)]
  526. public bool TraceEnabled
  527. {
  528. get { return Trace.IsEnabled; }
  529. set { Trace.IsEnabled = value; }
  530. }
  531. #else
  532. protected bool TraceEnabled
  533. {
  534. set { Trace.IsEnabled = value; }
  535. }
  536. #endif
  537. [EditorBrowsable (EditorBrowsableState.Never)]
  538. #if NET_2_0
  539. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  540. [BrowsableAttribute (false)]
  541. public TraceMode TraceModeValue
  542. {
  543. get { return Trace.TraceMode; }
  544. set { Trace.TraceMode = value; }
  545. }
  546. #else
  547. protected TraceMode TraceModeValue
  548. {
  549. set { Trace.TraceMode = value; }
  550. }
  551. #endif
  552. [EditorBrowsable (EditorBrowsableState.Never)]
  553. protected int TransactionMode
  554. {
  555. #if NET_2_0
  556. get { return _transactionMode; }
  557. #endif
  558. set { _transactionMode = value; }
  559. }
  560. #if NET_2_0
  561. [EditorBrowsable (EditorBrowsableState.Advanced)]
  562. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  563. [BrowsableAttribute (false)]
  564. public string UICulture
  565. {
  566. get { return Thread.CurrentThread.CurrentUICulture.Name; }
  567. set { Thread.CurrentThread.CurrentUICulture = GetPageCulture (value, Thread.CurrentThread.CurrentUICulture); }
  568. }
  569. #else
  570. [EditorBrowsable (EditorBrowsableState.Never)]
  571. protected string UICulture
  572. {
  573. set { Thread.CurrentThread.CurrentUICulture = new CultureInfo (value); }
  574. }
  575. #endif
  576. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  577. [Browsable (false)]
  578. public IPrincipal User
  579. {
  580. get { return Context.User; }
  581. }
  582. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  583. [Browsable (false)]
  584. public ValidatorCollection Validators
  585. {
  586. get {
  587. if (_validators == null)
  588. _validators = new ValidatorCollection ();
  589. return _validators;
  590. }
  591. }
  592. [MonoTODO ("Use this when encrypting/decrypting ViewState")]
  593. [Browsable (false)]
  594. public string ViewStateUserKey {
  595. get { return viewStateUserKey; }
  596. set { viewStateUserKey = value; }
  597. }
  598. [Browsable (false)]
  599. public override bool Visible
  600. {
  601. get { return base.Visible; }
  602. set { base.Visible = value; }
  603. }
  604. #endregion
  605. #region Methods
  606. #if NET_2_0
  607. CultureInfo GetPageCulture (string culture, CultureInfo deflt)
  608. {
  609. if (culture == null)
  610. return deflt;
  611. CultureInfo ret = null;
  612. if (culture.StartsWith ("auto")) {
  613. string[] languages = Request.UserLanguages;
  614. try {
  615. if (languages != null && languages.Length > 0)
  616. ret = new CultureInfo (languages[0]);
  617. } catch {
  618. }
  619. if (ret == null)
  620. ret = deflt;
  621. } else
  622. ret = new CultureInfo (culture);
  623. return ret;
  624. }
  625. #endif
  626. [EditorBrowsable (EditorBrowsableState.Never)]
  627. protected IAsyncResult AspCompatBeginProcessRequest (HttpContext context,
  628. AsyncCallback cb,
  629. object extraData)
  630. {
  631. throw new NotImplementedException ();
  632. }
  633. [EditorBrowsable (EditorBrowsableState.Never)]
  634. protected void AspCompatEndProcessRequest (IAsyncResult result)
  635. {
  636. throw new NotImplementedException ();
  637. }
  638. [EditorBrowsable (EditorBrowsableState.Advanced)]
  639. protected virtual HtmlTextWriter CreateHtmlTextWriter (TextWriter tw)
  640. {
  641. return new HtmlTextWriter (tw);
  642. }
  643. [EditorBrowsable (EditorBrowsableState.Never)]
  644. public void DesignerInitialize ()
  645. {
  646. InitRecursive (null);
  647. }
  648. [EditorBrowsable (EditorBrowsableState.Advanced)]
  649. protected virtual NameValueCollection DeterminePostBackMode ()
  650. {
  651. if (_context == null)
  652. return null;
  653. HttpRequest req = _context.Request;
  654. if (req == null)
  655. return null;
  656. NameValueCollection coll = null;
  657. if (0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture)) {
  658. coll = req.Form;
  659. WebROCollection c = (WebROCollection) coll;
  660. allow_load = !c.GotID;
  661. if (allow_load) {
  662. c.ID = GetTypeHashCode ();
  663. } else {
  664. allow_load = (c.ID == GetTypeHashCode ());
  665. }
  666. } else {
  667. coll = req.QueryString;
  668. }
  669. if (coll != null && coll ["__VIEWSTATE"] == null && coll ["__EVENTTARGET"] == null)
  670. return null;
  671. return coll;
  672. }
  673. #if NET_2_0
  674. public override Control FindControl (string id) {
  675. if (id == ID)
  676. return this;
  677. else
  678. return base.FindControl (id);
  679. }
  680. #endif
  681. #if NET_2_0
  682. [Obsolete]
  683. #endif
  684. [EditorBrowsable (EditorBrowsableState.Advanced)]
  685. public string GetPostBackClientEvent (Control control, string argument)
  686. {
  687. return scriptManager.GetPostBackEventReference (control, argument);
  688. }
  689. #if NET_2_0
  690. [Obsolete]
  691. #endif
  692. [EditorBrowsable (EditorBrowsableState.Advanced)]
  693. public string GetPostBackClientHyperlink (Control control, string argument)
  694. {
  695. return scriptManager.GetPostBackClientHyperlink (control, argument);
  696. }
  697. #if NET_2_0
  698. [Obsolete]
  699. #endif
  700. [EditorBrowsable (EditorBrowsableState.Advanced)]
  701. public string GetPostBackEventReference (Control control)
  702. {
  703. return scriptManager.GetPostBackEventReference (control, "");
  704. }
  705. #if NET_2_0
  706. [Obsolete]
  707. #endif
  708. [EditorBrowsable (EditorBrowsableState.Advanced)]
  709. public string GetPostBackEventReference (Control control, string argument)
  710. {
  711. return scriptManager.GetPostBackEventReference (control, argument);
  712. }
  713. internal void RequiresPostBackScript ()
  714. {
  715. requiresPostBackScript = true;
  716. }
  717. [EditorBrowsable (EditorBrowsableState.Never)]
  718. public virtual int GetTypeHashCode ()
  719. {
  720. return 0;
  721. }
  722. #if NET_2_0
  723. [MonoTODO("The following properties of OutputCacheParameters are silently ignored: CacheProfile, NoStore, SqlDependency")]
  724. protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings)
  725. {
  726. if (cacheSettings.Enabled)
  727. InitOutputCache(cacheSettings.Duration,
  728. cacheSettings.VaryByHeader,
  729. cacheSettings.VaryByCustom,
  730. cacheSettings.Location,
  731. cacheSettings.VaryByParam);
  732. }
  733. #endif
  734. [EditorBrowsable (EditorBrowsableState.Never)]
  735. protected virtual void InitOutputCache (int duration,
  736. string varyByHeader,
  737. string varyByCustom,
  738. OutputCacheLocation location,
  739. string varyByParam)
  740. {
  741. HttpCachePolicy cache = _context.Response.Cache;
  742. bool set_vary = false;
  743. switch (location) {
  744. case OutputCacheLocation.Any:
  745. cache.SetCacheability (HttpCacheability.Public);
  746. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  747. cache.SetLastModified (_context.Timestamp);
  748. set_vary = true;
  749. break;
  750. case OutputCacheLocation.Client:
  751. cache.SetCacheability (HttpCacheability.Private);
  752. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  753. cache.SetLastModified (_context.Timestamp);
  754. break;
  755. case OutputCacheLocation.Downstream:
  756. cache.SetCacheability (HttpCacheability.Public);
  757. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  758. cache.SetLastModified (_context.Timestamp);
  759. break;
  760. case OutputCacheLocation.Server:
  761. cache.SetCacheability (HttpCacheability.Server);
  762. set_vary = true;
  763. break;
  764. case OutputCacheLocation.None:
  765. break;
  766. }
  767. if (set_vary) {
  768. if (varyByCustom != null)
  769. cache.SetVaryByCustom (varyByCustom);
  770. if (varyByParam != null && varyByParam.Length > 0) {
  771. string[] prms = varyByParam.Split (';');
  772. foreach (string p in prms)
  773. cache.VaryByParams [p.Trim ()] = true;
  774. cache.VaryByParams.IgnoreParams = false;
  775. } else {
  776. cache.VaryByParams.IgnoreParams = true;
  777. }
  778. if (varyByHeader != null && varyByHeader.Length > 0) {
  779. string[] hdrs = varyByHeader.Split (';');
  780. foreach (string h in hdrs)
  781. cache.VaryByHeaders [h.Trim ()] = true;
  782. }
  783. }
  784. cache.Duration = duration;
  785. cache.SetExpires (_context.Timestamp.AddSeconds (duration));
  786. }
  787. #if NET_2_0
  788. [Obsolete]
  789. #else
  790. [EditorBrowsable (EditorBrowsableState.Advanced)]
  791. #endif
  792. public bool IsClientScriptBlockRegistered (string key)
  793. {
  794. return scriptManager.IsClientScriptBlockRegistered (key);
  795. }
  796. #if NET_2_0
  797. [Obsolete]
  798. #else
  799. [EditorBrowsable (EditorBrowsableState.Advanced)]
  800. #endif
  801. public bool IsStartupScriptRegistered (string key)
  802. {
  803. return scriptManager.IsStartupScriptRegistered (key);
  804. }
  805. public string MapPath (string virtualPath)
  806. {
  807. return Request.MapPath (virtualPath);
  808. }
  809. #if NET_2_0
  810. protected internal override void Render (HtmlTextWriter writer) {
  811. if (MaintainScrollPositionOnPostBack) {
  812. RequiresPostBackScript ();
  813. string scriptUrl = ClientScript.GetWebResourceUrl (typeof (Page), "MaintainScrollPositionOnPostBack.js");
  814. ClientScript.RegisterClientScriptInclude (typeof (Page), "MaintainScrollPositionOnPostBack.js", scriptUrl);
  815. ClientScript.RegisterHiddenField (ScrollPositionXID, Request [ScrollPositionXID]);
  816. ClientScript.RegisterHiddenField (ScrollPositionYID, Request [ScrollPositionYID]);
  817. StringBuilder script = new StringBuilder ();
  818. script.AppendLine ("<script type=\"text/javascript\">");
  819. script.AppendLine ("<!--");
  820. script.AppendLine ("theForm.oldSubmit = theForm.submit");
  821. script.AppendLine ("theForm.submit = WebForm_SaveScrollPositionSubmit");
  822. script.AppendLine ("theForm.oldOnSubmit = theForm.onsubmit");
  823. script.AppendLine ("theForm.onsubmit = WebForm_SaveScrollPositionOnSubmit");
  824. if (IsPostBack) {
  825. script.AppendLine ("theForm.oldOnLoad = window.onload");
  826. script.AppendLine ("window.onload = WebForm_RestoreScrollPosition");
  827. }
  828. script.AppendLine ("// -->");
  829. script.AppendLine ("</script>");
  830. ClientScript.RegisterStartupScript (typeof (Page), "MaintainScrollPositionOnPostBackStartup", script.ToString());
  831. }
  832. base.Render (writer);
  833. }
  834. #endif
  835. private void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
  836. {
  837. writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventSourceID);
  838. writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventArgumentID);
  839. writer.WriteLine ();
  840. writer.WriteLine ("<script language=\"javascript\">");
  841. writer.WriteLine ("<!--");
  842. writer.WriteLine ("\tvar theForm;\n\tif (document.getElementById) {{ theForm = document.getElementById ('{0}'); }}", formUniqueID);
  843. writer.WriteLine ("\telse {{ theForm = document.{0}; }}", formUniqueID);
  844. writer.WriteLine ("\tfunction __doPostBack(eventTarget, eventArgument) {");
  845. writer.WriteLine ("\t\ttheForm.{0}.value = eventTarget;", postEventSourceID);
  846. writer.WriteLine ("\t\ttheForm.{0}.value = eventArgument;", postEventArgumentID);
  847. writer.WriteLine ("\t\ttheForm.submit();");
  848. writer.WriteLine ("\t}");
  849. writer.WriteLine ("// -->");
  850. writer.WriteLine ("</script>");
  851. }
  852. internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
  853. {
  854. if (renderingForm)
  855. throw new HttpException ("Only 1 HtmlForm is allowed per page.");
  856. renderingForm = true;
  857. writer.WriteLine ();
  858. scriptManager.WriteHiddenFields (writer);
  859. if (requiresPostBackScript) {
  860. RenderPostBackScript (writer, formUniqueID);
  861. postBackScriptRendered = true;
  862. }
  863. if (handleViewState) {
  864. string vs = GetViewStateString ();
  865. writer.Write ("<input type=\"hidden\" name=\"__VIEWSTATE\" ");
  866. writer.WriteLine ("value=\"{0}\" />", vs);
  867. }
  868. scriptManager.WriteClientScriptBlocks (writer);
  869. }
  870. internal LosFormatter GetFormatter ()
  871. {
  872. #if NET_2_0
  873. PagesSection config = (PagesSection) WebConfigurationManager.GetSection ("system.web/pages");
  874. #else
  875. PagesConfiguration config = PagesConfiguration.GetInstance (_context);
  876. #endif
  877. byte [] vkey = null;
  878. if (config.EnableViewStateMac) {
  879. #if NET_2_0
  880. MachineKeySection mconfig = (MachineKeySection) WebConfigurationManager.GetSection ("system.web/machineKey");
  881. vkey = mconfig.ValidationKeyBytes;
  882. #else
  883. MachineKeyConfig mconfig = HttpContext.GetAppConfig ("system.web/machineKey") as MachineKeyConfig;
  884. vkey = mconfig.ValidationKey;
  885. #endif
  886. }
  887. return new LosFormatter (config.EnableViewStateMac, vkey);
  888. }
  889. string GetViewStateString ()
  890. {
  891. if (_savedViewState == null)
  892. return null;
  893. LosFormatter fmt = GetFormatter ();
  894. return fmt.SerializeToBase64 (_savedViewState);
  895. }
  896. internal object GetSavedViewState ()
  897. {
  898. return _savedViewState;
  899. }
  900. internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
  901. {
  902. scriptManager.WriteArrayDeclares (writer);
  903. if (!postBackScriptRendered && requiresPostBackScript)
  904. RenderPostBackScript (writer, formUniqueID);
  905. #if NET_2_0
  906. scriptManager.SaveEventValidationState ();
  907. #endif
  908. scriptManager.WriteHiddenFields (writer);
  909. scriptManager.WriteClientScriptIncludes (writer);
  910. scriptManager.WriteStartupScriptBlocks (writer);
  911. renderingForm = false;
  912. postBackScriptRendered = false;
  913. }
  914. private void ProcessPostData (NameValueCollection data, bool second)
  915. {
  916. if (data == null)
  917. return;
  918. if (_requiresPostBackCopy == null && _requiresPostBack != null)
  919. _requiresPostBackCopy = (ArrayList) _requiresPostBack.Clone ();
  920. Hashtable used = new Hashtable ();
  921. foreach (string id in data.AllKeys){
  922. if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID)
  923. continue;
  924. string real_id = id;
  925. int dot = real_id.IndexOf ('.');
  926. if (dot >= 1)
  927. real_id = real_id.Substring (0, dot);
  928. if (real_id == null || used.ContainsKey (real_id))
  929. continue;
  930. used.Add (real_id, real_id);
  931. Control ctrl = FindControl (real_id);
  932. if (ctrl != null){
  933. IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
  934. IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
  935. if (pbdh == null) {
  936. if (pbeh != null)
  937. RegisterRequiresRaiseEvent (pbeh);
  938. continue;
  939. }
  940. if (pbdh.LoadPostData (real_id, data) == true) {
  941. if (requiresPostDataChanged == null)
  942. requiresPostDataChanged = new ArrayList ();
  943. requiresPostDataChanged.Add (pbdh);
  944. if (_requiresPostBackCopy != null)
  945. _requiresPostBackCopy.Remove (ctrl.UniqueID);
  946. }
  947. } else if (!second) {
  948. if (secondPostData == null)
  949. secondPostData = new NameValueCollection ();
  950. secondPostData.Add (real_id, data [id]);
  951. }
  952. }
  953. ArrayList list1 = null;
  954. if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
  955. string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
  956. foreach (string id in handlers) {
  957. IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
  958. if (pbdh != null) {
  959. _requiresPostBackCopy.Remove (id);
  960. if (pbdh.LoadPostData (id, data)) {
  961. if (requiresPostDataChanged == null)
  962. requiresPostDataChanged = new ArrayList ();
  963. requiresPostDataChanged.Add (pbdh);
  964. }
  965. } else if (second) {
  966. if (list1 == null)
  967. list1 = new ArrayList ();
  968. list1.Add (id);
  969. }
  970. }
  971. }
  972. _requiresPostBack = list1;
  973. }
  974. [EditorBrowsable (EditorBrowsableState.Never)]
  975. #if NET_2_0 || TARGET_JVM
  976. public virtual void ProcessRequest (HttpContext context)
  977. #else
  978. public void ProcessRequest (HttpContext context)
  979. #endif
  980. {
  981. #if NET_2_0
  982. _lifeCycle = PageLifeCycle.Unknown;
  983. #endif
  984. _context = context;
  985. if (clientTarget != null)
  986. Request.ClientTarget = clientTarget;
  987. WireupAutomaticEvents ();
  988. //-- Control execution lifecycle in the docs
  989. // Save culture information because it can be modified in FrameworkInitialize()
  990. CultureInfo culture = Thread.CurrentThread.CurrentCulture;
  991. CultureInfo uiculture = Thread.CurrentThread.CurrentUICulture;
  992. FrameworkInitialize ();
  993. context.ErrorPage = _errorPage;
  994. try {
  995. InternalProcessRequest ();
  996. } catch (ThreadAbortException) {
  997. // Do nothing, just ignore it by now.
  998. } catch (Exception e) {
  999. context.AddError (e); // OnError might access LastError
  1000. OnError (EventArgs.Empty);
  1001. context.ClearError (e);
  1002. // We want to remove that error, as we're rethrowing to stop
  1003. // further processing.
  1004. Trace.Warn ("Unhandled Exception", e.ToString (), e);
  1005. throw;
  1006. } finally {
  1007. try {
  1008. #if NET_2_0
  1009. _lifeCycle = PageLifeCycle.Unload;
  1010. #endif
  1011. RenderTrace ();
  1012. UnloadRecursive (true);
  1013. #if NET_2_0
  1014. _lifeCycle = PageLifeCycle.End;
  1015. #endif
  1016. } catch {}
  1017. if (Thread.CurrentThread.CurrentCulture.Equals (culture) == false)
  1018. Thread.CurrentThread.CurrentCulture = culture;
  1019. if (Thread.CurrentThread.CurrentUICulture.Equals (uiculture) == false)
  1020. Thread.CurrentThread.CurrentUICulture = uiculture;
  1021. }
  1022. }
  1023. #if NET_2_0
  1024. internal void ProcessCrossPagePostBack (HttpContext context)
  1025. {
  1026. isCrossPagePostBack = true;
  1027. ProcessRequest (context);
  1028. }
  1029. #endif
  1030. void InternalProcessRequest ()
  1031. {
  1032. _requestValueCollection = this.DeterminePostBackMode();
  1033. #if NET_2_0
  1034. _lifeCycle = PageLifeCycle.Start;
  1035. // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
  1036. if (_requestValueCollection != null) {
  1037. if (!isCrossPagePostBack && _requestValueCollection [PreviousPageID] != null && _requestValueCollection [PreviousPageID] != Request.FilePath) {
  1038. LoadPreviousPageReference ();
  1039. }
  1040. else {
  1041. isCallback = _requestValueCollection [CallbackArgumentID] != null;
  1042. isPostBack = !isCallback;
  1043. }
  1044. }
  1045. _lifeCycle = PageLifeCycle.PreInit;
  1046. OnPreInit (EventArgs.Empty);
  1047. InitializeTheme ();
  1048. ApplyMasterPage ();
  1049. _lifeCycle = PageLifeCycle.Init;
  1050. #endif
  1051. Trace.Write ("aspx.page", "Begin Init");
  1052. InitRecursive (null);
  1053. Trace.Write ("aspx.page", "End Init");
  1054. #if NET_2_0
  1055. _lifeCycle = PageLifeCycle.InitComplete;
  1056. OnInitComplete (EventArgs.Empty);
  1057. #endif
  1058. renderingForm = false;
  1059. #if NET_2_0
  1060. if (IsPostBack || IsCallback) {
  1061. _lifeCycle = PageLifeCycle.PreLoad;
  1062. if (_requestValueCollection != null)
  1063. scriptManager.RestoreEventValidationState (_requestValueCollection [scriptManager.EventStateFieldName]);
  1064. #else
  1065. if (IsPostBack) {
  1066. #endif
  1067. Trace.Write ("aspx.page", "Begin LoadViewState");
  1068. LoadPageViewState ();
  1069. Trace.Write ("aspx.page", "End LoadViewState");
  1070. Trace.Write ("aspx.page", "Begin ProcessPostData");
  1071. ProcessPostData (_requestValueCollection, false);
  1072. Trace.Write ("aspx.page", "End ProcessPostData");
  1073. }
  1074. #if NET_2_0
  1075. OnPreLoad (EventArgs.Empty);
  1076. _lifeCycle = PageLifeCycle.Load;
  1077. #endif
  1078. LoadRecursive ();
  1079. #if NET_2_0
  1080. if (IsPostBack || IsCallback) {
  1081. _lifeCycle = PageLifeCycle.ControlEvents;
  1082. #else
  1083. if (IsPostBack) {
  1084. #endif
  1085. Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
  1086. ProcessPostData (secondPostData, true);
  1087. Trace.Write ("aspx.page", "End ProcessPostData Second Try");
  1088. Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
  1089. RaiseChangedEvents ();
  1090. Trace.Write ("aspx.page", "End Raise ChangedEvents");
  1091. Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
  1092. RaisePostBackEvents ();
  1093. Trace.Write ("aspx.page", "End Raise PostBackEvent");
  1094. }
  1095. #if NET_2_0
  1096. _lifeCycle = PageLifeCycle.LoadComplete;
  1097. OnLoadComplete (EventArgs.Empty);
  1098. if (IsCrossPagePostBack)
  1099. return;
  1100. if (IsCallback) {
  1101. string result = ProcessCallbackData ();
  1102. HtmlTextWriter callbackOutput = new HtmlTextWriter (_context.Response.Output);
  1103. callbackOutput.Write (result);
  1104. callbackOutput.Flush ();
  1105. return;
  1106. }
  1107. _lifeCycle = PageLifeCycle.PreRender;
  1108. #endif
  1109. Trace.Write ("aspx.page", "Begin PreRender");
  1110. PreRenderRecursiveInternal ();
  1111. Trace.Write ("aspx.page", "End PreRender");
  1112. #if NET_2_0
  1113. OnPreRenderComplete (EventArgs.Empty);
  1114. #endif
  1115. Trace.Write ("aspx.page", "Begin SaveViewState");
  1116. SavePageViewState ();
  1117. Trace.Write ("aspx.page", "End SaveViewState");
  1118. #if NET_2_0
  1119. _lifeCycle = PageLifeCycle.SaveStateComplete;
  1120. OnSaveStateComplete (EventArgs.Empty);
  1121. _lifeCycle = PageLifeCycle.Render;
  1122. #endif
  1123. //--
  1124. Trace.Write ("aspx.page", "Begin Render");
  1125. HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
  1126. RenderControl (output);
  1127. Trace.Write ("aspx.page", "End Render");
  1128. }
  1129. private void RenderTrace ()
  1130. {
  1131. TraceManager traceManager = HttpRuntime.TraceManager;
  1132. if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
  1133. return;
  1134. Trace.SaveData ();
  1135. if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput)
  1136. return;
  1137. if (!traceManager.LocalOnly || Context.Request.IsLocal) {
  1138. HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
  1139. Trace.Render (output);
  1140. }
  1141. }
  1142. #if NET_2_0
  1143. bool CheckForValidationSupport (Control targetControl)
  1144. {
  1145. if (targetControl == null)
  1146. return false;
  1147. Type type = targetControl.GetType ();
  1148. object[] attributes = type.GetCustomAttributes (true);
  1149. foreach (object attr in attributes)
  1150. if (attr is SupportsEventValidationAttribute)
  1151. return true;
  1152. return false;
  1153. }
  1154. #endif
  1155. void RaisePostBackEvents ()
  1156. {
  1157. #if NET_2_0
  1158. Control targetControl;
  1159. #endif
  1160. if (requiresRaiseEvent != null) {
  1161. #if NET_2_0
  1162. targetControl = requiresRaiseEvent as Control;
  1163. if (targetControl != null && CheckForValidationSupport (targetControl))
  1164. scriptManager.ValidateEvent (targetControl.UniqueID, null);
  1165. #endif
  1166. RaisePostBackEvent (requiresRaiseEvent, null);
  1167. return;
  1168. }
  1169. NameValueCollection postdata = _requestValueCollection;
  1170. if (postdata == null)
  1171. return;
  1172. string eventTarget = postdata [postEventSourceID];
  1173. if (eventTarget == null || eventTarget.Length == 0) {
  1174. Validate ();
  1175. return;
  1176. }
  1177. #if NET_2_0
  1178. targetControl = FindControl (eventTarget);
  1179. IPostBackEventHandler target = targetControl as IPostBackEventHandler;
  1180. #else
  1181. IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
  1182. #endif
  1183. if (target == null)
  1184. return;
  1185. string eventArgument = postdata [postEventArgumentID];
  1186. #if NET_2_0
  1187. if (CheckForValidationSupport (targetControl))
  1188. scriptManager.ValidateEvent (targetControl.UniqueID, eventArgument);
  1189. #endif
  1190. RaisePostBackEvent (target, eventArgument);
  1191. }
  1192. internal void RaiseChangedEvents ()
  1193. {
  1194. if (requiresPostDataChanged == null)
  1195. return;
  1196. foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
  1197. ipdh.RaisePostDataChangedEvent ();
  1198. requiresPostDataChanged = null;
  1199. }
  1200. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1201. protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
  1202. {
  1203. sourceControl.RaisePostBackEvent (eventArgument);
  1204. }
  1205. #if NET_2_0
  1206. [Obsolete]
  1207. #endif
  1208. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1209. public void RegisterArrayDeclaration (string arrayName, string arrayValue)
  1210. {
  1211. scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
  1212. }
  1213. #if NET_2_0
  1214. [Obsolete]
  1215. #endif
  1216. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1217. public virtual void RegisterClientScriptBlock (string key, string script)
  1218. {
  1219. scriptManager.RegisterClientScriptBlock (key, script);
  1220. }
  1221. #if NET_2_0
  1222. [Obsolete]
  1223. #endif
  1224. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1225. public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
  1226. {
  1227. scriptManager.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
  1228. }
  1229. [MonoTODO("Used in HtmlForm")]
  1230. internal void RegisterClientScriptFile (string a, string b, string c)
  1231. {
  1232. throw new NotImplementedException ();
  1233. }
  1234. #if NET_2_0
  1235. [Obsolete]
  1236. #endif
  1237. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1238. public void RegisterOnSubmitStatement (string key, string script)
  1239. {
  1240. scriptManager.RegisterOnSubmitStatement (key, script);
  1241. }
  1242. internal string GetSubmitStatements ()
  1243. {
  1244. return scriptManager.WriteSubmitStatements ();
  1245. }
  1246. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1247. public void RegisterRequiresPostBack (Control control)
  1248. {
  1249. if (_requiresPostBack == null)
  1250. _requiresPostBack = new ArrayList ();
  1251. _requiresPostBack.Add (control.UniqueID);
  1252. }
  1253. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1254. public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
  1255. {
  1256. requiresRaiseEvent = control;
  1257. }
  1258. #if NET_2_0
  1259. [Obsolete]
  1260. #endif
  1261. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1262. public virtual void RegisterStartupScript (string key, string script)
  1263. {
  1264. scriptManager.RegisterStartupScript (key, script);
  1265. }
  1266. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1267. public void RegisterViewStateHandler ()
  1268. {
  1269. handleViewState = true;
  1270. }
  1271. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1272. protected virtual void SavePageStateToPersistenceMedium (object viewState)
  1273. {
  1274. _savedViewState = viewState;
  1275. }
  1276. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1277. protected virtual object LoadPageStateFromPersistenceMedium ()
  1278. {
  1279. NameValueCollection postdata = _requestValueCollection;
  1280. string view_state;
  1281. if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
  1282. return null;
  1283. if (view_state == "")
  1284. return null;
  1285. LosFormatter fmt = GetFormatter ();
  1286. try {
  1287. return fmt.Deserialize (view_state);
  1288. } catch (Exception e) {
  1289. throw new HttpException ("Error restoring page viewstate.", e);
  1290. }
  1291. }
  1292. internal void LoadPageViewState()
  1293. {
  1294. object sState = LoadPageStateFromPersistenceMedium ();
  1295. if (sState != null) {
  1296. #if NET_2_0
  1297. Triplet data = (Triplet) sState;
  1298. if (allow_load) {
  1299. LoadPageControlState (data.Third);
  1300. LoadViewStateRecursive (data.First);
  1301. _requiresPostBack = data.Second as ArrayList;
  1302. }
  1303. #else
  1304. Pair pair = (Pair) sState;
  1305. if (allow_load) {
  1306. LoadViewStateRecursive (pair.First);
  1307. _requiresPostBack = pair.Second as ArrayList;
  1308. }
  1309. #endif
  1310. }
  1311. }
  1312. internal void SavePageViewState ()
  1313. {
  1314. if (!handleViewState)
  1315. return;
  1316. #if NET_2_0
  1317. object controlState = SavePageControlState ();
  1318. #endif
  1319. object viewState = SaveViewStateRecursive ();
  1320. object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
  1321. #if NET_2_0
  1322. Triplet triplet = new Triplet ();
  1323. triplet.First = viewState;
  1324. triplet.Second = reqPostback;
  1325. triplet.Third = controlState;
  1326. if (triplet.First == null && triplet.Second == null && triplet.Third == null)
  1327. triplet = null;
  1328. SavePageStateToPersistenceMedium (triplet);
  1329. #else
  1330. Pair pair = new Pair ();
  1331. pair.First = viewState;
  1332. pair.Second = reqPostback;
  1333. if (pair.First == null && pair.Second == null)
  1334. pair = null;
  1335. SavePageStateToPersistenceMedium (pair);
  1336. #endif
  1337. }
  1338. public virtual void Validate ()
  1339. {
  1340. is_validated = true;
  1341. ValidateCollection (_validators);
  1342. }
  1343. #if NET_2_0
  1344. internal bool AreValidatorsUplevel () {
  1345. return AreValidatorsUplevel (String.Empty);
  1346. }
  1347. internal bool AreValidatorsUplevel (string valGroup)
  1348. #else
  1349. internal virtual bool AreValidatorsUplevel ()
  1350. #endif
  1351. {
  1352. bool uplevel = false;
  1353. foreach (IValidator v in Validators) {
  1354. BaseValidator bv = v as BaseValidator;
  1355. if (bv == null) continue;
  1356. #if NET_2_0
  1357. if (valGroup != bv.ValidationGroup)
  1358. continue;
  1359. #endif
  1360. if (bv.GetRenderUplevel()) {
  1361. uplevel = true;
  1362. break;
  1363. }
  1364. }
  1365. return uplevel;
  1366. }
  1367. bool ValidateCollection (ValidatorCollection validators)
  1368. {
  1369. #if NET_2_0
  1370. if (!_eventValidation)
  1371. return true;
  1372. #endif
  1373. if (validators == null || validators.Count == 0)
  1374. return true;
  1375. bool all_valid = true;
  1376. foreach (IValidator v in validators){
  1377. v.Validate ();
  1378. if (v.IsValid == false)
  1379. all_valid = false;
  1380. }
  1381. return all_valid;
  1382. }
  1383. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1384. public virtual void VerifyRenderingInServerForm (Control control)
  1385. {
  1386. if (_context == null)
  1387. return;
  1388. if (!renderingForm)
  1389. throw new HttpException ("Control '" +
  1390. control.ClientID +
  1391. "' of type '" +
  1392. control.GetType ().Name +
  1393. "' must be placed inside a form tag with runat=server.");
  1394. }
  1395. protected override void FrameworkInitialize ()
  1396. {
  1397. base.FrameworkInitialize ();
  1398. #if NET_2_0
  1399. InitializeStyleSheet ();
  1400. #endif
  1401. }
  1402. #endregion
  1403. #if NET_2_0
  1404. public
  1405. #else
  1406. internal
  1407. #endif
  1408. ClientScriptManager ClientScript {
  1409. get { return scriptManager; }
  1410. }
  1411. #if NET_2_0
  1412. static readonly object InitCompleteEvent = new object ();
  1413. static readonly object LoadCompleteEvent = new object ();
  1414. static readonly object PreInitEvent = new object ();
  1415. static readonly object PreLoadEvent = new object ();
  1416. static readonly object PreRenderCompleteEvent = new object ();
  1417. static readonly object SaveStateCompleteEvent = new object ();
  1418. int event_mask;
  1419. const int initcomplete_mask = 1;
  1420. const int loadcomplete_mask = 1 << 1;
  1421. const int preinit_mask = 1 << 2;
  1422. const int preload_mask = 1 << 3;
  1423. const int prerendercomplete_mask = 1 << 4;
  1424. const int savestatecomplete_mask = 1 << 5;
  1425. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1426. public event EventHandler InitComplete {
  1427. add {
  1428. event_mask |= initcomplete_mask;
  1429. Events.AddHandler (InitCompleteEvent, value);
  1430. }
  1431. remove { Events.RemoveHandler (InitCompleteEvent, value); }
  1432. }
  1433. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1434. public event EventHandler LoadComplete {
  1435. add {
  1436. event_mask |= loadcomplete_mask;
  1437. Events.AddHandler (LoadCompleteEvent, value);
  1438. }
  1439. remove { Events.RemoveHandler (LoadCompleteEvent, value); }
  1440. }
  1441. public event EventHandler PreInit {
  1442. add {
  1443. event_mask |= preinit_mask;
  1444. Events.AddHandler (PreInitEvent, value);
  1445. }
  1446. remove { Events.RemoveHandler (PreInitEvent, value); }
  1447. }
  1448. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1449. public event EventHandler PreLoad {
  1450. add {
  1451. event_mask |= preload_mask;
  1452. Events.AddHandler (PreLoadEvent, value);
  1453. }
  1454. remove { Events.RemoveHandler (PreLoadEvent, value); }
  1455. }
  1456. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1457. public event EventHandler PreRenderComplete {
  1458. add {
  1459. event_mask |= prerendercomplete_mask;
  1460. Events.AddHandler (PreRenderCompleteEvent, value);
  1461. }
  1462. remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
  1463. }
  1464. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1465. public event EventHandler SaveStateComplete {
  1466. add {
  1467. event_mask |= savestatecomplete_mask;
  1468. Events.AddHandler (SaveStateCompleteEvent, value);
  1469. }
  1470. remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
  1471. }
  1472. protected virtual void OnInitComplete (EventArgs e)
  1473. {
  1474. if ((event_mask & initcomplete_mask) != 0) {
  1475. EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
  1476. if (eh != null) eh (this, e);
  1477. }
  1478. }
  1479. protected virtual void OnLoadComplete (EventArgs e)
  1480. {
  1481. if ((event_mask & loadcomplete_mask) != 0) {
  1482. EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
  1483. if (eh != null) eh (this, e);
  1484. }
  1485. }
  1486. protected virtual void OnPreInit (EventArgs e)
  1487. {
  1488. if ((event_mask & preinit_mask) != 0) {
  1489. EventHandler eh = (EventHandler) (Events [PreInitEvent]);
  1490. if (eh != null) eh (this, e);
  1491. }
  1492. }
  1493. protected virtual void OnPreLoad (EventArgs e)
  1494. {
  1495. if ((event_mask & preload_mask) != 0) {
  1496. EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
  1497. if (eh != null) eh (this, e);
  1498. }
  1499. }
  1500. protected virtual void OnPreRenderComplete (EventArgs e)
  1501. {
  1502. if ((event_mask & prerendercomplete_mask) != 0) {
  1503. EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
  1504. if (eh != null) eh (this, e);
  1505. }
  1506. }
  1507. protected virtual void OnSaveStateComplete (EventArgs e)
  1508. {
  1509. if ((event_mask & savestatecomplete_mask) != 0) {
  1510. EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
  1511. if (eh != null) eh (this, e);
  1512. }
  1513. }
  1514. public HtmlForm Form {
  1515. get { return _form; }
  1516. }
  1517. internal void RegisterForm (HtmlForm form)
  1518. {
  1519. _form = form;
  1520. }
  1521. [BrowsableAttribute (false)]
  1522. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1523. public Page PreviousPage {
  1524. get { return previousPage; }
  1525. }
  1526. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1527. [BrowsableAttribute (false)]
  1528. public bool IsCallback {
  1529. get { return isCallback; }
  1530. }
  1531. [BrowsableAttribute (false)]
  1532. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1533. public bool IsCrossPagePostBack {
  1534. get { return isCrossPagePostBack; }
  1535. }
  1536. string ProcessCallbackData ()
  1537. {
  1538. string callbackTarget = _requestValueCollection [CallbackSourceID];
  1539. if (callbackTarget == null || callbackTarget.Length == 0)
  1540. throw new HttpException ("Callback target not provided.");
  1541. Control targetControl = FindControl (callbackTarget);
  1542. ICallbackEventHandler target = targetControl as ICallbackEventHandler;
  1543. if (target == null)
  1544. throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
  1545. string callbackArgument = _requestValueCollection [CallbackArgumentID];
  1546. if (CheckForValidationSupport (targetControl))
  1547. scriptManager.ValidateEvent (targetControl.UniqueID, callbackArgument);
  1548. target.RaiseCallbackEvent (callbackArgument);
  1549. return target.GetCallbackResult ();
  1550. }
  1551. [BrowsableAttribute (false)]
  1552. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1553. public HtmlHead Header {
  1554. get { return htmlHeader; }
  1555. }
  1556. internal void SetHeader (HtmlHead header)
  1557. {
  1558. htmlHeader = header;
  1559. if (_title != null) {
  1560. htmlHeader.Title = _title;
  1561. _title = null;
  1562. }
  1563. }
  1564. void ApplyMasterPage ()
  1565. {
  1566. if (masterPageFile != null && masterPageFile.Length > 0) {
  1567. ArrayList appliedMasterPageFiles = new ArrayList ();
  1568. if (Master != null) {
  1569. MasterPage.ApplyMasterPageRecursive (Master, appliedMasterPageFiles);
  1570. Master.Page = this;
  1571. Controls.Clear ();
  1572. Controls.Add (Master);
  1573. }
  1574. }
  1575. }
  1576. [DefaultValueAttribute ("")]
  1577. public virtual string MasterPageFile {
  1578. get { return masterPageFile; }
  1579. set {
  1580. masterPageFile = value;
  1581. masterPage = null;
  1582. }
  1583. }
  1584. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1585. [BrowsableAttribute (false)]
  1586. public MasterPage Master {
  1587. get {
  1588. if (masterPage == null)
  1589. masterPage = MasterPage.CreateMasterPage (this, Context, masterPageFile, contentTemplates);
  1590. return masterPage;
  1591. }
  1592. }
  1593. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1594. public void RegisterRequiresControlState (Control control)
  1595. {
  1596. if (control == null)
  1597. throw new ArgumentNullException ("control");
  1598. if (RequiresControlState (control))
  1599. return;
  1600. if (requireStateControls == null)
  1601. requireStateControls = new ArrayList ();
  1602. int n = requireStateControls.Add (control);
  1603. if (_savedControlState != null && n < _savedControlState.Length) {
  1604. object state = _savedControlState [n];
  1605. if (state != null)
  1606. control.LoadControlState (state);
  1607. }
  1608. }
  1609. public bool RequiresControlState (Control control)
  1610. {
  1611. if (requireStateControls == null) return false;
  1612. return requireStateControls.Contains (control);
  1613. }
  1614. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1615. public void UnregisterRequiresControlState (Control control)
  1616. {
  1617. if (requireStateControls != null)
  1618. requireStateControls.Remove (control);
  1619. }
  1620. public ValidatorCollection GetValidators (string validationGroup)
  1621. {
  1622. string valgr = validationGroup;
  1623. if (valgr == null)
  1624. valgr = String.Empty;
  1625. if (_validatorsByGroup == null) _validatorsByGroup = new Hashtable ();
  1626. ValidatorCollection col = _validatorsByGroup [valgr] as ValidatorCollection;
  1627. if (col == null) {
  1628. col = new ValidatorCollection ();
  1629. _validatorsByGroup [valgr] = col;
  1630. }
  1631. return col;
  1632. }
  1633. public virtual void Validate (string validationGroup)
  1634. {
  1635. is_validated = true;
  1636. if (validationGroup == null)
  1637. ValidateCollection (_validatorsByGroup [String.Empty] as ValidatorCollection);
  1638. else if (_validatorsByGroup != null) {
  1639. ValidateCollection (_validatorsByGroup [validationGroup] as ValidatorCollection);
  1640. }
  1641. }
  1642. object SavePageControlState ()
  1643. {
  1644. if (requireStateControls == null) return null;
  1645. object[] state = new object [requireStateControls.Count];
  1646. bool allNull = true;
  1647. for (int n=0; n<state.Length; n++) {
  1648. state [n] = ((Control) requireStateControls [n]).SaveControlState ();
  1649. if (state [n] != null) allNull = false;
  1650. }
  1651. if (allNull) return null;
  1652. else return state;
  1653. }
  1654. void LoadPageControlState (object data)
  1655. {
  1656. _savedControlState = (object []) data;
  1657. if (requireStateControls == null) return;
  1658. int max = Math.Min (requireStateControls.Count, _savedControlState != null ? _savedControlState.Length : requireStateControls.Count);
  1659. for (int n=0; n < max; n++) {
  1660. Control ctl = (Control) requireStateControls [n];
  1661. ctl.LoadControlState (_savedControlState != null ? _savedControlState [n] : null);
  1662. }
  1663. }
  1664. void LoadPreviousPageReference ()
  1665. {
  1666. if (_requestValueCollection != null) {
  1667. string prevPage = _requestValueCollection [PreviousPageID];
  1668. if (prevPage != null) {
  1669. previousPage = (Page) PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
  1670. previousPage.ProcessCrossPagePostBack (_context);
  1671. } else {
  1672. previousPage = _context.LastPage;
  1673. }
  1674. }
  1675. _context.LastPage = this;
  1676. }
  1677. Hashtable contentTemplates;
  1678. [EditorBrowsable (EditorBrowsableState.Never)]
  1679. protected internal void AddContentTemplate (string templateName, ITemplate template)
  1680. {
  1681. if (contentTemplates == null)
  1682. contentTemplates = new Hashtable ();
  1683. contentTemplates [templateName] = template;
  1684. }
  1685. PageTheme _pageTheme;
  1686. internal PageTheme PageTheme {
  1687. get { return _pageTheme; }
  1688. }
  1689. PageTheme _styleSheetPageTheme;
  1690. internal PageTheme StyleSheetPageTheme {
  1691. get { return _styleSheetPageTheme; }
  1692. }
  1693. Stack dataItemCtx;
  1694. internal void PushDataItemContext (object o) {
  1695. if (dataItemCtx == null)
  1696. dataItemCtx = new Stack ();
  1697. dataItemCtx.Push (o);
  1698. }
  1699. internal void PopDataItemContext () {
  1700. if (dataItemCtx == null)
  1701. throw new InvalidOperationException ();
  1702. dataItemCtx.Pop ();
  1703. }
  1704. public object GetDataItem() {
  1705. if (dataItemCtx == null || dataItemCtx.Count == 0)
  1706. throw new InvalidOperationException ("No data item");
  1707. return dataItemCtx.Peek ();
  1708. }
  1709. protected internal override void OnInit (EventArgs e)
  1710. {
  1711. base.OnInit (e);
  1712. if (Header == null)
  1713. return;
  1714. ArrayList themes = new ArrayList();
  1715. if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
  1716. themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
  1717. if (PageTheme != null && PageTheme.GetStyleSheets () != null)
  1718. themes.AddRange (PageTheme.GetStyleSheets ());
  1719. foreach (string lss in themes) {
  1720. HtmlLink hl = new HtmlLink ();
  1721. hl.Href = ResolveUrl (lss);
  1722. hl.Attributes["type"] = "text/css";
  1723. hl.Attributes["rel"] = "stylesheet";
  1724. Header.Controls.Add (hl);
  1725. }
  1726. }
  1727. #endif
  1728. #if NET_2_0
  1729. [MonoTODO ("Used by .net aspx parser")]
  1730. protected object GetWrappedFileDependencies (string [] list)
  1731. {
  1732. return null;
  1733. }
  1734. [MonoTODO ("Used by .net aspx parser")]
  1735. protected virtual void InitializeCulture ()
  1736. {
  1737. }
  1738. [MonoTODO ("Used by .net aspx parser")]
  1739. protected internal void AddWrappedFileDependencies (object virtualFileDependencies)
  1740. {
  1741. }
  1742. #endif
  1743. }
  1744. }