Page.cs 43 KB

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