-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathControl.cs
3665 lines (3182 loc) · 138 KB
/
Control.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//------------------------------------------------------------------------------
// <copyright file="Control.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI {
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
using System.Web.Caching;
using System.Web.Configuration;
using System.Web.Hosting;
using System.Web.Routing;
using System.Web.UI.Adapters;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.Util;
using HttpException = System.Web.HttpException;
// Delegate used for the compiled template
public delegate void RenderMethod(HtmlTextWriter output, Control container);
public delegate Control BuildMethod();
// Defines the properties, methods, and events that are shared by all server
// controls in the Web Forms page framework.</para>
[
Bindable(true),
DefaultProperty("ID"),
DesignerCategory("Code"),
Designer("System.Web.UI.Design.ControlDesigner, " + AssemblyRef.SystemDesign),
DesignerSerializer("Microsoft.VisualStudio.Web.WebForms.ControlCodeDomSerializer, " + AssemblyRef.MicrosoftVisualStudioWeb, "System.ComponentModel.Design.Serialization.CodeDomSerializer, " + AssemblyRef.SystemDesign),
Themeable(false),
ToolboxItemFilter("System.Web.UI", ToolboxItemFilterType.Require),
ToolboxItemAttribute("System.Web.UI.Design.WebControlToolboxItem, " + AssemblyRef.SystemDesign)
]
public class Control : IComponent, IParserAccessor, IUrlResolutionService, IDataBindingsAccessor, IControlBuilderAccessor, IControlDesignerAccessor, IExpressionsAccessor {
internal static readonly object EventDataBinding = new object();
internal static readonly object EventInit = new object();
internal static readonly object EventLoad = new object();
internal static readonly object EventUnload = new object();
internal static readonly object EventPreRender = new object();
private static readonly object EventDisposed = new object();
internal const bool EnableViewStateDefault = true;
internal const char ID_SEPARATOR = '$';
private const char ID_RENDER_SEPARATOR = '_';
internal const char LEGACY_ID_SEPARATOR = ':';
private string _id;
// allows us to reuse the id variable to store a calculated id w/o polluting the public getter
private string _cachedUniqueID;
private string _cachedPredictableID;
private Control _parent;
// fields related to being a container
private ControlState _controlState;
private StateBag _viewState;
private EventHandlerList _events;
private ControlCollection _controls;
// The naming container that this control leaves in. Note that even if
// this ctrl is a naming container, it will not point to itself, but to
// the naming container that contains it.
private Control _namingContainer;
internal Page _page;
private OccasionalFields _occasionalFields;
// The virtual directory of the Page or UserControl that hosts this control.
// const masks into the BitVector32
private const int idNotCalculated = 0x00000001;
private const int marked = 0x00000002;
private const int disableViewState = 0x00000004;
private const int controlsCreated = 0x00000008;
private const int invisible = 0x00000010;
private const int visibleDirty = 0x00000020;
private const int idNotRequired = 0x00000040;
private const int isNamingContainer = 0x00000080;
private const int creatingControls = 0x00000100;
private const int notVisibleOnPage = 0x00000200;
private const int themeApplied = 0x00000400;
private const int mustRenderID = 0x00000800;
private const int disableTheming = 0x00001000;
private const int enableThemingSet = 0x00002000;
private const int styleSheetApplied = 0x00004000;
private const int controlAdapterResolved = 0x00008000;
private const int designMode = 0x00010000;
private const int designModeChecked = 0x00020000;
private const int disableChildControlState = 0x00040000;
internal const int isWebControlDisabled = 0x00080000;
private const int controlStateApplied = 0x00100000;
private const int useGeneratedID = 0x00200000;
private const int validateRequestModeDirty = 0x00400000;
private const int viewStateNotInherited = 0x00800000;
private const int viewStateMode = 0x01000000;
private const int clientIDMode = 0x06000000;
private const int clientIDModeOffset = 25;
private const int effectiveClientIDMode = 0x18000000;
private const int effectiveClientIDModeOffset = 27;
private const int validateRequestMode = 0x60000000;
private const int validateRequestModeOffset = 29;
#pragma warning disable 0649
internal SimpleBitVector32 flags;
#pragma warning restore 0649
private const string automaticIDPrefix = "ctl";
private const string automaticLegacyIDPrefix = "_ctl";
private const int automaticIDCount = 128;
private static readonly string[] automaticIDs = new string [automaticIDCount] {
"ctl00", "ctl01", "ctl02", "ctl03", "ctl04", "ctl05", "ctl06",
"ctl07", "ctl08", "ctl09", "ctl10", "ctl11", "ctl12", "ctl13",
"ctl14", "ctl15", "ctl16", "ctl17", "ctl18", "ctl19", "ctl20",
"ctl21", "ctl22", "ctl23", "ctl24", "ctl25", "ctl26", "ctl27",
"ctl28", "ctl29", "ctl30", "ctl31", "ctl32", "ctl33", "ctl34",
"ctl35", "ctl36", "ctl37", "ctl38", "ctl39", "ctl40", "ctl41",
"ctl42", "ctl43", "ctl44", "ctl45", "ctl46", "ctl47", "ctl48",
"ctl49", "ctl50", "ctl51", "ctl52", "ctl53", "ctl54", "ctl55",
"ctl56", "ctl57", "ctl58", "ctl59", "ctl60", "ctl61", "ctl62",
"ctl63", "ctl64", "ctl65", "ctl66", "ctl67", "ctl68", "ctl69",
"ctl70", "ctl71", "ctl72", "ctl73", "ctl74", "ctl75", "ctl76",
"ctl77", "ctl78", "ctl79", "ctl80", "ctl81", "ctl82", "ctl83",
"ctl84", "ctl85", "ctl86", "ctl87", "ctl88", "ctl89", "ctl90",
"ctl91", "ctl92", "ctl93", "ctl94", "ctl95", "ctl96", "ctl97",
"ctl98", "ctl99",
"ctl100", "ctl101", "ctl102", "ctl103", "ctl104", "ctl105", "ctl106",
"ctl107", "ctl108", "ctl109", "ctl110", "ctl111", "ctl112", "ctl113",
"ctl114", "ctl115", "ctl116", "ctl117", "ctl118", "ctl119", "ctl120",
"ctl121", "ctl122", "ctl123", "ctl124", "ctl125", "ctl126", "ctl127"
};
/// <devdoc>
/// <para>Initializes a new instance of the <see cref='System.Web.UI.Control'/> class.</para>
/// </devdoc>
public Control() {
if (this is INamingContainer)
flags.Set(isNamingContainer);
}
private ClientIDMode ClientIDModeValue {
get {
return (ClientIDMode)flags[clientIDMode, clientIDModeOffset];
}
set {
flags[clientIDMode, clientIDModeOffset] = (int)value;
}
}
[SuppressMessage("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase", MessageId="Member")]
[
DefaultValue(ClientIDMode.Inherit),
Themeable(false),
WebCategory("Behavior"),
WebSysDescription(SR.Control_ClientIDMode)
]
public virtual ClientIDMode ClientIDMode {
get {
return ClientIDModeValue;
}
set {
if (ClientIDModeValue != value) {
if (value != EffectiveClientIDModeValue) {
ClearEffectiveClientIDMode();
ClearCachedClientID();
}
ClientIDModeValue = value;
}
}
}
private ClientIDMode EffectiveClientIDModeValue {
get {
return (ClientIDMode)flags[effectiveClientIDMode, effectiveClientIDModeOffset];
}
set {
flags[effectiveClientIDMode, effectiveClientIDModeOffset] = (int)value;
}
}
internal virtual ClientIDMode EffectiveClientIDMode {
get {
if (EffectiveClientIDModeValue == ClientIDMode.Inherit) {
EffectiveClientIDModeValue = ClientIDMode;
if (EffectiveClientIDModeValue == ClientIDMode.Inherit) {
if (NamingContainer != null) {
EffectiveClientIDModeValue = NamingContainer.EffectiveClientIDMode;
}
else {
HttpContext context = Context;
if (context != null) {
EffectiveClientIDModeValue = RuntimeConfig.GetConfig(context).Pages.ClientIDMode;
}
else {
EffectiveClientIDModeValue = RuntimeConfig.GetConfig().Pages.ClientIDMode;
}
}
}
}
return EffectiveClientIDModeValue;
}
}
internal string UniqueClientID {
get {
string uniqueID = UniqueID;
if(uniqueID != null && uniqueID.IndexOf(IdSeparator) >= 0) {
return uniqueID.Replace(IdSeparator, ID_RENDER_SEPARATOR);
}
return uniqueID;
}
}
internal string StaticClientID {
get {
return flags[useGeneratedID] ? String.Empty : ID ?? String.Empty;
}
}
internal ControlAdapter AdapterInternal {
get {
if (_occasionalFields == null ||
_occasionalFields.RareFields == null ||
_occasionalFields.RareFields.Adapter == null) {
return null;
}
return _occasionalFields.RareFields.Adapter;
}
set {
if (value != null) {
RareFieldsEnsured.Adapter = value;
}
else {
if (_occasionalFields != null &&
_occasionalFields.RareFields != null &&
_occasionalFields.RareFields.Adapter != null) {
_occasionalFields.RareFields.Adapter = null;
}
}
}
}
private string GetClientID() {
switch (EffectiveClientIDMode) {
case ClientIDMode.Predictable:
return PredictableClientID;
case ClientIDMode.Static:
return StaticClientID;
default:
return UniqueClientID;
}
}
private string GetPredictableClientIDPrefix() {
string predictableIDPrefix;
Control namingContainer = NamingContainer;
if (namingContainer != null) {
if (_id == null) {
GenerateAutomaticID();
}
if (namingContainer is Page || namingContainer is MasterPage) {
predictableIDPrefix = _id;
}
else {
predictableIDPrefix = namingContainer.GetClientID();
if (String.IsNullOrEmpty(predictableIDPrefix)) {
predictableIDPrefix = _id;
}
else {
if (!String.IsNullOrEmpty(_id) && (!(this is IDataItemContainer) || (this is IDataBoundItemControl))) {
predictableIDPrefix = predictableIDPrefix + ID_RENDER_SEPARATOR + _id;
}
}
}
}
else {
predictableIDPrefix = _id;
}
return predictableIDPrefix;
}
private string GetPredictableClientIDSuffix() {
string predictableIDSuffix = null;
Control dataItemContainer = DataItemContainer;
if (dataItemContainer != null &&
!(dataItemContainer is IDataBoundItemControl) &&
(!(this is IDataItemContainer) || (this is IDataBoundItemControl))) {
Control dataKeysContainer = dataItemContainer.DataKeysContainer;
if (dataKeysContainer != null && (((IDataKeysControl)dataKeysContainer).ClientIDRowSuffix != null) && (((IDataKeysControl)dataKeysContainer).ClientIDRowSuffix.Length > 0)) {
predictableIDSuffix = String.Empty;
IOrderedDictionary dataKey = ((IDataKeysControl)dataKeysContainer).ClientIDRowSuffixDataKeys[((IDataItemContainer)dataItemContainer).DisplayIndex].Values;
foreach (string suffixName in ((IDataKeysControl)dataKeysContainer).ClientIDRowSuffix) {
predictableIDSuffix = predictableIDSuffix + ID_RENDER_SEPARATOR + dataKey[suffixName].ToString();
}
}
else {
int index = ((IDataItemContainer)dataItemContainer).DisplayIndex;
if (index >= 0) {
predictableIDSuffix = ID_RENDER_SEPARATOR + index.ToString(CultureInfo.InvariantCulture);
}
}
}
return predictableIDSuffix;
}
internal string PredictableClientID {
get {
if (_cachedPredictableID != null) {
return _cachedPredictableID;
}
_cachedPredictableID = GetPredictableClientIDPrefix();
string suffixID = GetPredictableClientIDSuffix();
// Concatenates Predictable clientID and ClientIDRowSuffix if available
if (!String.IsNullOrEmpty(suffixID)) {
if (!String.IsNullOrEmpty(_cachedPredictableID)) {
_cachedPredictableID = _cachedPredictableID + suffixID;
}
else {
_cachedPredictableID = suffixID.Substring(1);
}
}
return String.IsNullOrEmpty(_cachedPredictableID) ? String.Empty : _cachedPredictableID;
}
}
/// <devdoc>
/// <para>Indicates the control identifier generated by the ASP.NET framework. </para>
/// </devdoc>
[
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
WebSysDescription(SR.Control_ClientID)
]
public virtual string ClientID {
// This property is required to render a unique client-friendly id.
get {
if (EffectiveClientIDMode != ClientIDMode.Static) {
// Ensure that ID is set. The assumption being made is that the caller
// is likely to use the client ID in script, and to support that the
// control should render out an ID attribute
EnsureID();
}
return GetClientID();
}
}
protected char ClientIDSeparator {
get {
return ID_RENDER_SEPARATOR;
}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
[
WebSysDescription(SR.Control_OnDisposed)
]
public event EventHandler Disposed {
add {
Events.AddHandler(EventDisposed, value);
}
remove {
Events.RemoveHandler(EventDisposed, value);
}
}
/// <devdoc>
/// <para>Gets the <see langword='HttpContext'/> object of the current Web request. If
/// the control's context is <see langword='null'/>, this will be the context of the
/// control's parent, unless the parent control's context is <see langword='null'/>.
/// If this is the case, this will be equal to the HttpContext property.</para>
/// </devdoc>
[
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
]
protected internal virtual HttpContext Context {
// Request context containing the intrinsics
get {
Page page = Page;
if(page != null) {
return page.Context;
}
return HttpContext.Current;
}
}
protected virtual ControlAdapter ResolveAdapter() {
if(flags[controlAdapterResolved]) {
return AdapterInternal;
}
if (DesignMode) {
flags.Set(controlAdapterResolved);
return null;
}
HttpContext context = Context;
if (context != null && context.Request.Browser != null) {
AdapterInternal = context.Request.Browser.GetAdapter(this);
}
flags.Set(controlAdapterResolved);
return AdapterInternal;
}
/// <devdoc>
/// <para>Indicates the list of event handler delegates for the control. This property
/// is read-only.</para>
/// </devdoc>
protected ControlAdapter Adapter {
get {
if(flags[controlAdapterResolved]) {
return AdapterInternal;
}
AdapterInternal = ResolveAdapter();
flags.Set(controlAdapterResolved);
return AdapterInternal;
}
}
/// <devdoc>
/// Indicates whether a control is being used in the context of a design surface.
/// </devdoc>
protected internal bool DesignMode {
get {
if(!flags[designModeChecked]) {
Page page = Page;
if(page != null ) {
if(page.GetDesignModeInternal()) {
flags.Set(designMode);
}
else {
flags.Clear(designMode);
}
}
else {
if(Site != null) {
if(Site.DesignMode) {
flags.Set(designMode);
}
else {
flags.Clear(designMode);
}
}
else if (Parent != null) {
if(Parent.DesignMode) {
flags.Set(designMode);
}
// VSWhidbey 535747: If Page, Site and Parent are all null, do not change the
// designMode flag since it might had been previously set by the controlBuilder.
// This does not affect runtime since designMode is by-default false.
/*
else {
flags.Clear(designMode);
}
*/
}
}
flags.Set(designModeChecked);
}
return flags[designMode];
}
}
// Helper function to call validateEvent.
internal void ValidateEvent(string uniqueID) {
ValidateEvent(uniqueID, String.Empty);
}
// Helper function to call validateEvent.
internal void ValidateEvent(string uniqueID, string eventArgument) {
if (Page != null && SupportsEventValidation) {
Page.ClientScript.ValidateEvent(uniqueID, eventArgument);
}
}
// Indicates whether the control supports event validation
// By default, all web controls in System.Web assembly supports it but not custom controls.
private bool SupportsEventValidation {
get {
return SupportsEventValidationAttribute.SupportsEventValidation(this.GetType());
}
}
/// <devdoc>
/// <para>Indicates the list of event handler delegates for the control. This property
/// is read-only.</para>
/// </devdoc>
protected EventHandlerList Events {
get {
if (_events == null) {
_events = new EventHandlerList();
}
return _events;
}
}
protected bool HasEvents() {
return (_events != null);
}
/// <devdoc>
/// <para> Gets or sets the identifier for the control. Setting the
/// property on a control allows programmatic access to the control's properties. If
/// this property is not specified on a control, either declaratively or
/// programmatically, then you cannot write event handlers and the like for the control.</para>
/// </devdoc>
[
ParenthesizePropertyName(true),
MergableProperty(false),
Filterable(false),
Themeable(false),
WebSysDescription(SR.Control_ID)
]
public virtual string ID {
get {
if (!flags[idNotCalculated] && !flags[mustRenderID]) {
return null;
}
return _id;
}
set {
// allow the id to be unset
if (value != null && value.Length == 0)
value = null;
string oldID = _id;
_id = value;
ClearCachedUniqueIDRecursive();
flags.Set(idNotCalculated);
flags.Clear(useGeneratedID);
// Update the ID in the naming container
if ((_namingContainer != null) && (oldID != null)) {
_namingContainer.DirtyNameTable();
}
if (oldID != null && oldID != _id) {
ClearCachedClientID();
}
}
}
/// <devdoc>
/// <para>Gets and sets a value indicating whether theme is enabled.</para>
/// </devdoc>
[
Browsable(false),
DefaultValue(true),
Themeable(false),
WebCategory("Behavior"),
WebSysDescription(SR.Control_EnableTheming)
]
public virtual bool EnableTheming {
get {
if (flags[enableThemingSet]) {
return !flags[disableTheming];
}
if (Parent != null) {
return Parent.EnableTheming;
}
return !flags[disableTheming];
}
set {
if ((_controlState >= ControlState.FrameworkInitialized) && !DesignMode) {
throw new InvalidOperationException(SR.GetString(SR.PropertySetBeforePreInitOrAddToControls, "EnableTheming"));
}
if(!value) {
flags.Set(disableTheming);
}
else {
flags.Clear(disableTheming);
}
flags.Set(enableThemingSet);
}
}
// Serialzie the value if it's set explicitely.
internal bool ShouldSerializeEnableTheming() {
return flags[enableThemingSet];;
}
internal bool IsBindingContainer {
get {
return this is INamingContainer && !(this is INonBindingContainer);
}
}
protected internal bool IsChildControlStateCleared {
get {
return flags[disableChildControlState];
}
}
/// <devdoc>
/// <para>Gets and sets the skinID of the control.</para>
/// </devdoc>
[
Browsable(false),
DefaultValue(""),
Filterable(false),
WebCategory("Behavior"),
WebSysDescription(SR.Control_SkinId),
]
public virtual string SkinID {
get {
if(_occasionalFields != null) {
return _occasionalFields.SkinId == null ? String.Empty : _occasionalFields.SkinId;
}
return String.Empty;
}
set {
if (!DesignMode) {
if (flags[styleSheetApplied]) {
throw new InvalidOperationException(SR.GetString(SR.PropertySetBeforeStyleSheetApplied, "SkinId"));
}
if (_controlState >= ControlState.FrameworkInitialized) {
throw new InvalidOperationException(SR.GetString(SR.PropertySetBeforePreInitOrAddToControls, "SkinId"));
}
}
EnsureOccasionalFields();
_occasionalFields.SkinId = value;
}
}
private ControlRareFields RareFieldsEnsured {
get {
EnsureOccasionalFields();
ControlRareFields rareFields = _occasionalFields.RareFields;
if(rareFields == null) {
rareFields = new ControlRareFields();
_occasionalFields.RareFields = rareFields;
}
return rareFields;
}
}
private ControlRareFields RareFields {
get {
if(_occasionalFields != null) {
return _occasionalFields.RareFields;
}
return null;
}
}
private void EnsureOccasionalFields() {
if(_occasionalFields == null) {
_occasionalFields = new OccasionalFields();
}
}
/// <devdoc>
/// <para>
/// Gets or sets a value indicating whether the control should maintain its view
/// state, and the view state of any child control in contains, when the current
/// page request ends.
/// </para>
/// </devdoc>
[
DefaultValue(EnableViewStateDefault),
Themeable(false),
WebCategory("Behavior"),
WebSysDescription(SR.Control_MaintainState)
]
public virtual bool EnableViewState {
get {
return !flags[disableViewState];
}
set {
SetEnableViewStateInternal(value);
}
}
[
DefaultValue(ViewStateMode.Inherit),
Themeable(false),
WebCategory("Behavior"),
WebSysDescription(SR.Control_ViewStateMode)
]
public virtual ViewStateMode ViewStateMode {
get {
return flags[viewStateNotInherited] ?
(flags[viewStateMode] ? ViewStateMode.Enabled : ViewStateMode.Disabled) :
ViewStateMode.Inherit;
}
set {
if ((value < ViewStateMode.Inherit) || (value > ViewStateMode.Disabled)) {
throw new ArgumentOutOfRangeException("value");
}
if (value == ViewStateMode.Inherit) {
flags.Clear(viewStateNotInherited);
}
else {
flags.Set(viewStateNotInherited);
if (value == ViewStateMode.Enabled) {
flags.Set(viewStateMode);
}
else {
flags.Clear(viewStateMode);
}
}
}
}
internal void SetEnableViewStateInternal(bool value) {
if (!value)
flags.Set(disableViewState);
else
flags.Clear(disableViewState);
}
/// <devdoc>
/// Gets a value indicating whether the control is maintaining its view
/// state, when the current page request ends by looking at its own EnableViewState
/// value, and the value for all its parents.
/// </devdoc>
protected internal bool IsViewStateEnabled {
get {
Control current = this;
while (current != null) {
if (current.EnableViewState == false) {
return false;
}
ViewStateMode mode = current.ViewStateMode;
if (mode != ViewStateMode.Inherit) {
return (mode == ViewStateMode.Enabled);
}
current = current.Parent;
}
return true;
}
}
/// <devdoc>
/// <para>Gets the reference to the current control's naming container.</para>
/// </devdoc>
[
Bindable(false),
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
WebSysDescription(SR.Control_NamingContainer)
]
public virtual Control NamingContainer {
get {
if (_namingContainer == null) {
if (Parent != null) {
// Search for the closest naming container in the tree
if (Parent.flags[isNamingContainer])
_namingContainer = Parent;
else
_namingContainer = Parent.NamingContainer;
}
}
return _namingContainer;
}
}
/// <internalonly/>
/// <devdoc>
/// <para>Returns the databinding container of this control. In most cases,
/// this is the same as the NamingContainer. But when using LoadTemplate(),
/// we get into a situation where that is not the case (ASURT 94138)</para>
/// The behavior is different than V1 that Usercontrol.BindingContainer is no
/// longer the UserControl but the control contains it. The behavior is consistent
/// with LoadTemplate() case.
/// </devdoc>
[
Bindable(false),
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
EditorBrowsable(EditorBrowsableState.Never)
]
public Control BindingContainer {
get {
Control bindingContainer = NamingContainer;
while (bindingContainer is INonBindingContainer) {
bindingContainer = bindingContainer.BindingContainer;
}
return bindingContainer;
}
}
[
Bindable(false),
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
EditorBrowsable(EditorBrowsableState.Never)
]
public Control DataItemContainer {
get {
Control dataItemContainer = NamingContainer;
while (dataItemContainer != null && !(dataItemContainer is IDataItemContainer)) {
dataItemContainer = dataItemContainer.DataItemContainer;
}
return dataItemContainer;
}
}
[
Bindable(false),
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
EditorBrowsable(EditorBrowsableState.Never)
]
public Control DataKeysContainer {
get {
Control dataKeysContainer = NamingContainer;
while (dataKeysContainer != null && !(dataKeysContainer is IDataKeysControl)) {
dataKeysContainer = dataKeysContainer.DataKeysContainer;
}
return dataKeysContainer;
}
}
/// <internalonly/>
/// <devdoc>
/// VSWhidbey 80467: Need to adapt id separator.
/// </devdoc>
protected char IdSeparator {
get {
if (Page != null) {
return Page.IdSeparator;
}
return IdSeparatorFromConfig;
}
}
// VSWhidbey 475945: Use the old id separator if configured
internal char IdSeparatorFromConfig {
get {
return ((EnableLegacyRendering) ? LEGACY_ID_SEPARATOR : ID_SEPARATOR);
}
}
// VSWhidbey 244374: Allow controls to opt into loading view state by ID instead of index (perf hit)
protected bool LoadViewStateByID {
get {
return ViewStateModeByIdAttribute.IsEnabled(GetType());
}
}
/// <devdoc>
/// <para> Gets the <see cref='System.Web.UI.Page'/> object that contains the
/// current control.</para>
/// </devdoc>
[
Bindable(false),
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
WebSysDescription(SR.Control_Page)
]
public virtual Page Page {
get {
if (_page == null) {
if (Parent != null) {
_page = Parent.Page;
}
}
return _page;
}
set {
if (OwnerControl != null) {
throw new InvalidOperationException();
}
// This is necessary because we need to set the page in generated
// code before controls are added to the tree (ASURT 75330)
Debug.Assert(_page == null);
Debug.Assert(Parent == null || Parent.Page == null);
_page = value;
}
}
internal RouteCollection RouteCollection {
get {
if (_occasionalFields == null ||
_occasionalFields.RareFields == null ||
_occasionalFields.RareFields.RouteCollection == null) {
return RouteTable.Routes;
}
return _occasionalFields.RareFields.RouteCollection;
}
set {
if (value != null) {
RareFieldsEnsured.RouteCollection = value;
}
else {
if (_occasionalFields != null &&
_occasionalFields.RareFields != null &&
_occasionalFields.RareFields.RouteCollection != null) {
_occasionalFields.RareFields.RouteCollection = null;
}
}
}
}
// VSWhidbey 244999
internal virtual bool IsReloadable {
get {
return false;
}
}
// DevDiv 33149, 43258: A backward compat. switch for Everett rendering
internal bool EnableLegacyRendering {
get {
Page page = Page;
if (page != null) {
return (page.XhtmlConformanceMode == XhtmlConformanceMode.Legacy);
}
else if (DesignMode || Adapter != null) {
return false;
}
else {
return (GetXhtmlConformanceSection().Mode == XhtmlConformanceMode.Legacy);
}
}
}
internal XhtmlConformanceSection GetXhtmlConformanceSection() {
HttpContext context = Context;
XhtmlConformanceSection xhtmlConformanceSection;
if (context != null) {
// if context is available, use the most efficient way to get the section
xhtmlConformanceSection = RuntimeConfig.GetConfig(context).XhtmlConformance;
}
else {
xhtmlConformanceSection = RuntimeConfig.GetConfig().XhtmlConformance;
}
Debug.Assert(xhtmlConformanceSection != null);
return xhtmlConformanceSection;
}
[
Bindable(false),
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
]
public virtual Version RenderingCompatibility {
get {
if (_occasionalFields == null ||
_occasionalFields.RareFields == null ||
_occasionalFields.RareFields.RenderingCompatibility == null) {
return RuntimeConfig.Pages.ControlRenderingCompatibilityVersion;
}
return _occasionalFields.RareFields.RenderingCompatibility;
}
set {
if (value != null) {
RareFieldsEnsured.RenderingCompatibility = value;
}
else {
if (_occasionalFields != null &&
_occasionalFields.RareFields != null &&
_occasionalFields.RareFields.RenderingCompatibility != null) {
_occasionalFields.RareFields.RenderingCompatibility = null;
}
}
}
}