Page.cs 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218
  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 PostBackFunctionName {
  404. get {
  405. return "__doPostBack";
  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. WebROCollection c = (WebROCollection) coll;
  687. allow_load = !c.GotID;
  688. if (allow_load) {
  689. c.ID = GetTypeHashCode ();
  690. } else {
  691. allow_load = (c.ID == GetTypeHashCode ());
  692. }
  693. } else {
  694. coll = req.QueryString;
  695. }
  696. #if TARGET_J2EE
  697. coll = LoadViewStateForPortlet((WebROCollection)coll);
  698. #endif
  699. if (coll != null && coll ["__VIEWSTATE"] == null && coll ["__EVENTTARGET"] == null)
  700. return null;
  701. return coll;
  702. }
  703. #if NET_2_0
  704. public override Control FindControl (string id) {
  705. if (id == ID)
  706. return this;
  707. else
  708. return base.FindControl (id);
  709. }
  710. #endif
  711. #if NET_2_0
  712. [Obsolete]
  713. #endif
  714. [EditorBrowsable (EditorBrowsableState.Advanced)]
  715. public string GetPostBackClientEvent (Control control, string argument)
  716. {
  717. return scriptManager.GetPostBackEventReference (control, argument);
  718. }
  719. #if NET_2_0
  720. [Obsolete]
  721. #endif
  722. [EditorBrowsable (EditorBrowsableState.Advanced)]
  723. public string GetPostBackClientHyperlink (Control control, string argument)
  724. {
  725. return scriptManager.GetPostBackClientHyperlink (control, argument);
  726. }
  727. #if NET_2_0
  728. [Obsolete]
  729. #endif
  730. [EditorBrowsable (EditorBrowsableState.Advanced)]
  731. public string GetPostBackEventReference (Control control)
  732. {
  733. return scriptManager.GetPostBackEventReference (control, "");
  734. }
  735. #if NET_2_0
  736. [Obsolete]
  737. #endif
  738. [EditorBrowsable (EditorBrowsableState.Advanced)]
  739. public string GetPostBackEventReference (Control control, string argument)
  740. {
  741. return scriptManager.GetPostBackEventReference (control, argument);
  742. }
  743. internal void RequiresPostBackScript ()
  744. {
  745. requiresPostBackScript = true;
  746. }
  747. [EditorBrowsable (EditorBrowsableState.Never)]
  748. public virtual int GetTypeHashCode ()
  749. {
  750. return 0;
  751. }
  752. #if NET_2_0
  753. [MonoTODO("The following properties of OutputCacheParameters are silently ignored: CacheProfile, NoStore, SqlDependency")]
  754. protected internal virtual void InitOutputCache(OutputCacheParameters cacheSettings)
  755. {
  756. if (cacheSettings.Enabled)
  757. InitOutputCache(cacheSettings.Duration,
  758. cacheSettings.VaryByHeader,
  759. cacheSettings.VaryByCustom,
  760. cacheSettings.Location,
  761. cacheSettings.VaryByParam);
  762. }
  763. #endif
  764. [EditorBrowsable (EditorBrowsableState.Never)]
  765. protected virtual void InitOutputCache (int duration,
  766. string varyByHeader,
  767. string varyByCustom,
  768. OutputCacheLocation location,
  769. string varyByParam)
  770. {
  771. HttpCachePolicy cache = _context.Response.Cache;
  772. bool set_vary = false;
  773. switch (location) {
  774. case OutputCacheLocation.Any:
  775. cache.SetCacheability (HttpCacheability.Public);
  776. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  777. cache.SetLastModified (_context.Timestamp);
  778. set_vary = true;
  779. break;
  780. case OutputCacheLocation.Client:
  781. cache.SetCacheability (HttpCacheability.Private);
  782. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  783. cache.SetLastModified (_context.Timestamp);
  784. break;
  785. case OutputCacheLocation.Downstream:
  786. cache.SetCacheability (HttpCacheability.Public);
  787. cache.SetMaxAge (new TimeSpan (0, 0, duration));
  788. cache.SetLastModified (_context.Timestamp);
  789. break;
  790. case OutputCacheLocation.Server:
  791. cache.SetCacheability (HttpCacheability.Server);
  792. set_vary = true;
  793. break;
  794. case OutputCacheLocation.None:
  795. break;
  796. }
  797. if (set_vary) {
  798. if (varyByCustom != null)
  799. cache.SetVaryByCustom (varyByCustom);
  800. if (varyByParam != null && varyByParam.Length > 0) {
  801. string[] prms = varyByParam.Split (';');
  802. foreach (string p in prms)
  803. cache.VaryByParams [p.Trim ()] = true;
  804. cache.VaryByParams.IgnoreParams = false;
  805. } else {
  806. cache.VaryByParams.IgnoreParams = true;
  807. }
  808. if (varyByHeader != null && varyByHeader.Length > 0) {
  809. string[] hdrs = varyByHeader.Split (';');
  810. foreach (string h in hdrs)
  811. cache.VaryByHeaders [h.Trim ()] = true;
  812. }
  813. }
  814. cache.Duration = duration;
  815. cache.SetExpires (_context.Timestamp.AddSeconds (duration));
  816. }
  817. #if NET_2_0
  818. [Obsolete]
  819. #else
  820. [EditorBrowsable (EditorBrowsableState.Advanced)]
  821. #endif
  822. public bool IsClientScriptBlockRegistered (string key)
  823. {
  824. return scriptManager.IsClientScriptBlockRegistered (key);
  825. }
  826. #if NET_2_0
  827. [Obsolete]
  828. #else
  829. [EditorBrowsable (EditorBrowsableState.Advanced)]
  830. #endif
  831. public bool IsStartupScriptRegistered (string key)
  832. {
  833. return scriptManager.IsStartupScriptRegistered (key);
  834. }
  835. public string MapPath (string virtualPath)
  836. {
  837. return Request.MapPath (virtualPath);
  838. }
  839. #if NET_2_0
  840. protected internal override void Render (HtmlTextWriter writer) {
  841. if (MaintainScrollPositionOnPostBack) {
  842. RequiresPostBackScript ();
  843. string scriptUrl = ClientScript.GetWebResourceUrl (typeof (Page), "MaintainScrollPositionOnPostBack.js");
  844. ClientScript.RegisterClientScriptInclude (typeof (Page), "MaintainScrollPositionOnPostBack.js", scriptUrl);
  845. ClientScript.RegisterHiddenField (ScrollPositionXID, Request [ScrollPositionXID]);
  846. ClientScript.RegisterHiddenField (ScrollPositionYID, Request [ScrollPositionYID]);
  847. StringBuilder script = new StringBuilder ();
  848. script.AppendLine ("<script type=\"text/javascript\">");
  849. script.AppendLine ("<!--");
  850. script.AppendLine ("theForm.oldSubmit = theForm.submit");
  851. script.AppendLine ("theForm.submit = WebForm_SaveScrollPositionSubmit");
  852. script.AppendLine ("theForm.oldOnSubmit = theForm.onsubmit");
  853. script.AppendLine ("theForm.onsubmit = WebForm_SaveScrollPositionOnSubmit");
  854. if (IsPostBack) {
  855. script.AppendLine ("theForm.oldOnLoad = window.onload");
  856. script.AppendLine ("window.onload = WebForm_RestoreScrollPosition");
  857. }
  858. script.AppendLine ("// -->");
  859. script.AppendLine ("</script>");
  860. ClientScript.RegisterStartupScript (typeof (Page), "MaintainScrollPositionOnPostBackStartup", script.ToString());
  861. }
  862. base.Render (writer);
  863. }
  864. #endif
  865. private void RenderPostBackScript (HtmlTextWriter writer, string formUniqueID)
  866. {
  867. writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventSourceID);
  868. writer.WriteLine ("<input type=\"hidden\" name=\"{0}\" value=\"\" />", postEventArgumentID);
  869. writer.WriteLine ();
  870. writer.WriteLine ("<script language=\"javascript\">");
  871. writer.WriteLine ("<!--");
  872. writer.WriteLine ("\tvar theForm;\n\tif (document.getElementById) {{ theForm = document.getElementById ('{0}'); }}", formUniqueID);
  873. writer.WriteLine ("\telse {{ theForm = document.{0}; }}", formUniqueID);
  874. writer.WriteLine ("\tfunction " + PostBackFunctionName + "(eventTarget, eventArgument) {");
  875. writer.WriteLine ("\t\tif(document.ValidatorOnSubmit && !ValidatorOnSubmit()) return;");
  876. writer.WriteLine ("\t\ttheForm.{0}.value = eventTarget;", postEventSourceID);
  877. writer.WriteLine ("\t\ttheForm.{0}.value = eventArgument;", postEventArgumentID);
  878. writer.WriteLine ("\t\ttheForm.submit();");
  879. writer.WriteLine ("\t}");
  880. writer.WriteLine ("// -->");
  881. writer.WriteLine ("</script>");
  882. }
  883. internal void OnFormRender (HtmlTextWriter writer, string formUniqueID)
  884. {
  885. if (renderingForm)
  886. throw new HttpException ("Only 1 HtmlForm is allowed per page.");
  887. renderingForm = true;
  888. writer.WriteLine ();
  889. if (handleViewState)
  890. scriptManager.RegisterHiddenField ("__VIEWSTATE", _savedViewState);
  891. scriptManager.WriteHiddenFields (writer);
  892. if (requiresPostBackScript) {
  893. RenderPostBackScript (writer, formUniqueID);
  894. postBackScriptRendered = true;
  895. }
  896. scriptManager.WriteClientScriptIncludes (writer);
  897. scriptManager.WriteClientScriptBlocks (writer);
  898. }
  899. internal IStateFormatter GetFormatter ()
  900. {
  901. return new ObjectStateFormatter (this);
  902. }
  903. internal string GetSavedViewState ()
  904. {
  905. return _savedViewState;
  906. }
  907. internal void OnFormPostRender (HtmlTextWriter writer, string formUniqueID)
  908. {
  909. scriptManager.WriteArrayDeclares (writer);
  910. if (!postBackScriptRendered && requiresPostBackScript)
  911. RenderPostBackScript (writer, formUniqueID);
  912. #if NET_2_0
  913. scriptManager.SaveEventValidationState ();
  914. scriptManager.WriteExpandoAttributes (writer);
  915. #endif
  916. scriptManager.WriteHiddenFields (writer);
  917. scriptManager.WriteStartupScriptBlocks (writer);
  918. renderingForm = false;
  919. postBackScriptRendered = false;
  920. }
  921. private void ProcessPostData (NameValueCollection data, bool second)
  922. {
  923. if (data != null) {
  924. Hashtable used = new Hashtable ();
  925. foreach (string id in data.AllKeys){
  926. if (id == "__VIEWSTATE" || id == postEventSourceID || id == postEventArgumentID)
  927. continue;
  928. string real_id = id;
  929. int dot = real_id.IndexOf ('.');
  930. if (dot >= 1)
  931. real_id = real_id.Substring (0, dot);
  932. if (real_id == null || used.ContainsKey (real_id))
  933. continue;
  934. used.Add (real_id, real_id);
  935. Control ctrl = FindControl (real_id);
  936. if (ctrl != null){
  937. IPostBackDataHandler pbdh = ctrl as IPostBackDataHandler;
  938. IPostBackEventHandler pbeh = ctrl as IPostBackEventHandler;
  939. if (pbdh == null) {
  940. if (pbeh != null)
  941. RegisterRequiresRaiseEvent (pbeh);
  942. continue;
  943. }
  944. if (pbdh.LoadPostData (real_id, data) == true) {
  945. if (requiresPostDataChanged == null)
  946. requiresPostDataChanged = new ArrayList ();
  947. requiresPostDataChanged.Add (pbdh);
  948. }
  949. if (_requiresPostBackCopy != null)
  950. _requiresPostBackCopy.Remove (real_id);
  951. } else if (!second) {
  952. if (secondPostData == null)
  953. secondPostData = new NameValueCollection ();
  954. secondPostData.Add (real_id, data [id]);
  955. }
  956. }
  957. }
  958. ArrayList list1 = null;
  959. if (_requiresPostBackCopy != null && _requiresPostBackCopy.Count > 0) {
  960. string [] handlers = (string []) _requiresPostBackCopy.ToArray (typeof (string));
  961. foreach (string id in handlers) {
  962. IPostBackDataHandler pbdh = FindControl (id) as IPostBackDataHandler;
  963. if (pbdh != null) {
  964. _requiresPostBackCopy.Remove (id);
  965. if (pbdh.LoadPostData (id, data)) {
  966. if (requiresPostDataChanged == null)
  967. requiresPostDataChanged = new ArrayList ();
  968. requiresPostDataChanged.Add (pbdh);
  969. }
  970. } else if (!second) {
  971. if (list1 == null)
  972. list1 = new ArrayList ();
  973. list1.Add (id);
  974. }
  975. }
  976. }
  977. _requiresPostBackCopy = second ? null : list1;
  978. if (second)
  979. secondPostData = null;
  980. }
  981. [EditorBrowsable (EditorBrowsableState.Never)]
  982. #if NET_2_0 || TARGET_JVM
  983. public virtual void ProcessRequest (HttpContext context)
  984. #else
  985. public void ProcessRequest (HttpContext context)
  986. #endif
  987. {
  988. #if NET_2_0
  989. _lifeCycle = PageLifeCycle.Unknown;
  990. #endif
  991. _context = context;
  992. if (clientTarget != null)
  993. Request.ClientTarget = clientTarget;
  994. WireupAutomaticEvents ();
  995. //-- Control execution lifecycle in the docs
  996. // Save culture information because it can be modified in FrameworkInitialize()
  997. CultureInfo culture = Thread.CurrentThread.CurrentCulture;
  998. CultureInfo uiculture = Thread.CurrentThread.CurrentUICulture;
  999. FrameworkInitialize ();
  1000. context.ErrorPage = _errorPage;
  1001. try {
  1002. InternalProcessRequest ();
  1003. } catch (ThreadAbortException) {
  1004. // Do nothing, just ignore it by now.
  1005. } catch (Exception e) {
  1006. context.AddError (e); // OnError might access LastError
  1007. OnError (EventArgs.Empty);
  1008. context.ClearError (e);
  1009. // We want to remove that error, as we're rethrowing to stop
  1010. // further processing.
  1011. Trace.Warn ("Unhandled Exception", e.ToString (), e);
  1012. throw;
  1013. } finally {
  1014. try {
  1015. #if NET_2_0
  1016. _lifeCycle = PageLifeCycle.Unload;
  1017. #endif
  1018. RenderTrace ();
  1019. UnloadRecursive (true);
  1020. #if NET_2_0
  1021. _lifeCycle = PageLifeCycle.End;
  1022. #endif
  1023. } catch {}
  1024. if (Thread.CurrentThread.CurrentCulture.Equals (culture) == false)
  1025. Thread.CurrentThread.CurrentCulture = culture;
  1026. if (Thread.CurrentThread.CurrentUICulture.Equals (uiculture) == false)
  1027. Thread.CurrentThread.CurrentUICulture = uiculture;
  1028. }
  1029. }
  1030. #if NET_2_0
  1031. internal void ProcessCrossPagePostBack (HttpContext context)
  1032. {
  1033. isCrossPagePostBack = true;
  1034. ProcessRequest (context);
  1035. }
  1036. #endif
  1037. void InternalProcessRequest ()
  1038. {
  1039. _requestValueCollection = this.DeterminePostBackMode();
  1040. #if NET_2_0
  1041. _lifeCycle = PageLifeCycle.Start;
  1042. // http://msdn2.microsoft.com/en-us/library/ms178141.aspx
  1043. if (_requestValueCollection != null) {
  1044. if (!isCrossPagePostBack && _requestValueCollection [PreviousPageID] != null && _requestValueCollection [PreviousPageID] != Request.FilePath) {
  1045. _doLoadPreviousPage = true;
  1046. }
  1047. else {
  1048. isCallback = _requestValueCollection [CallbackArgumentID] != null;
  1049. isPostBack = !isCallback;
  1050. }
  1051. }
  1052. // if request was transfered from other page - track Prev. Page
  1053. previousPage = _context.LastPage;
  1054. _context.LastPage = this;
  1055. _lifeCycle = PageLifeCycle.PreInit;
  1056. OnPreInit (EventArgs.Empty);
  1057. InitializeTheme ();
  1058. ApplyMasterPage ();
  1059. _lifeCycle = PageLifeCycle.Init;
  1060. #endif
  1061. Trace.Write ("aspx.page", "Begin Init");
  1062. InitRecursive (null);
  1063. Trace.Write ("aspx.page", "End Init");
  1064. #if NET_2_0
  1065. _lifeCycle = PageLifeCycle.InitComplete;
  1066. OnInitComplete (EventArgs.Empty);
  1067. #endif
  1068. renderingForm = false;
  1069. #if NET_2_0
  1070. if (IsPostBack || IsCallback) {
  1071. _lifeCycle = PageLifeCycle.PreLoad;
  1072. if (_requestValueCollection != null)
  1073. scriptManager.RestoreEventValidationState (_requestValueCollection [scriptManager.EventStateFieldName]);
  1074. #else
  1075. if (IsPostBack) {
  1076. #endif
  1077. Trace.Write ("aspx.page", "Begin LoadViewState");
  1078. LoadPageViewState ();
  1079. Trace.Write ("aspx.page", "End LoadViewState");
  1080. Trace.Write ("aspx.page", "Begin ProcessPostData");
  1081. ProcessPostData (_requestValueCollection, false);
  1082. Trace.Write ("aspx.page", "End ProcessPostData");
  1083. }
  1084. #if NET_2_0
  1085. OnPreLoad (EventArgs.Empty);
  1086. _lifeCycle = PageLifeCycle.Load;
  1087. #endif
  1088. LoadRecursive ();
  1089. #if NET_2_0
  1090. if (IsPostBack || IsCallback) {
  1091. _lifeCycle = PageLifeCycle.ControlEvents;
  1092. #else
  1093. if (IsPostBack) {
  1094. #endif
  1095. Trace.Write ("aspx.page", "Begin ProcessPostData Second Try");
  1096. ProcessPostData (secondPostData, true);
  1097. Trace.Write ("aspx.page", "End ProcessPostData Second Try");
  1098. Trace.Write ("aspx.page", "Begin Raise ChangedEvents");
  1099. RaiseChangedEvents ();
  1100. Trace.Write ("aspx.page", "End Raise ChangedEvents");
  1101. Trace.Write ("aspx.page", "Begin Raise PostBackEvent");
  1102. RaisePostBackEvents ();
  1103. Trace.Write ("aspx.page", "End Raise PostBackEvent");
  1104. }
  1105. #if NET_2_0
  1106. _lifeCycle = PageLifeCycle.LoadComplete;
  1107. OnLoadComplete (EventArgs.Empty);
  1108. if (IsCrossPagePostBack)
  1109. return;
  1110. if (IsCallback) {
  1111. string result = ProcessCallbackData ();
  1112. HtmlTextWriter callbackOutput = new HtmlTextWriter (_context.Response.Output);
  1113. callbackOutput.Write (result);
  1114. callbackOutput.Flush ();
  1115. return;
  1116. }
  1117. _lifeCycle = PageLifeCycle.PreRender;
  1118. #endif
  1119. Trace.Write ("aspx.page", "Begin PreRender");
  1120. PreRenderRecursiveInternal ();
  1121. Trace.Write ("aspx.page", "End PreRender");
  1122. #if NET_2_0
  1123. _lifeCycle = PageLifeCycle.PreRenderComplete;
  1124. OnPreRenderComplete (EventArgs.Empty);
  1125. #endif
  1126. Trace.Write ("aspx.page", "Begin SaveViewState");
  1127. SavePageViewState ();
  1128. Trace.Write ("aspx.page", "End SaveViewState");
  1129. #if NET_2_0
  1130. _lifeCycle = PageLifeCycle.SaveStateComplete;
  1131. OnSaveStateComplete (EventArgs.Empty);
  1132. #endif
  1133. #if TARGET_J2EE
  1134. if (SaveViewStateForNextPortletRender())
  1135. return;
  1136. #endif
  1137. #if NET_2_0
  1138. _lifeCycle = PageLifeCycle.Render;
  1139. #endif
  1140. //--
  1141. Trace.Write ("aspx.page", "Begin Render");
  1142. HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
  1143. RenderControl (output);
  1144. Trace.Write ("aspx.page", "End Render");
  1145. }
  1146. private void RenderTrace ()
  1147. {
  1148. TraceManager traceManager = HttpRuntime.TraceManager;
  1149. if (Trace.HaveTrace && !Trace.IsEnabled || !Trace.HaveTrace && !traceManager.Enabled)
  1150. return;
  1151. Trace.SaveData ();
  1152. if (!Trace.HaveTrace && traceManager.Enabled && !traceManager.PageOutput)
  1153. return;
  1154. if (!traceManager.LocalOnly || Context.Request.IsLocal) {
  1155. HtmlTextWriter output = new HtmlTextWriter (_context.Response.Output);
  1156. Trace.Render (output);
  1157. }
  1158. }
  1159. #if NET_2_0
  1160. bool CheckForValidationSupport (Control targetControl)
  1161. {
  1162. if (targetControl == null)
  1163. return false;
  1164. Type type = targetControl.GetType ();
  1165. object[] attributes = type.GetCustomAttributes (true);
  1166. foreach (object attr in attributes)
  1167. if (attr is SupportsEventValidationAttribute)
  1168. return true;
  1169. return false;
  1170. }
  1171. #endif
  1172. void RaisePostBackEvents ()
  1173. {
  1174. #if NET_2_0
  1175. Control targetControl;
  1176. #endif
  1177. if (requiresRaiseEvent != null) {
  1178. #if NET_2_0
  1179. targetControl = requiresRaiseEvent as Control;
  1180. if (targetControl != null && CheckForValidationSupport (targetControl))
  1181. scriptManager.ValidateEvent (targetControl.UniqueID, null);
  1182. #endif
  1183. RaisePostBackEvent (requiresRaiseEvent, null);
  1184. return;
  1185. }
  1186. NameValueCollection postdata = _requestValueCollection;
  1187. if (postdata == null)
  1188. return;
  1189. string eventTarget = postdata [postEventSourceID];
  1190. if (eventTarget == null || eventTarget.Length == 0) {
  1191. Validate ();
  1192. return;
  1193. }
  1194. #if NET_2_0
  1195. targetControl = FindControl (eventTarget);
  1196. IPostBackEventHandler target = targetControl as IPostBackEventHandler;
  1197. #else
  1198. IPostBackEventHandler target = FindControl (eventTarget) as IPostBackEventHandler;
  1199. #endif
  1200. if (target == null)
  1201. return;
  1202. string eventArgument = postdata [postEventArgumentID];
  1203. #if NET_2_0
  1204. if (CheckForValidationSupport (targetControl))
  1205. scriptManager.ValidateEvent (targetControl.UniqueID, eventArgument);
  1206. #endif
  1207. RaisePostBackEvent (target, eventArgument);
  1208. }
  1209. internal void RaiseChangedEvents ()
  1210. {
  1211. if (requiresPostDataChanged == null)
  1212. return;
  1213. foreach (IPostBackDataHandler ipdh in requiresPostDataChanged)
  1214. ipdh.RaisePostDataChangedEvent ();
  1215. requiresPostDataChanged = null;
  1216. }
  1217. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1218. protected virtual void RaisePostBackEvent (IPostBackEventHandler sourceControl, string eventArgument)
  1219. {
  1220. sourceControl.RaisePostBackEvent (eventArgument);
  1221. }
  1222. #if NET_2_0
  1223. [Obsolete]
  1224. #endif
  1225. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1226. public void RegisterArrayDeclaration (string arrayName, string arrayValue)
  1227. {
  1228. scriptManager.RegisterArrayDeclaration (arrayName, arrayValue);
  1229. }
  1230. #if NET_2_0
  1231. [Obsolete]
  1232. #endif
  1233. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1234. public virtual void RegisterClientScriptBlock (string key, string script)
  1235. {
  1236. scriptManager.RegisterClientScriptBlock (key, script);
  1237. }
  1238. #if NET_2_0
  1239. [Obsolete]
  1240. #endif
  1241. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1242. public virtual void RegisterHiddenField (string hiddenFieldName, string hiddenFieldInitialValue)
  1243. {
  1244. scriptManager.RegisterHiddenField (hiddenFieldName, hiddenFieldInitialValue);
  1245. }
  1246. [MonoTODO("Not implemented, Used in HtmlForm")]
  1247. internal void RegisterClientScriptFile (string a, string b, string c)
  1248. {
  1249. throw new NotImplementedException ();
  1250. }
  1251. #if NET_2_0
  1252. [Obsolete]
  1253. #endif
  1254. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1255. public void RegisterOnSubmitStatement (string key, string script)
  1256. {
  1257. scriptManager.RegisterOnSubmitStatement (key, script);
  1258. }
  1259. internal string GetSubmitStatements ()
  1260. {
  1261. return scriptManager.WriteSubmitStatements ();
  1262. }
  1263. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1264. public void RegisterRequiresPostBack (Control control)
  1265. {
  1266. if (_requiresPostBack == null)
  1267. _requiresPostBack = new ArrayList ();
  1268. if (_requiresPostBack.Contains (control.UniqueID))
  1269. return;
  1270. _requiresPostBack.Add (control.UniqueID);
  1271. }
  1272. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1273. public virtual void RegisterRequiresRaiseEvent (IPostBackEventHandler control)
  1274. {
  1275. requiresRaiseEvent = control;
  1276. }
  1277. #if NET_2_0
  1278. [Obsolete]
  1279. #endif
  1280. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1281. public virtual void RegisterStartupScript (string key, string script)
  1282. {
  1283. scriptManager.RegisterStartupScript (key, script);
  1284. }
  1285. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1286. public void RegisterViewStateHandler ()
  1287. {
  1288. handleViewState = true;
  1289. }
  1290. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1291. protected virtual void SavePageStateToPersistenceMedium (object viewState)
  1292. {
  1293. PageStatePersister persister = this.PageStatePersister;
  1294. if (persister == null)
  1295. return;
  1296. Pair pair = viewState as Pair;
  1297. if (pair != null) {
  1298. persister.ViewState = pair.First;
  1299. persister.ControlState = pair.Second;
  1300. } else
  1301. persister.ViewState = viewState;
  1302. persister.Save ();
  1303. }
  1304. internal string RawViewState {
  1305. get {
  1306. NameValueCollection postdata = _requestValueCollection;
  1307. string view_state;
  1308. if (postdata == null || (view_state = postdata ["__VIEWSTATE"]) == null)
  1309. return null;
  1310. if (view_state == "")
  1311. return null;
  1312. return view_state;
  1313. }
  1314. set { _savedViewState = value; }
  1315. }
  1316. #if NET_2_0
  1317. protected virtual
  1318. #else
  1319. internal
  1320. #endif
  1321. PageStatePersister PageStatePersister {
  1322. get {
  1323. if (page_state_persister == null)
  1324. page_state_persister = new HiddenFieldPageStatePersister (this);
  1325. return page_state_persister;
  1326. }
  1327. }
  1328. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1329. protected virtual object LoadPageStateFromPersistenceMedium ()
  1330. {
  1331. PageStatePersister persister = this.PageStatePersister;
  1332. if (persister == null)
  1333. return null;
  1334. persister.Load ();
  1335. return new Pair (persister.ViewState, persister.ControlState);
  1336. }
  1337. internal void LoadPageViewState()
  1338. {
  1339. Pair sState = LoadPageStateFromPersistenceMedium () as Pair;
  1340. if (sState != null) {
  1341. if (allow_load) {
  1342. #if NET_2_0
  1343. LoadPageControlState (sState.Second);
  1344. #endif
  1345. Pair vsr = sState.First as Pair;
  1346. if (vsr != null) {
  1347. LoadViewStateRecursive (vsr.First);
  1348. _requiresPostBackCopy = vsr.Second as ArrayList;
  1349. }
  1350. }
  1351. }
  1352. }
  1353. internal void SavePageViewState ()
  1354. {
  1355. if (!handleViewState)
  1356. return;
  1357. #if NET_2_0
  1358. object controlState = SavePageControlState ();
  1359. #endif
  1360. object viewState = SaveViewStateRecursive ();
  1361. object reqPostback = (_requiresPostBack != null && _requiresPostBack.Count > 0) ? _requiresPostBack : null;
  1362. Pair vsr = null;
  1363. if (viewState != null || reqPostback != null)
  1364. vsr = new Pair (viewState, reqPostback);
  1365. Pair pair = new Pair ();
  1366. pair.First = vsr;
  1367. #if NET_2_0
  1368. pair.Second = controlState;
  1369. #else
  1370. pair.Second = null;
  1371. #endif
  1372. if (pair.First == null && pair.Second == null)
  1373. SavePageStateToPersistenceMedium (null);
  1374. else
  1375. SavePageStateToPersistenceMedium (pair);
  1376. }
  1377. public virtual void Validate ()
  1378. {
  1379. is_validated = true;
  1380. ValidateCollection (_validators);
  1381. }
  1382. #if NET_2_0
  1383. internal bool AreValidatorsUplevel () {
  1384. return AreValidatorsUplevel (String.Empty);
  1385. }
  1386. internal bool AreValidatorsUplevel (string valGroup)
  1387. #else
  1388. internal virtual bool AreValidatorsUplevel ()
  1389. #endif
  1390. {
  1391. bool uplevel = false;
  1392. foreach (IValidator v in Validators) {
  1393. BaseValidator bv = v as BaseValidator;
  1394. if (bv == null) continue;
  1395. #if NET_2_0
  1396. if (valGroup != bv.ValidationGroup)
  1397. continue;
  1398. #endif
  1399. if (bv.GetRenderUplevel()) {
  1400. uplevel = true;
  1401. break;
  1402. }
  1403. }
  1404. return uplevel;
  1405. }
  1406. bool ValidateCollection (ValidatorCollection validators)
  1407. {
  1408. #if NET_2_0
  1409. if (!_eventValidation)
  1410. return true;
  1411. #endif
  1412. if (validators == null || validators.Count == 0)
  1413. return true;
  1414. bool all_valid = true;
  1415. foreach (IValidator v in validators){
  1416. v.Validate ();
  1417. if (v.IsValid == false)
  1418. all_valid = false;
  1419. }
  1420. return all_valid;
  1421. }
  1422. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1423. public virtual void VerifyRenderingInServerForm (Control control)
  1424. {
  1425. if (_context == null)
  1426. return;
  1427. if (!renderingForm)
  1428. throw new HttpException ("Control '" +
  1429. control.ClientID +
  1430. "' of type '" +
  1431. control.GetType ().Name +
  1432. "' must be placed inside a form tag with runat=server.");
  1433. }
  1434. protected override void FrameworkInitialize ()
  1435. {
  1436. base.FrameworkInitialize ();
  1437. #if NET_2_0
  1438. InitializeStyleSheet ();
  1439. #endif
  1440. }
  1441. #endregion
  1442. #if NET_2_0
  1443. public
  1444. #else
  1445. internal
  1446. #endif
  1447. ClientScriptManager ClientScript {
  1448. get { return scriptManager; }
  1449. }
  1450. #if NET_2_0
  1451. static readonly object InitCompleteEvent = new object ();
  1452. static readonly object LoadCompleteEvent = new object ();
  1453. static readonly object PreInitEvent = new object ();
  1454. static readonly object PreLoadEvent = new object ();
  1455. static readonly object PreRenderCompleteEvent = new object ();
  1456. static readonly object SaveStateCompleteEvent = new object ();
  1457. int event_mask;
  1458. const int initcomplete_mask = 1;
  1459. const int loadcomplete_mask = 1 << 1;
  1460. const int preinit_mask = 1 << 2;
  1461. const int preload_mask = 1 << 3;
  1462. const int prerendercomplete_mask = 1 << 4;
  1463. const int savestatecomplete_mask = 1 << 5;
  1464. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1465. public event EventHandler InitComplete {
  1466. add {
  1467. event_mask |= initcomplete_mask;
  1468. Events.AddHandler (InitCompleteEvent, value);
  1469. }
  1470. remove { Events.RemoveHandler (InitCompleteEvent, value); }
  1471. }
  1472. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1473. public event EventHandler LoadComplete {
  1474. add {
  1475. event_mask |= loadcomplete_mask;
  1476. Events.AddHandler (LoadCompleteEvent, value);
  1477. }
  1478. remove { Events.RemoveHandler (LoadCompleteEvent, value); }
  1479. }
  1480. public event EventHandler PreInit {
  1481. add {
  1482. event_mask |= preinit_mask;
  1483. Events.AddHandler (PreInitEvent, value);
  1484. }
  1485. remove { Events.RemoveHandler (PreInitEvent, value); }
  1486. }
  1487. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1488. public event EventHandler PreLoad {
  1489. add {
  1490. event_mask |= preload_mask;
  1491. Events.AddHandler (PreLoadEvent, value);
  1492. }
  1493. remove { Events.RemoveHandler (PreLoadEvent, value); }
  1494. }
  1495. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1496. public event EventHandler PreRenderComplete {
  1497. add {
  1498. event_mask |= prerendercomplete_mask;
  1499. Events.AddHandler (PreRenderCompleteEvent, value);
  1500. }
  1501. remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
  1502. }
  1503. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1504. public event EventHandler SaveStateComplete {
  1505. add {
  1506. event_mask |= savestatecomplete_mask;
  1507. Events.AddHandler (SaveStateCompleteEvent, value);
  1508. }
  1509. remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
  1510. }
  1511. protected virtual void OnInitComplete (EventArgs e)
  1512. {
  1513. if ((event_mask & initcomplete_mask) != 0) {
  1514. EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
  1515. if (eh != null) eh (this, e);
  1516. }
  1517. }
  1518. protected virtual void OnLoadComplete (EventArgs e)
  1519. {
  1520. if ((event_mask & loadcomplete_mask) != 0) {
  1521. EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
  1522. if (eh != null) eh (this, e);
  1523. }
  1524. }
  1525. protected virtual void OnPreInit (EventArgs e)
  1526. {
  1527. if ((event_mask & preinit_mask) != 0) {
  1528. EventHandler eh = (EventHandler) (Events [PreInitEvent]);
  1529. if (eh != null) eh (this, e);
  1530. }
  1531. }
  1532. protected virtual void OnPreLoad (EventArgs e)
  1533. {
  1534. if ((event_mask & preload_mask) != 0) {
  1535. EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
  1536. if (eh != null) eh (this, e);
  1537. }
  1538. }
  1539. protected virtual void OnPreRenderComplete (EventArgs e)
  1540. {
  1541. if ((event_mask & prerendercomplete_mask) != 0) {
  1542. EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
  1543. if (eh != null) eh (this, e);
  1544. }
  1545. if (Form == null)
  1546. return;
  1547. if (!Form.DetermineRenderUplevel ())
  1548. return;
  1549. /* figure out if we have some control we're going to focus */
  1550. if (String.IsNullOrEmpty (_focusedControlID)) {
  1551. _focusedControlID = Form.DefaultFocus;
  1552. if (String.IsNullOrEmpty (_focusedControlID))
  1553. _focusedControlID = Form.DefaultButton;
  1554. }
  1555. if (!String.IsNullOrEmpty (_focusedControlID) || Form.SubmitDisabledControls) {
  1556. RequiresPostBackScript ();
  1557. ClientScript.RegisterWebFormClientScript ();
  1558. if (!String.IsNullOrEmpty (_focusedControlID)) {
  1559. ClientScript.RegisterStartupScript ("HtmlForm-DefaultButton-StartupScript",
  1560. String.Format ("<script type=\"text/javascript\">\n" +
  1561. "<!--\n" +
  1562. "WebForm_AutoFocus('{0}');// -->\n" +
  1563. "</script>\n", _focusedControlID));
  1564. }
  1565. if (Form.SubmitDisabledControls) {
  1566. ClientScript.RegisterOnSubmitStatement ("HtmlForm-SubmitDisabledControls-SubmitStatement",
  1567. "javascript: return WebForm_OnSubmit();");
  1568. ClientScript.RegisterStartupScript ("HtmlForm-SubmitDisabledControls-StartupScript",
  1569. @"<script language=""JavaScript"">
  1570. <!--
  1571. function WebForm_OnSubmit() {
  1572. WebForm_ReEnableControls();
  1573. return true;
  1574. } // -->
  1575. </script>");
  1576. }
  1577. }
  1578. }
  1579. protected virtual void OnSaveStateComplete (EventArgs e)
  1580. {
  1581. if ((event_mask & savestatecomplete_mask) != 0) {
  1582. EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
  1583. if (eh != null) eh (this, e);
  1584. }
  1585. }
  1586. public HtmlForm Form {
  1587. get { return _form; }
  1588. }
  1589. internal void RegisterForm (HtmlForm form)
  1590. {
  1591. _form = form;
  1592. }
  1593. [BrowsableAttribute (false)]
  1594. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1595. public Page PreviousPage {
  1596. get {
  1597. if (_doLoadPreviousPage) {
  1598. _doLoadPreviousPage = false;
  1599. LoadPreviousPageReference ();
  1600. }
  1601. return previousPage;
  1602. }
  1603. }
  1604. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1605. [BrowsableAttribute (false)]
  1606. public bool IsCallback {
  1607. get { return isCallback; }
  1608. }
  1609. [BrowsableAttribute (false)]
  1610. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1611. public bool IsCrossPagePostBack {
  1612. get { return isCrossPagePostBack; }
  1613. }
  1614. public new virtual char IdSeparator {
  1615. get {
  1616. //TODO: why override?
  1617. return base.IdSeparator;
  1618. }
  1619. }
  1620. string ProcessCallbackData ()
  1621. {
  1622. string callbackTarget = _requestValueCollection [CallbackSourceID];
  1623. if (callbackTarget == null || callbackTarget.Length == 0)
  1624. throw new HttpException ("Callback target not provided.");
  1625. Control targetControl = FindControl (callbackTarget);
  1626. ICallbackEventHandler target = targetControl as ICallbackEventHandler;
  1627. if (target == null)
  1628. throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
  1629. string callbackArgument = _requestValueCollection [CallbackArgumentID];
  1630. target.RaiseCallbackEvent (callbackArgument);
  1631. return target.GetCallbackResult ();
  1632. }
  1633. [BrowsableAttribute (false)]
  1634. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1635. public HtmlHead Header {
  1636. get { return htmlHeader; }
  1637. }
  1638. internal void SetHeader (HtmlHead header)
  1639. {
  1640. htmlHeader = header;
  1641. if (_title != null) {
  1642. htmlHeader.Title = _title;
  1643. _title = null;
  1644. }
  1645. }
  1646. [MonoTODO("Not Implemented")]
  1647. protected bool AsyncMode {
  1648. get {
  1649. throw new NotImplementedException ();
  1650. }
  1651. set {
  1652. throw new NotImplementedException ();
  1653. }
  1654. }
  1655. [MonoTODO ("Not Implemented")]
  1656. public TimeSpan AsyncTimeout {
  1657. get {
  1658. throw new NotImplementedException ();
  1659. }
  1660. set {
  1661. throw new NotImplementedException ();
  1662. }
  1663. }
  1664. [MonoTODO ("Not Implemented")]
  1665. public bool IsAsync {
  1666. get {
  1667. throw new NotImplementedException ();
  1668. }
  1669. }
  1670. [MonoTODO ("Not Implemented")]
  1671. protected internal virtual string UniqueFilePathSuffix {
  1672. get {
  1673. throw new NotImplementedException ();
  1674. }
  1675. }
  1676. [MonoTODO ("Not Implemented")]
  1677. public int MaxPageStateFieldLength {
  1678. get {
  1679. throw new NotImplementedException ();
  1680. }
  1681. set {
  1682. throw new NotImplementedException ();
  1683. }
  1684. }
  1685. [MonoTODO ("Not Implemented")]
  1686. public ViewStateEncryptionMode ViewStateEncryptionMode {
  1687. get {
  1688. throw new NotImplementedException ();
  1689. }
  1690. set {
  1691. throw new NotImplementedException ();
  1692. }
  1693. }
  1694. [MonoTODO ("Not Implemented")]
  1695. public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler)
  1696. {
  1697. throw new NotImplementedException ();
  1698. }
  1699. [MonoTODO ("Not Implemented")]
  1700. public void AddOnPreRenderCompleteAsync (BeginEventHandler beginHandler, EndEventHandler endHandler, Object state)
  1701. {
  1702. throw new NotImplementedException ();
  1703. }
  1704. [MonoTODO ("Not Implemented")]
  1705. public void ExecuteRegisteredAsyncTasks ()
  1706. {
  1707. throw new NotImplementedException ();
  1708. }
  1709. [MonoTODO ("Not Implemented")]
  1710. public static HtmlTextWriter CreateHtmlTextWriterFromType (TextWriter tw, Type writerType)
  1711. {
  1712. throw new NotImplementedException ();
  1713. }
  1714. [MonoTODO ("Not Implemented")]
  1715. public void RegisterRequiresViewStateEncryption ()
  1716. {
  1717. throw new NotImplementedException ();
  1718. }
  1719. void ApplyMasterPage ()
  1720. {
  1721. if (masterPageFile != null && masterPageFile.Length > 0) {
  1722. ArrayList appliedMasterPageFiles = new ArrayList ();
  1723. if (Master != null) {
  1724. MasterPage.ApplyMasterPageRecursive (Master, appliedMasterPageFiles);
  1725. Master.Page = this;
  1726. Controls.Clear ();
  1727. Controls.Add (Master);
  1728. }
  1729. }
  1730. }
  1731. [DefaultValueAttribute ("")]
  1732. public virtual string MasterPageFile {
  1733. get { return masterPageFile; }
  1734. set {
  1735. masterPageFile = value;
  1736. masterPage = null;
  1737. }
  1738. }
  1739. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1740. [BrowsableAttribute (false)]
  1741. public MasterPage Master {
  1742. get {
  1743. if (Context == null || String.IsNullOrEmpty (masterPageFile))
  1744. return null;
  1745. if (masterPage == null)
  1746. masterPage = MasterPage.CreateMasterPage (this, Context, masterPageFile, contentTemplates);
  1747. return masterPage;
  1748. }
  1749. }
  1750. public void SetFocus (string clientID)
  1751. {
  1752. if (String.IsNullOrEmpty (clientID))
  1753. throw new ArgumentNullException ("control");
  1754. if (_lifeCycle > PageLifeCycle.PreRender)
  1755. throw new InvalidOperationException ("SetFocus can only be called before and during PreRender.");
  1756. if(Form==null)
  1757. throw new InvalidOperationException ("A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property.");
  1758. _focusedControlID = clientID;
  1759. }
  1760. public void SetFocus (Control control)
  1761. {
  1762. if (control == null)
  1763. throw new ArgumentNullException ("control");
  1764. SetFocus (control.ClientID);
  1765. }
  1766. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1767. public void RegisterRequiresControlState (Control control)
  1768. {
  1769. if (control == null)
  1770. throw new ArgumentNullException ("control");
  1771. if (RequiresControlState (control))
  1772. return;
  1773. if (requireStateControls == null)
  1774. requireStateControls = new ArrayList ();
  1775. int n = requireStateControls.Add (control);
  1776. if (_savedControlState == null || n >= _savedControlState.Length)
  1777. return;
  1778. for (Control parent = control.Parent; parent != null; parent = parent.Parent)
  1779. if (parent.IsChildControlStateCleared)
  1780. return;
  1781. object state = _savedControlState [n];
  1782. if (state != null)
  1783. control.LoadControlState (state);
  1784. }
  1785. public bool RequiresControlState (Control control)
  1786. {
  1787. if (requireStateControls == null) return false;
  1788. return requireStateControls.Contains (control);
  1789. }
  1790. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1791. public void UnregisterRequiresControlState (Control control)
  1792. {
  1793. if (requireStateControls != null)
  1794. requireStateControls.Remove (control);
  1795. }
  1796. public ValidatorCollection GetValidators (string validationGroup)
  1797. {
  1798. string valgr = validationGroup;
  1799. if (valgr == null)
  1800. valgr = String.Empty;
  1801. if (_validatorsByGroup == null) _validatorsByGroup = new Hashtable ();
  1802. ValidatorCollection col = _validatorsByGroup [valgr] as ValidatorCollection;
  1803. if (col == null) {
  1804. col = new ValidatorCollection ();
  1805. _validatorsByGroup [valgr] = col;
  1806. }
  1807. return col;
  1808. }
  1809. public virtual void Validate (string validationGroup)
  1810. {
  1811. is_validated = true;
  1812. if (validationGroup == null)
  1813. ValidateCollection (_validatorsByGroup [String.Empty] as ValidatorCollection);
  1814. else if (_validatorsByGroup != null) {
  1815. ValidateCollection (_validatorsByGroup [validationGroup] as ValidatorCollection);
  1816. }
  1817. }
  1818. object SavePageControlState ()
  1819. {
  1820. if (requireStateControls == null) return null;
  1821. object[] state = new object [requireStateControls.Count];
  1822. bool allNull = true;
  1823. for (int n=0; n<state.Length; n++) {
  1824. state [n] = ((Control) requireStateControls [n]).SaveControlState ();
  1825. if (state [n] != null) allNull = false;
  1826. }
  1827. if (allNull) return null;
  1828. else return state;
  1829. }
  1830. void LoadPageControlState (object data)
  1831. {
  1832. _savedControlState = (object []) data;
  1833. if (requireStateControls == null) return;
  1834. int max = Math.Min (requireStateControls.Count, _savedControlState != null ? _savedControlState.Length : requireStateControls.Count);
  1835. for (int n=0; n < max; n++) {
  1836. Control ctl = (Control) requireStateControls [n];
  1837. ctl.LoadControlState (_savedControlState != null ? _savedControlState [n] : null);
  1838. }
  1839. }
  1840. void LoadPreviousPageReference ()
  1841. {
  1842. if (_requestValueCollection != null) {
  1843. string prevPage = _requestValueCollection [PreviousPageID];
  1844. if (prevPage != null) {
  1845. previousPage = (Page) PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
  1846. previousPage.ProcessCrossPagePostBack (_context);
  1847. }
  1848. }
  1849. }
  1850. Hashtable contentTemplates;
  1851. [EditorBrowsable (EditorBrowsableState.Never)]
  1852. protected internal void AddContentTemplate (string templateName, ITemplate template)
  1853. {
  1854. if (contentTemplates == null)
  1855. contentTemplates = new Hashtable ();
  1856. contentTemplates [templateName] = template;
  1857. }
  1858. PageTheme _pageTheme;
  1859. internal PageTheme PageTheme {
  1860. get { return _pageTheme; }
  1861. }
  1862. PageTheme _styleSheetPageTheme;
  1863. internal PageTheme StyleSheetPageTheme {
  1864. get { return _styleSheetPageTheme; }
  1865. }
  1866. Stack dataItemCtx;
  1867. internal void PushDataItemContext (object o) {
  1868. if (dataItemCtx == null)
  1869. dataItemCtx = new Stack ();
  1870. dataItemCtx.Push (o);
  1871. }
  1872. internal void PopDataItemContext () {
  1873. if (dataItemCtx == null)
  1874. throw new InvalidOperationException ();
  1875. dataItemCtx.Pop ();
  1876. }
  1877. public object GetDataItem() {
  1878. if (dataItemCtx == null || dataItemCtx.Count == 0)
  1879. throw new InvalidOperationException ("No data item");
  1880. return dataItemCtx.Peek ();
  1881. }
  1882. protected internal override void OnInit (EventArgs e)
  1883. {
  1884. base.OnInit (e);
  1885. if (Header == null)
  1886. return;
  1887. ArrayList themes = new ArrayList();
  1888. if (StyleSheetPageTheme != null && StyleSheetPageTheme.GetStyleSheets () != null)
  1889. themes.AddRange (StyleSheetPageTheme.GetStyleSheets ());
  1890. if (PageTheme != null && PageTheme.GetStyleSheets () != null)
  1891. themes.AddRange (PageTheme.GetStyleSheets ());
  1892. foreach (string lss in themes) {
  1893. HtmlLink hl = new HtmlLink ();
  1894. hl.Href = ResolveUrl (lss);
  1895. hl.Attributes["type"] = "text/css";
  1896. hl.Attributes["rel"] = "stylesheet";
  1897. Header.Controls.Add (hl);
  1898. }
  1899. }
  1900. #endif
  1901. #if NET_2_0
  1902. [MonoTODO ("Not implemented. Only used by .net aspx parser")]
  1903. protected object GetWrappedFileDependencies (string [] list)
  1904. {
  1905. return null;
  1906. }
  1907. [MonoTODO ("Does nothing. Used by .net aspx parser")]
  1908. protected virtual void InitializeCulture ()
  1909. {
  1910. }
  1911. [MonoTODO ("Does nothing. Used by .net aspx parser")]
  1912. protected internal void AddWrappedFileDependencies (object virtualFileDependencies)
  1913. {
  1914. }
  1915. #endif
  1916. }
  1917. }