1 //------------------------------------------------------------------------------
2 // <copyright file="ChtmlSelectionListAdapter.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
6 
7 using System;
8 using System.Globalization;
9 using System.IO;
10 using System.Web;
11 using System.Web.UI;
12 using System.Web.UI.HtmlControls;
13 using System.Web.UI.MobileControls;
14 using System.Security.Permissions;
15 
16 #if COMPILING_FOR_SHIPPED_SOURCE
17 namespace System.Web.UI.MobileControls.ShippedAdapterSource
18 #else
19 namespace System.Web.UI.MobileControls.Adapters
20 #endif
21 
22 {
23     /*
24      * ChtmlSelectionListAdapter provides the chtml device functionality for SelectionList controls.
25      *
26      * Copyright (c) 2000 Microsoft Corporation
27      */
28     /// <include file='doc\ChtmlSelectionListAdapter.uex' path='docs/doc[@for="ChtmlSelectionListAdapter"]/*' />
29     [AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
30     [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
31     [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.")]
32     public class ChtmlSelectionListAdapter : HtmlSelectionListAdapter
33     {
34         /// <include file='doc\ChtmlSelectionListAdapter.uex' path='docs/doc[@for="ChtmlSelectionListAdapter.RequiresFormTag"]/*' />
35         public override bool RequiresFormTag
36         {
37             get
38             {
39                 // Some browsers require the form tag to display the selection
40                 // list properly
41                 return true;
42             }
43         }
44 
45         /// <include file='doc\ChtmlSelectionListAdapter.uex' path='docs/doc[@for="ChtmlSelectionListAdapter.Render"]/*' />
Render(HtmlMobileTextWriter writer)46         public override void Render(HtmlMobileTextWriter writer)
47         {
48             ListSelectType selectType = Control.SelectType;
49             if (selectType == ListSelectType.MultiSelectListBox &&
50                 Device.SupportsSelectMultiple == false)
51             {
52                 // Render occurs after SaveViewState.  Here we make a temp
53                 // change which is not persisted to the view state.
54                 Control.SelectType = selectType = ListSelectType.CheckBox;
55             }
56 
57             if (!Device.RequiresUniqueHtmlCheckboxNames ||
58                 selectType != ListSelectType.CheckBox)
59             {
60                 base.Render(writer);
61             }
62             else
63             {
64                 MobileListItemCollection items = Control.Items;
65                 if (items.Count == 0)
66                 {
67                     return;
68                 }
69                 writer.EnterStyle(Style);
70                 bool writeBreak = false;
71                 foreach (MobileListItem item in items)
72                 {
73                     int index = items.IndexOf(item);
74                     if(writeBreak)
75                     {
76                         writer.WriteBreak();
77                     }
78 
79                     writer.Write("<input type=\"checkbox\" name=\"");
80                     if(Device.RequiresAttributeColonSubstitution)
81                     {
82                         writer.Write(Control.UniqueID.Replace(':', ','));
83                     }
84                     else
85                     {
86                         writer.Write(Control.UniqueID);
87                     }
88                     writer.Write(Constants.SelectionListSpecialCharacter);
89                     writer.Write(index);
90                     writer.Write("\" value=\"");
91                     if (!String.IsNullOrEmpty(Control.Form.Action))
92                     {
93                         writer.WriteEncodedText(item.Value);
94                     }
95                     else
96                     {
97                         writer.Write(item.Index.ToString(CultureInfo.InvariantCulture));
98                     }
99                     if (item.Selected &&
100                         Device.SupportsUncheck)
101                     {
102                         writer.Write("\" checked>");
103                     }
104                     else
105                     {
106                         writer.Write("\">");
107                     }
108 
109                     writer.WriteText(item.Text, true);
110                     writeBreak = true;
111                 }
112                 writer.ExitStyle(Style, Control.BreakAfter);
113             }
114         }
115     }
116 }
117