Page.cs 42 KB

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