Page.cs 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604
  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 CONFIGURATION_2_0
  703. PagesSection config = (PagesSection) WebConfigurationManager.GetWebApplicationSection ("system.web/pages");
  704. #else
  705. PagesConfiguration config = PagesConfiguration.GetInstance (_context);
  706. #endif
  707. byte [] vkey = null;
  708. if (config.EnableViewStateMac) {
  709. #if CONFIGURATION_2_0
  710. MachineKeySection mconfig = (MachineKeySection) WebConfigurationManager.GetWebApplicationSection ("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 (validators == null || validators.Count == 0)
  1121. return true;
  1122. bool all_valid = true;
  1123. foreach (IValidator v in validators){
  1124. v.Validate ();
  1125. if (v.IsValid == false)
  1126. all_valid = false;
  1127. }
  1128. return all_valid;
  1129. }
  1130. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1131. public virtual void VerifyRenderingInServerForm (Control control)
  1132. {
  1133. if (_context == null)
  1134. return;
  1135. if (!renderingForm)
  1136. throw new HttpException ("Control '" +
  1137. control.ClientID +
  1138. "' of type '" +
  1139. control.GetType ().Name +
  1140. "' must be placed inside a form tag with runat=server.");
  1141. }
  1142. #endregion
  1143. #if NET_2_0
  1144. public
  1145. #else
  1146. internal
  1147. #endif
  1148. ClientScriptManager ClientScript {
  1149. get { return scriptManager; }
  1150. }
  1151. #if NET_2_0
  1152. static readonly object InitCompleteEvent = new object ();
  1153. static readonly object LoadCompleteEvent = new object ();
  1154. static readonly object PreInitEvent = new object ();
  1155. static readonly object PreLoadEvent = new object ();
  1156. static readonly object PreRenderCompleteEvent = new object ();
  1157. static readonly object SaveStateCompleteEvent = new object ();
  1158. int event_mask;
  1159. const int initcomplete_mask = 1;
  1160. const int loadcomplete_mask = 1 << 1;
  1161. const int preinit_mask = 1 << 2;
  1162. const int preload_mask = 1 << 3;
  1163. const int prerendercomplete_mask = 1 << 4;
  1164. const int savestatecomplete_mask = 1 << 5;
  1165. public event EventHandler InitComplete {
  1166. add {
  1167. event_mask |= initcomplete_mask;
  1168. Events.AddHandler (InitCompleteEvent, value);
  1169. }
  1170. remove { Events.RemoveHandler (InitCompleteEvent, value); }
  1171. }
  1172. public event EventHandler LoadComplete {
  1173. add {
  1174. event_mask |= loadcomplete_mask;
  1175. Events.AddHandler (LoadCompleteEvent, value);
  1176. }
  1177. remove { Events.RemoveHandler (LoadCompleteEvent, value); }
  1178. }
  1179. public event EventHandler PreInit {
  1180. add {
  1181. event_mask |= preinit_mask;
  1182. Events.AddHandler (PreInitEvent, value);
  1183. }
  1184. remove { Events.RemoveHandler (PreInitEvent, value); }
  1185. }
  1186. public event EventHandler PreLoad {
  1187. add {
  1188. event_mask |= preload_mask;
  1189. Events.AddHandler (PreLoadEvent, value);
  1190. }
  1191. remove { Events.RemoveHandler (PreLoadEvent, value); }
  1192. }
  1193. public event EventHandler PreRenderComplete {
  1194. add {
  1195. event_mask |= prerendercomplete_mask;
  1196. Events.AddHandler (PreRenderCompleteEvent, value);
  1197. }
  1198. remove { Events.RemoveHandler (PreRenderCompleteEvent, value); }
  1199. }
  1200. public event EventHandler SaveStateComplete {
  1201. add {
  1202. event_mask |= savestatecomplete_mask;
  1203. Events.AddHandler (SaveStateCompleteEvent, value);
  1204. }
  1205. remove { Events.RemoveHandler (SaveStateCompleteEvent, value); }
  1206. }
  1207. protected virtual void OnInitComplete (EventArgs e)
  1208. {
  1209. if ((event_mask & initcomplete_mask) != 0) {
  1210. EventHandler eh = (EventHandler) (Events [InitCompleteEvent]);
  1211. if (eh != null) eh (this, e);
  1212. }
  1213. }
  1214. protected virtual void OnLoadComplete (EventArgs e)
  1215. {
  1216. if ((event_mask & loadcomplete_mask) != 0) {
  1217. EventHandler eh = (EventHandler) (Events [LoadCompleteEvent]);
  1218. if (eh != null) eh (this, e);
  1219. }
  1220. }
  1221. protected virtual void OnPreInit (EventArgs e)
  1222. {
  1223. if ((event_mask & preinit_mask) != 0) {
  1224. EventHandler eh = (EventHandler) (Events [PreInitEvent]);
  1225. if (eh != null) eh (this, e);
  1226. }
  1227. }
  1228. protected virtual void OnPreLoad (EventArgs e)
  1229. {
  1230. if ((event_mask & preload_mask) != 0) {
  1231. EventHandler eh = (EventHandler) (Events [PreLoadEvent]);
  1232. if (eh != null) eh (this, e);
  1233. }
  1234. }
  1235. protected virtual void OnPreRenderComplete (EventArgs e)
  1236. {
  1237. if ((event_mask & prerendercomplete_mask) != 0) {
  1238. EventHandler eh = (EventHandler) (Events [PreRenderCompleteEvent]);
  1239. if (eh != null) eh (this, e);
  1240. }
  1241. }
  1242. protected virtual void OnSaveStateComplete (EventArgs e)
  1243. {
  1244. if ((event_mask & savestatecomplete_mask) != 0) {
  1245. EventHandler eh = (EventHandler) (Events [SaveStateCompleteEvent]);
  1246. if (eh != null) eh (this, e);
  1247. }
  1248. }
  1249. public HtmlForm Form {
  1250. get { return _form; }
  1251. }
  1252. internal void RegisterForm (HtmlForm form)
  1253. {
  1254. _form = form;
  1255. }
  1256. [BrowsableAttribute (false)]
  1257. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1258. public Page PreviousPage {
  1259. get { return previousPage; }
  1260. }
  1261. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1262. [BrowsableAttribute (false)]
  1263. public bool IsCallback {
  1264. get { return _requestValueCollection != null && _requestValueCollection [CallbackArgumentID] != null; }
  1265. }
  1266. [BrowsableAttribute (false)]
  1267. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1268. public bool IsCrossPagePostBack {
  1269. get { return _requestValueCollection != null && isCrossPagePostBack; }
  1270. }
  1271. string ProcessCallbackData ()
  1272. {
  1273. string callbackTarget = _requestValueCollection [CallbackSourceID];
  1274. if (callbackTarget == null || callbackTarget.Length == 0)
  1275. throw new HttpException ("Callback target not provided.");
  1276. ICallbackEventHandler target = FindControl (callbackTarget) as ICallbackEventHandler;
  1277. if (target == null)
  1278. throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
  1279. string callbackArgument = _requestValueCollection [CallbackArgumentID];
  1280. return target.RaiseCallbackEvent (callbackArgument);
  1281. }
  1282. [BrowsableAttribute (false)]
  1283. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1284. public HtmlHead Header {
  1285. get { return htmlHeader; }
  1286. }
  1287. internal void SetHeader (HtmlHead header)
  1288. {
  1289. htmlHeader = header;
  1290. }
  1291. [DefaultValueAttribute ("")]
  1292. public string MasterPageFile {
  1293. get { return masterPageFile; }
  1294. set { masterPageFile = value; masterPage = null; }
  1295. }
  1296. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  1297. [BrowsableAttribute (false)]
  1298. public MasterPage Master {
  1299. get {
  1300. if (masterPage == null)
  1301. masterPage = MasterPageParser.GetCompiledMasterInstance (masterPageFile, Server.MapPath (masterPageFile), Context);
  1302. return masterPage;
  1303. }
  1304. }
  1305. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1306. public void RegisterRequiresControlState (Control control)
  1307. {
  1308. if (requireStateControls == null) requireStateControls = new ArrayList ();
  1309. requireStateControls.Add (control);
  1310. }
  1311. public bool RequiresControlState (Control control)
  1312. {
  1313. if (requireStateControls == null) return false;
  1314. return requireStateControls.Contains (control);
  1315. }
  1316. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1317. public void UnregisterRequiresControlState (Control control)
  1318. {
  1319. if (requireStateControls != null)
  1320. requireStateControls.Remove (control);
  1321. }
  1322. public ValidatorCollection GetValidators (string validationGroup)
  1323. {
  1324. if (validationGroup == null || validationGroup == "")
  1325. return Validators;
  1326. if (_validatorsByGroup == null) _validatorsByGroup = new Hashtable ();
  1327. ValidatorCollection col = _validatorsByGroup [validationGroup] as ValidatorCollection;
  1328. if (col == null) {
  1329. col = new ValidatorCollection ();
  1330. _validatorsByGroup [validationGroup] = col;
  1331. }
  1332. return col;
  1333. }
  1334. public virtual void Validate (string validationGroup)
  1335. {
  1336. is_validated = true;
  1337. if (validationGroup == null || validationGroup == "")
  1338. ValidateCollection (_validators);
  1339. else if (_validatorsByGroup != null) {
  1340. ValidateCollection (_validatorsByGroup [validationGroup] as ValidatorCollection);
  1341. }
  1342. }
  1343. object SavePageControlState ()
  1344. {
  1345. if (requireStateControls == null) return null;
  1346. object[] state = new object [requireStateControls.Count];
  1347. bool allNull = true;
  1348. for (int n=0; n<state.Length; n++) {
  1349. state [n] = ((Control) requireStateControls [n]).SaveControlState ();
  1350. if (state [n] != null) allNull = false;
  1351. }
  1352. if (allNull) return null;
  1353. else return state;
  1354. }
  1355. void LoadPageControlState (object data)
  1356. {
  1357. if (requireStateControls == null) return;
  1358. object[] state = (object[]) data;
  1359. int max = Math.Min (requireStateControls.Count, state != null ? state.Length : requireStateControls.Count);
  1360. for (int n=0; n < max; n++) {
  1361. Control ctl = (Control) requireStateControls [n];
  1362. ctl.LoadControlState (state != null ? state [n] : null);
  1363. }
  1364. }
  1365. void LoadPreviousPageReference ()
  1366. {
  1367. if (_requestValueCollection != null) {
  1368. string prevPage = _requestValueCollection [PreviousPageID];
  1369. if (prevPage != null) {
  1370. previousPage = (Page) PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage), Context);
  1371. previousPage.ProcessCrossPagePostBack (_context);
  1372. } else {
  1373. previousPage = _context.LastPage;
  1374. }
  1375. }
  1376. _context.LastPage = this;
  1377. }
  1378. [EditorBrowsable (EditorBrowsableState.Advanced)]
  1379. protected internal void AddContentTemplate (string templateName, ITemplate template)
  1380. {
  1381. Master.AddContentTemplate (templateName, template);
  1382. }
  1383. #endif
  1384. }
  1385. }