Page.cs 69 KB

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