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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591
|
//------------------------------------------------------------------------------
// <copyright file="MobilePage.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Web.SessionState;
using System.Web.Mobile;
using System.Web.Security;
using System.Web.Util;
using System.Security.Permissions;
namespace System.Web.UI.MobileControls
{
/*
* Mobile page class.
* The page will use device id to create the appropriate DeviceAdapter,
* and then delegate all major functions to the adapter.
*
* THE MOBILE PAGE CLASS DOES NOT CONTAIN DEVICE-SPECIFIC CODE.
*
* All mobile aspx pages MUST extend from this using page inherit directive:
* <%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="cs" %>
*
* Copyright (c) 2000 Microsoft Corporation
*/
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage"]/*' />
[
Designer("Microsoft.VisualStudio.Web.WebForms.MobileWebFormDesigner, " + AssemblyRef.MicrosoftVisualStudioWeb, typeof(IRootDesigner)),
ToolboxItem(false)
]
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
public class MobilePage : Page
{
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.HiddenPostEventSourceId"]/*' />
public static readonly String HiddenPostEventSourceId = postEventSourceID;
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.HiddenPostEventArgumentId"]/*' />
public static readonly String HiddenPostEventArgumentId = postEventArgumentID;
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.ViewStateID"]/*' />
public static readonly String ViewStateID = "__VIEWSTATE";
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.HiddenVariablePrefix"]/*' />
public static readonly String HiddenVariablePrefix = "__V_";
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.PageClientViewStateKey"]/*' />
public static readonly String PageClientViewStateKey = "__P";
private const String DesignerAdapter = "System.Web.UI.MobileControls.Adapters.HtmlPageAdapter";
private IPageAdapter _pageAdapter;
private bool _debugMode = false;
private StyleSheet _styleSheet = null;
private IDictionary _hiddenVariables;
private Hashtable _clientViewState;
private String _eventSource;
private Hashtable _privateViewState = new Hashtable();
bool _privateViewStateLoaded = false;
private NameValueCollection _requestValueCollection;
private bool _isRenderingInForm = false;
private bool _afterPreInit;
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.AddParsedSubObject"]/*' />
protected override void AddParsedSubObject(Object o)
{
// Note : AddParsedSubObject is never called at DesignTime
if (o is StyleSheet)
{
if (_styleSheet != null)
{
throw new
Exception(SR.GetString(SR.StyleSheet_DuplicateWarningMessage));
}
else
{
_styleSheet = (StyleSheet)o;
}
}
base.AddParsedSubObject(o);
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.Device"]/*' />
[
Browsable(false),
Bindable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
]
public virtual MobileCapabilities Device
{
get
{
if (DesignMode)
{
return new
System.Web.UI.Design.MobileControls.DesignerCapabilities();
}
return (MobileCapabilities)Request.Browser;
}
}
[
Browsable(false),
Bindable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
EditorBrowsable(EditorBrowsableState.Advanced)
]
public override sealed string MasterPageFile {
get {
return null;
}
set {
if (_afterPreInit) {
throw new NotSupportedException(SR.GetString(SR.Feature_Not_Supported_On_MobilePage, "MasterPage"));
}
}
}
// EventValidation is not supported on a mobile page.
public override bool EnableEventValidation {
get {
return false;
}
set {
if (_afterPreInit && value) {
throw new NotSupportedException(SR.GetString(SR.Feature_Not_Supported_On_MobilePage, "EventValidation"));
}
}
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.StyleSheet"]/*' />
[
Browsable(false),
Bindable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
]
public StyleSheet StyleSheet
{
get
{
return (_styleSheet != null) ? _styleSheet : StyleSheet.Default;
}
set
{
_styleSheet = value;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
public override String Theme {
get {
return base.Theme;
}
set {
if (_afterPreInit) {
throw new NotSupportedException(SR.GetString(SR.Feature_Not_Supported_On_MobilePage, "Theme"));
}
}
}
[
Bindable(false),
Localizable(false),
EditorBrowsable(EditorBrowsableState.Never),
]
public new String Title {
get {
return String.Empty;
}
set {
throw new NotSupportedException(SR.GetString(SR.Feature_Not_Supported_On_MobilePage, "Title"));
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
public override String StyleSheetTheme {
get {
return base.StyleSheetTheme;
}
set {
if (_afterPreInit) {
throw new NotSupportedException(SR.GetString(SR.Feature_Not_Supported_On_MobilePage, "StyleSheetTheme"));
}
}
}
[
Browsable(false),
EditorBrowsable(EditorBrowsableState.Advanced)
]
public override bool EnableTheming {
get {
return base.EnableTheming;
}
set {
throw new NotSupportedException(SR.GetString(SR.Feature_Not_Supported_On_MobilePage, "Theme"));
}
}
private IList _forms;
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.Forms"]/*' />
[
Browsable(false),
Bindable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
]
public IList Forms
{
get
{
if (_forms == null)
{
int probableFormCount = Controls.Count / 2; // since there are literal controls between each
_forms = new ArrayList(probableFormCount);
AddForms(this);
}
return _forms;
}
}
private void AddForms(Control parent)
{
foreach (Control control in parent.Controls)
{
if (control is Form)
{
_forms.Add(control);
}
else if (control is UserControl)
{
AddForms(control);
}
}
}
private enum RunMode
{
Unknown,
Design,
Runtime,
};
private RunMode _runMode = RunMode.Unknown;
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.DesignMode"]/*' />
[
Browsable(false),
Bindable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
EditorBrowsable(EditorBrowsableState.Never),
]
public new bool DesignMode
{
get
{
if (_runMode == RunMode.Unknown)
{
_runMode = RunMode.Runtime;
try
{
_runMode = (HttpContext.Current == null) ? RunMode.Design : RunMode.Runtime;
}
catch
{
_runMode = RunMode.Design;
}
}
return _runMode == RunMode.Design;
}
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.Adapter"]/*' />
[
Browsable(false),
Bindable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
]
public new IPageAdapter Adapter
{
get
{
if (_pageAdapter == null)
{
IPageAdapter pageAdapter = RequestingDeviceConfig.NewPageAdapter();
pageAdapter.Page = this;
_pageAdapter = pageAdapter;
if(!DesignMode)
{
Type t = ControlsConfig.GetFromContext(HttpContext.Current).CookielessDataDictionaryType;
if(t != null && typeof(IDictionary).IsAssignableFrom(t))
{
pageAdapter.CookielessDataDictionary = Activator.CreateInstance(t) as IDictionary;
pageAdapter.PersistCookielessData = true;
}
}
}
return _pageAdapter;
}
}
private bool _haveIdSeparator;
private char _idSeparator;
public override char IdSeparator {
get {
if (_haveIdSeparator) {
return _idSeparator;
}
_haveIdSeparator = true;
IPageAdapter pageAdapter = Adapter;
Debug.Assert(pageAdapter != null);
// VSWhidbey 280485
if (pageAdapter is System.Web.UI.MobileControls.Adapters.WmlPageAdapter ||
pageAdapter is System.Web.UI.MobileControls.Adapters.XhtmlAdapters.XhtmlPageAdapter) {
_idSeparator = ':';
}
else {
_idSeparator = base.IdSeparator;
}
return _idSeparator;
}
}
String _clientViewStateString;
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.ClientViewState"]/*' />
[
Browsable(false),
Bindable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
]
public String ClientViewState
{
get
{
if (_clientViewState == null || _clientViewState.Count == 0)
{
return null;
}
if (_clientViewStateString == null)
{
StringWriter writer = new StringWriter(CultureInfo.InvariantCulture);
StateFormatter.Serialize(writer, _clientViewState);
_clientViewStateString = writer.ToString();
}
return _clientViewStateString;
}
}
private BooleanOption _allowCustomAttributes = BooleanOption.NotSet;
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.AllowCustomAttributes"]/*' />
[
Browsable(false),
Bindable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
]
public bool AllowCustomAttributes
{
get
{
if (DesignMode)
{
return false;
}
if (_allowCustomAttributes == BooleanOption.NotSet)
{
_allowCustomAttributes =
ControlsConfig.GetFromContext(Context).AllowCustomAttributes ?
BooleanOption.True : BooleanOption.False;
}
return _allowCustomAttributes == BooleanOption.True;
}
set
{
_allowCustomAttributes = value ? BooleanOption.True : BooleanOption.False;
}
}
private void AddClientViewState(String id, Object viewState)
{
if (_clientViewState == null)
{
_clientViewState = new Hashtable();
}
_clientViewState[id] = viewState;
_clientViewStateString = null;
}
internal void AddClientViewState(MobileControl control, Object viewState)
{
AddClientViewState(control.UniqueID, viewState);
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.GetControlAdapter"]/*' />
public virtual IControlAdapter GetControlAdapter(MobileControl control)
{
IControlAdapter adapter = RequestingDeviceConfig.NewControlAdapter(control.GetType ());
adapter.Control = control;
return adapter;
}
private IndividualDeviceConfig _deviceConfig = null;
private IndividualDeviceConfig RequestingDeviceConfig
{
get
{
if (_deviceConfig == null)
{
if (DesignMode)
{
_deviceConfig = new DesignerDeviceConfig(DesignerAdapter);
}
else
{
_deviceConfig =
ControlsConfig.GetFromContext(Context).GetDeviceConfig(Context);
}
}
return _deviceConfig;
}
}
private String _appPath;
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.MakePathAbsolute"]/*' />
public String MakePathAbsolute(String virtualPath)
{
if (virtualPath == null || virtualPath.Length == 0)
{
return virtualPath;
}
if (!UrlPath.IsRelativeUrl(virtualPath))
{
// For consistency with ResolveUrl, do not apply app path modifier to rooted paths.
//return Response.ApplyAppPathModifier(virtualPath);
return virtualPath;
}
else
{
if (_appPath == null)
{
String path = Request.CurrentExecutionFilePath;
path = Response.ApplyAppPathModifier(path);
int slash = path.LastIndexOf('/');
if (slash != -1)
{
path = path.Substring(0, slash);
}
if (path.IndexOf(' ') != -1)
{
path = path.Replace(" ", "%20");
}
_appPath = path;
}
virtualPath = UrlPath.Combine(_appPath, virtualPath);
return virtualPath;
}
}
private String _relativeFilePath;
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.RelativeFilePath"]/*' />
[
Browsable(false),
]
public String RelativeFilePath
{
get
{
// Vs7 Property sig will always try to access public properties with get methods no
// matter Brosable attribute is off or not. We need to check if is DesignMode in
// order to prevent the exception from vs7 at design time.
if (DesignMode)
{
return String.Empty;
}
if (_relativeFilePath == null)
{
String s = Context.Request.CurrentExecutionFilePath;
String filePath = Context.Request.FilePath;
if(filePath.Equals(s))
{
int slash = s.LastIndexOf('/');
if (slash >= 0)
{
s = s.Substring(slash+1);
}
_relativeFilePath = s;
}
else
{
_relativeFilePath = Server.UrlDecode(UrlPath.MakeRelative(filePath, s));
}
}
return _relativeFilePath;
}
}
private String _absoluteFilePath;
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.AbsoluteFilePath"]/*' />
[
Browsable(false),
]
public String AbsoluteFilePath
{
get
{
// Vs7 Property sig will always try to access public properties with get methods no
// matter Brosable attribute is off or not. We need to check if Context is null in
// order to prevent the exception from vs7 at design time.
if (_absoluteFilePath == null && Context != null)
{
_absoluteFilePath = Response.ApplyAppPathModifier(Context.Request.CurrentExecutionFilePath);
}
return _absoluteFilePath;
}
}
private String _uniqueFilePathSuffix;
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.UniqueFilePathSuffix"]/*' />
[
Browsable(false),
]
public new String UniqueFilePathSuffix
{
// Required for browsers that don't properly handle
// self-referential form posts.
get
{
if (_uniqueFilePathSuffix == null)
{
// Only need a few digits, so save space by modulo'ing by a prime.
// The chosen prime is the highest of six digits.
long ticks = DateTime.Now.Ticks % 999983;
_uniqueFilePathSuffix = String.Concat(
Constants.UniqueFilePathSuffixVariable,
ticks.ToString("D6", CultureInfo.InvariantCulture));
}
return _uniqueFilePathSuffix;
}
}
private static String RemoveQueryStringElement(String queryStringText, String elementName)
{
int n = elementName.Length;
int i = 0;
for (i = 0; i < queryStringText.Length;)
{
i = queryStringText.IndexOf(elementName, i, StringComparison.Ordinal);
if (i < 0)
{
break;
}
if (i == 0 || queryStringText[i-1] == '&')
{
if (i+n < queryStringText.Length && queryStringText[i+n] == '=')
{
int j = queryStringText.IndexOf('&', i+n);
if (j < 0)
{
if (i == 0)
{
queryStringText = String.Empty;
}
else
{
queryStringText = queryStringText.Substring(0, i-1);
}
break;
}
else
{
queryStringText = queryStringText.Remove(i, j-i+1);
continue;
}
}
}
i += n;
}
return queryStringText;
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.QueryStringText"]/*' />
[
Browsable(false),
]
public String QueryStringText
{
// Returns the query string text, stripping off a unique file path
// suffix as required. Also assumes that if the suffix is
// present, the query string part is the text after it.
get
{
// Vs7 Property sig will always try to access public properties with get methods no
// matter Brosable attribute is off or not. We need to check if Context is null in
// order to prevent the exception from vs7 at design time.
if(DesignMode)
{
return String.Empty;
}
String fullQueryString;
if (Request.HttpMethod != "POST")
{
fullQueryString = CreateQueryStringTextFromCollection(Request.QueryString);
}
else if (Device.SupportsQueryStringInFormAction)
{
fullQueryString = Request.ServerVariables["QUERY_STRING"];
}
else
{
fullQueryString = CreateQueryStringTextFromCollection(_requestValueCollection);
}
if(fullQueryString != null && fullQueryString.Length > 0)
{
fullQueryString = RemoveQueryStringElement(fullQueryString, Constants.UniqueFilePathSuffixVariableWithoutEqual);
fullQueryString = RemoveQueryStringElement(fullQueryString, MobileRedirect.QueryStringVariable);
if (!Adapter.PersistCookielessData)
{
fullQueryString = RemoveQueryStringElement(fullQueryString, FormsAuthentication.FormsCookieName);
}
}
return fullQueryString;
}
}
private String _activeFormID;
private Form _activeForm;
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.ActiveForm"]/*' />
[
Browsable(false),
Bindable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
]
public Form ActiveForm
{
get
{
// retrieve form cached in local variable
if (_activeForm != null)
{
return _activeForm;
}
// else get the id from state and retrieve form
if (_activeFormID != null)
{
_activeForm = GetForm(_activeFormID);
_activeForm.Activated = true;
return _activeForm;
}
// else first visit to page, so activate first form
if (_activeForm == null && Forms.Count > 0)
{
_activeForm = (Form)Forms[0];
if(IsPostBack) {
_activeForm.Activated = true;
}
return _activeForm;
}
if (DesignMode)
{
return null;
}
else
{
throw new Exception(
SR.GetString(SR.MobilePage_AtLeastOneFormInPage));
}
}
set
{
Form oldForm = ActiveForm;
Form newForm = value;
_activeForm = newForm;
_activeFormID = newForm.UniqueID;
if (newForm != oldForm)
{
oldForm.FireDeactivate(EventArgs.Empty);
newForm.FireActivate(EventArgs.Empty);
// AUI 5577
newForm.PaginationStateChanged = true;
}
else
{
newForm.FireActivate(EventArgs.Empty);
}
}
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.GetForm"]/*' />
public Form GetForm(String id)
{
Form form = FindControl(id) as Form;
if (form == null)
{
throw new ArgumentException(SR.GetString(
SR.MobilePage_FormNotFound, id));
}
return form;
}
// Perform a "safe" redirect on postback.
// Abstracts away differences between clients in redirect behavior after a
// postback. Some clients do a GET to the new URL (treating it as a HTTP 303),
// others do a POST, with old data. This method ads a query string parameter to
// the redirection URL, so that the new target page can determine that it's a result
// of a redirection.
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.RedirectToMobilePage"]/*' />
public void RedirectToMobilePage(String url)
{
RedirectToMobilePage(url, true);
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.RedirectToMobilePage1"]/*' />
public void RedirectToMobilePage(String url, bool endResponse)
{
bool queryStringWritten = url.IndexOf("?", StringComparison.Ordinal) != -1 ? true : false;
if(Adapter.PersistCookielessData)
{
IDictionary dictionary = Adapter.CookielessDataDictionary;
if(dictionary != null)
{
foreach(String name in dictionary.Keys)
{
if(queryStringWritten)
{
url = String.Concat(url, "&");
}
else
{
url = String.Concat(url, "?");
queryStringWritten = true;
}
url = String.Concat(url, name + "=" + dictionary[name]);
}
}
}
Response.Redirect(url, endResponse);
// MobileRedirect.RedirectToUrl(Context, url, endResponse);
}
// Override Page.Validate to do the validation only for mobile
// validators that are in the current active form. Other validators in
// Page.Validators collection like aggregated web validators and mobile
// validators in other forms shouldn't be checked.
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.Validate"]/*' />
public override void Validate()
{
// We can safely remove other validators from the validator list
// since they shouldn't be checked.
for (int i = Validators.Count - 1; i >= 0; i--)
{
IValidator validator = Validators[i];
if (!(validator is BaseValidator) ||
((BaseValidator) validator).Form != ActiveForm)
{
Validators.Remove(validator);
}
}
base.Validate();
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.VerifyRenderingInServerForm"]/*' />
[
EditorBrowsable(EditorBrowsableState.Never),
]
public override void VerifyRenderingInServerForm(Control control)
{
if (!_isRenderingInForm && !DesignMode)
{
throw new Exception(SR.GetString(SR.MobileControl_MustBeInForm,
control.UniqueID,
control.GetType().Name));
}
}
internal void EnterFormRender(Form form)
{
_isRenderingInForm = true;
}
internal void ExitFormRender()
{
_isRenderingInForm = false;
}
// Override Page.InitOutputCache to add additional VaryByHeader
// keywords to provide correct caching of page outputs since by
// default ASP.NET only keys on URL for caching. In the case that
// different markup devices browse to the same URL, caching key on
// the URL is not good enough. So in addition to URL, User-Agent
// header is also added for the key. Also any additional headers can
// be added by the associated page adapter.
private const String UserAgentHeader = "User-Agent";
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.InitOutputCache"]/*' />
protected override void InitOutputCache(int duration,
String varyByHeader,
String varyByCustom,
OutputCacheLocation location,
String varyByParam)
{
InitOutputCache(duration, null, varyByHeader, varyByCustom, location, varyByParam);
}
protected override void InitOutputCache(int duration,
String varyByContentEncoding,
String varyByHeader,
String varyByCustom,
OutputCacheLocation location,
String varyByParam)
{
base.InitOutputCache(duration, varyByContentEncoding, varyByHeader, varyByCustom,
location, varyByParam);
Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
Response.Cache.VaryByHeaders[UserAgentHeader] = true;
IList headerList = Adapter.CacheVaryByHeaders;
if (headerList != null)
{
foreach (String header in headerList)
{
Response.Cache.VaryByHeaders[header] = true;
}
}
}
/////////////////////////////////////////////////////////////////////////
// HIDDEN FORM VARIABLES
/////////////////////////////////////////////////////////////////////////
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.HasHiddenVariables"]/*' />
public bool HasHiddenVariables()
{
return _hiddenVariables != null;
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.HiddenVariables"]/*' />
[
Browsable(false),
Bindable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
]
public IDictionary HiddenVariables
{
get
{
if (_hiddenVariables == null)
{
_hiddenVariables = new Hashtable();
}
return _hiddenVariables;
}
}
protected override void OnPreInit(EventArgs e) {
_afterPreInit = true;
base.OnPreInit(e);
}
/////////////////////////////////////////////////////////////////////////
// DEVICE-INDEPENDENT POSTBACK
/////////////////////////////////////////////////////////////////////////
// The functionality required here is to trap and handle
// postback events at the page level (delegating to the adapter),
// rather than expecting a control to handle it.
// This has to be done in DeterminePostBackMode, because there isn't
// anything else overrideable.
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.DeterminePostBackMode"]/*' />
protected override NameValueCollection DeterminePostBackMode()
{
// Ignore the transfer case.
if (Context.Handler != this)
{
return null;
}
// Let the specific adapter to manipulate the base collection if
// necessary.
NameValueCollection collection =
Adapter.DeterminePostBackMode(Context.Request,
postEventSourceID,
postEventArgumentID,
base.DeterminePostBackMode());
// Get hidden variables out of the collection.
if (collection != null)
{
// If the page was posted due to a redirect started by calling
// RedirectToMobilePage, then ignore the postback. For details,
// see RedirectToMobilePage method elsewhere in this class.
if (Page.Request.QueryString[MobileRedirect.QueryStringVariable] == MobileRedirect.QueryStringValue)
{
collection = null;
}
else
{
int count = collection.Count;
for (int i = 0; i < count; i++)
{
String key = collection.GetKey(i);
if (key.StartsWith(HiddenVariablePrefix, StringComparison.Ordinal))
{
HiddenVariables[key.Substring(HiddenVariablePrefix.Length)] = collection[i];
}
}
String eventSource = collection[postEventSourceID];
if (eventSource != null)
{
// Page level event
RaisePagePostBackEvent(eventSource, collection[postEventArgumentID]);
_eventSource = eventSource;
}
}
}
_requestValueCollection = collection;
/* Obsolete.
// If doing a postback, don't allow redirections.
if (collection != null)
{
MobileRedirect.DisallowRedirection(Context);
}
*/
return collection;
}
private void RaisePagePostBackEvent(String eventSource, String eventArgument)
{
// Let the adapter handle it.
Adapter.HandlePagePostBackEvent(eventSource, eventArgument);
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.RaisePostBackEvent"]/*' />
protected override void RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
{
if (eventArgument == null && sourceControl is Form)
{
// This is really a default event sent by an HTML browser. Try to find
// the default event handler from the active form, and call it.
Form activeForm = ActiveForm;
if (activeForm != null)
{
IPostBackEventHandler defaultHandler = activeForm.DefaultEventHandler;
if (defaultHandler != null)
{
base.RaisePostBackEvent(defaultHandler, null);
}
}
// Otherwise, eat the event - there's no one to send it to, and the form
// can't use it.
}
else
{
base.RaisePostBackEvent(sourceControl, eventArgument);
}
}
/////////////////////////////////////////////////////////////////////////
// BEGIN ADAPTER PLUMBING
/////////////////////////////////////////////////////////////////////////
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.OnInit"]/*' />
protected override void OnInit(EventArgs e)
{
#if ICECAP
IceCapAPI.StartProfile(IceCapAPI.PROFILE_THREADLEVEL, IceCapAPI.PROFILE_CURRENTID);
#endif
OnDeviceCustomize(new EventArgs());
// Accessing Request throws exception at designtime
if(!DesignMode && Request.Headers["__vs_debug"] != null)
{
_debugMode = true;
}
// ASP.NET requires the following method to be called to have
// ViewState calculated for the page.
RegisterViewStateHandler();
Adapter.OnInit(e);
base.OnInit(e);
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.OnLoad"]/*' />
protected override void OnLoad(EventArgs e)
{
// AUI 865
if (_eventSource != null && _eventSource.Length > 0)
{
MobileControl control = FindControl (_eventSource) as MobileControl;
if (control != null && (control is IPostBackEventHandler))
{
_activeForm = control.Form;
_activeForm.Activated = true;
}
}
Adapter.OnLoad(e);
base.OnLoad(e);
if (!IsPostBack)
{
ActiveForm.FireActivate(EventArgs.Empty);
}
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.OnPreRender"]/*' />
protected override void OnPreRender(EventArgs e)
{
Adapter.OnPreRender(e);
base.OnPreRender(e);
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.Render"]/*' />
protected override void Render(HtmlTextWriter writer)
{
#if TRACE
DumpSessionViewState();
#endif
Adapter.Render(writer);
}
#if TRACE
void DumpSessionViewState()
{
ArrayList arr;
_sessionViewState.Dump(this, out arr);
StringBuilder sb = new StringBuilder();
foreach (String s in arr)
{
sb.Append(s);
sb.Append("\r\n");
}
Trace.Write("SessionViewState", sb.ToString());
}
#endif
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.OnUnload"]/*' />
protected override void OnUnload(EventArgs e)
{
base.OnUnload(e);
Adapter.OnUnload(e);
#if ICECAP
IceCapAPI.StopProfile(IceCapAPI.PROFILE_THREADLEVEL, IceCapAPI.PROFILE_CURRENTID);
#endif
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.OnDeviceCustomize"]/*' />
protected virtual void OnDeviceCustomize(EventArgs e)
{
}
internal bool PrivateViewStateLoaded
{
get
{
return _privateViewStateLoaded;
}
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.GetPrivateViewState"]/*' />
public Object GetPrivateViewState(MobileControl ctl)
{
return _privateViewState == null ?
null :
_privateViewState[ctl.UniqueID];
}
private SessionViewState _sessionViewState = new SessionViewState();
private static readonly String _controlsRequiringPostBackKey = ".PBC";
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.LoadPageStateFromPersistenceMedium"]/*' />
protected override Object LoadPageStateFromPersistenceMedium()
{
Object state = null;
String clientViewStateString = _requestValueCollection[ViewStateID];
if (clientViewStateString != null)
{
try {
_privateViewState = StateFormatter.Deserialize(clientViewStateString) as Hashtable;
}
catch (Exception e) {
if (IsViewStateException(e)) {
_privateViewState = null;
// DevDiv #461378: Suppress validation errors for cross-page postbacks.
// This is a much simplified form of the check in Page.LoadPageStateFromPersistenceMedium.
if (Context != null && TraceEnabled) {
Trace.Write("aspx.page", "Ignoring page state", e);
}
}
else {
// we shouldn't ---- this exception; let the app error handler take care of it
throw;
}
}
if (_privateViewState != null)
{
Pair pair = _privateViewState[PageClientViewStateKey] as Pair;
if (pair != null)
{
_activeFormID = (String) pair.First;
Pair id = (Pair) pair.Second;
if (id != null)
{
_sessionViewState.Load(this, id);
state = _sessionViewState.ViewState;
if(state == null)
{
OnViewStateExpire(EventArgs.Empty);
}
else
{
Object[] arrState = state as Object[];
if (arrState != null)
{
_privateViewState = (Hashtable) arrState[1];
state = arrState[0];
}
}
}
}
_privateViewState.Remove(PageClientViewStateKey);
// If the page had no view state, but had controls requiring postback,
// this information was saved in client view state.
Object controlsRequiringPostBack =
_privateViewState[_controlsRequiringPostBackKey];
if (controlsRequiringPostBack != null)
{
state = new Pair(null,
new Triplet(GetTypeHashCode().ToString(CultureInfo.InvariantCulture),
null,
controlsRequiringPostBack));
_privateViewState.Remove(_controlsRequiringPostBackKey);
}
// Apply whatever private view state can be applied now.
foreach (DictionaryEntry entry in _privateViewState)
{
if (entry.Value != null)
{
MobileControl ctl = FindControl((String)entry.Key) as MobileControl;
if (ctl != null)
{
ctl.LoadPrivateViewStateInternal(entry.Value);
}
}
}
}
}
_privateViewStateLoaded = true;
if (state == null)
{
// Give framework back an empty page view state
state = new Pair(null, new Triplet(GetTypeHashCode().ToString(CultureInfo.InvariantCulture), null, null));
}
return state;
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.OnViewStateExpire"]/*' />
protected virtual void OnViewStateExpire(EventArgs e)
{
throw new Exception(SR.GetString(SR.SessionViewState_ExpiredOrCookieless));
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.SavePageStateToPersistenceMedium"]/*' />
protected override void SavePageStateToPersistenceMedium(Object view)
{
Object viewState = null;
Object privateViewState = null;
Pair serverViewStateID;
SavePrivateViewStateRecursive(this);
if (!CheckEmptyViewState(view))
{
viewState = view;
}
if (Device.RequiresOutputOptimization &&
_clientViewState != null &&
_clientViewState.Count > 0 &&
EnableViewState)
{
// Here we take over the content in _clientViewState. It
// should be reset to null. Then subsequently any info added
// will be set to the client accordingly.
privateViewState = _clientViewState;
_clientViewState = null;
_clientViewStateString = null;
}
// Are we being asked to save an empty view state?
if (viewState == null && privateViewState == null)
{
serverViewStateID = null;
}
else
{
// Our view state is dependent on session state. So, make sure session
// state is available.
if (!(this is IRequiresSessionState) || (this is IReadOnlySessionState))
{
throw new Exception(SR.GetString(SR.MobilePage_RequiresSessionState));
}
_sessionViewState.ViewState = (privateViewState == null) ?
viewState : new Object[2] { viewState, privateViewState };
serverViewStateID = _sessionViewState.Save(this);
if (Device.PreferredRenderingMime != "text/vnd.wap.wml" && Device["cachesAllResponsesWithExpires"] != "true")
{
if (String.Compare(Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase) == 0)
{
Response.Expires = 0;
}
else
{
Response.Expires = HttpContext.Current.Session.Timeout;
}
}
}
String activeFormID = ActiveForm == Forms[0] ? null : ActiveForm.UniqueID;
// Optimize what is written out.
if (activeFormID != null || serverViewStateID != null)
{
AddClientViewState(PageClientViewStateKey,
new Pair(activeFormID, serverViewStateID));
}
}
// NOTE: Make sure this stays in sync with Page.PageRegisteredControlsThatRequirePostBackKey
private const string PageRegisteredControlsThatRequirePostBackKey = "__ControlsRequirePostBackKey__";
private bool CheckEmptyViewState(Object viewState)
{
Pair pair = viewState as Pair;
if (pair == null) {
return false;
}
Pair allViewState = pair.Second as Pair;
if (allViewState == null || allViewState.Second != null)
{
return false;
}
IDictionary controlStates = pair.First as IDictionary;
if (controlStates != null)
{
// If the only thing in control is the set of controls
// requiring postback, then save the information in client-side
// state instead.
if (controlStates.Count == 1 &&
controlStates[PageRegisteredControlsThatRequirePostBackKey] != null) {
AddClientViewState(_controlsRequiringPostBackKey, controlStates[PageRegisteredControlsThatRequirePostBackKey]);
}
else
{
return false;
}
}
return true;
}
private void SavePrivateViewStateRecursive(Control control)
{
if (control.HasControls())
{
IEnumerator e = control.Controls.GetEnumerator();
while (e.MoveNext())
{
MobileControl c = e.Current as MobileControl;
if (c != null)
{
c.SavePrivateViewStateInternal();
SavePrivateViewStateRecursive(c);
}
else
{
SavePrivateViewStateRecursive((Control)e.Current);
}
}
}
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.LoadViewState"]/*' />
protected override void LoadViewState(Object savedState)
{
if (savedState != null)
{
Object[] state = (Object[])savedState;
if (state.Length > 0)
{
base.LoadViewState(state[0]);
if (state.Length > 1)
{
Adapter.LoadAdapterState(state[1]);
}
}
}
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.SaveViewState"]/*' />
protected override Object SaveViewState()
{
Object baseState = base.SaveViewState();
Object adapterState = Adapter.SaveAdapterState();
if (adapterState == null)
{
return (baseState == null) ? null : new Object[1] { baseState };
}
else
{
return new Object[2] { baseState, adapterState };
}
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.OnError"]/*' />
protected override void OnError(EventArgs e)
{
// Let the base class deal with it. A user-written error handler
// may catch and handle it.
base.OnError(e);
Exception error = Server.GetLastError();
if (error == null || error is System.Threading.ThreadAbortException)
{
return;
}
if (!_debugMode)
{
if(!HttpContext.Current.IsCustomErrorEnabled)
{
Response.Clear();
if (Adapter.HandleError(error, (HtmlTextWriter)CreateHtmlTextWriter(Response.Output)))
{
Server.ClearError();
}
}
}
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.CreateMarkupTextWriter"]/*' />
protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter writer)
{
HtmlTextWriter htmlwriter = Adapter.CreateTextWriter(writer);
if (htmlwriter == null)
{
htmlwriter = base.CreateHtmlTextWriter(writer);
}
return htmlwriter;
}
/////////////////////////////////////////////////////////////////////////
// END ADAPTER PLUMBING
/////////////////////////////////////////////////////////////////////////
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.AddedControl"]/*' />
protected override void AddedControl(Control control, int index)
{
if (control is Form || control is UserControl)
{
_forms = null;
}
base.AddedControl(control, index);
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.RemovedControl"]/*' />
protected override void RemovedControl(Control control)
{
if (control is Form || control is UserControl)
{
_forms = null;
}
base.RemovedControl(control);
}
private byte[] GetMacKeyModifier()
{
//NOTE: duplicate of the version in objectstateformatter.cs, keep in sync
// Use the page's directory and class name as part of the key (ASURT 64044)
// We need to make sure that the hash is case insensitive, since the file system
// is, and strange view state errors could otherwise happen (ASURT 128657)
int pageHashCode = StringComparer.InvariantCultureIgnoreCase.GetHashCode(
TemplateSourceDirectory);
pageHashCode += StringComparer.InvariantCultureIgnoreCase.GetHashCode(GetType().Name);
byte[] macKeyModifier;
if (ViewStateUserKey != null) {
// Modify the key with the ViewStateUserKey, if any (ASURT 126375)
int count = Encoding.Unicode.GetByteCount(ViewStateUserKey);
macKeyModifier = new byte[count + 4];
Encoding.Unicode.GetBytes(ViewStateUserKey,0, ViewStateUserKey.Length, macKeyModifier, 4);
}
else {
macKeyModifier = new byte[4];
}
macKeyModifier[0] = (byte) pageHashCode;
macKeyModifier[1] = (byte) (pageHashCode >> 8);
macKeyModifier[2] = (byte) (pageHashCode >> 16);
macKeyModifier[3] = (byte) (pageHashCode >> 24);
return macKeyModifier;
}
private LosFormatter _stateFormatter;
private LosFormatter StateFormatter
{
get
{
if (_stateFormatter == null)
{
if(!EnableViewStateMac)
{
_stateFormatter = new LosFormatter();
}
else
{
_stateFormatter = new LosFormatter(true, GetMacKeyModifier());
}
}
return _stateFormatter;
}
}
private String CreateQueryStringTextFromCollection(
NameValueCollection collection)
{
const String systemPostFieldPrefix = "__";
StringBuilder stringBuilder = new StringBuilder();
if (collection == null)
{
return String.Empty;
}
for (int i = 0; i < collection.Count; i++)
{
String name = collection.GetKey(i);
if (name != null)
{
if (name.StartsWith(systemPostFieldPrefix, StringComparison.Ordinal))
{
// Remove well-known postback elements
if (name == ViewStateID ||
name == postEventSourceID ||
name == postEventArgumentID ||
name == Constants.EventSourceID ||
name == Constants.EventArgumentID ||
name.StartsWith(HiddenVariablePrefix, StringComparison.Ordinal))
{
continue;
}
}
else
{
String controlId = name;
if (controlId.EndsWith(".x", StringComparison.Ordinal) ||
controlId.EndsWith(".y", StringComparison.Ordinal))
{
// Remove the .x and .y coordinates if the control is
// an image button
controlId = controlId.Substring(0, name.Length - 2);
}
if (FindControl(controlId) != null)
{
// Remove control id/value pairs if present
continue;
}
}
}
AppendParameters(collection, name, stringBuilder);
}
return stringBuilder.ToString();
}
private void AppendParameters(NameValueCollection sourceCollection,
String sourceKey,
StringBuilder stringBuilder)
{
String [] values = sourceCollection.GetValues(sourceKey);
foreach (String value in values)
{
if (stringBuilder.Length != 0)
{
stringBuilder.Append('&');
}
if (sourceKey == null)
{
// name can be null if there is a query name without equal
// sign appended
stringBuilder.Append(Server.UrlEncode(value));
}
else
{
stringBuilder.Append(Server.UrlEncode(sourceKey));
stringBuilder.Append('=');
stringBuilder.Append(Server.UrlEncode(value));
}
}
}
/// <include file='doc\MobilePage.uex' path='docs/doc[@for="MobilePage.RenderControl"]/*' />
public override void RenderControl(HtmlTextWriter writer) {
RenderControl(writer, null); // Use legacy adapter, not V2 adapter.
}
// Similar to the logic in ViewStateException.cs, but we can only check for
// ViewState exceptions in general, not MAC-specific exceptions.
private static bool IsViewStateException(Exception e) {
for (; e != null; e = e.InnerException) {
if (e is ViewStateException) { return true; }
}
return false;
}
}
}
|