Page.cs 42 KB

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