Page.cs 57 KB

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