Microsoft KB Archive/308975

= PRB: SelectionList Control Does Not Post Back to Server =

Article ID: 308975

Article Last Modified on 6/14/2002

-

APPLIES TO


 * Microsoft Mobile Internet Toolkit 1.0

-



This article was previously published under Q308975



SYMPTOMS
When you use the mobile SelectionList control found in the Microsoft Mobile Internet Toolkit, it does not post back to the server as expected when you make a selection.



CAUSE
This behavior occurs because the mobile SelectionList control does not contain a AutoPostBack property that is similar to the ASP.NET DropDownList server control. There is no AutoPostBack property for the mobile SelectionList control because client-side script is needed to enable this functionality. The AutoPostBack property is not available because some mobile devices do not support the ability to handle the needed client-side script. In most cases, you can post back to the server with a mobile Command control. When the mobile Command control posts back to the server, a SelectedIndexChanged event for the SelectionList control will execute if the event is defined and a change has been made.



RESOLUTION
To work around this issue, create a device filter, and then use the DeviceSpecific class to use an ASP.NET DropDownList server control.



STATUS
This behavior is by design.



How to Create a Device Filter
Device filters are created when you add a deviceFilters element to the System.web section of the Web.config file. The following sample code creates a filter that can be used to identify devices that support JavaScript. This type of filter is helpful because the ASP.NET DropDownList control sends client-side JavaScript to a browser.      

How to Use the DeviceSpecific Class
By using the DeviceSpecific class, you can use templates to send a customized rendering to devices that support JavaScript. This is done by using a mobile Panel control. Within the mobile Panel control, a DeviceSpecific tag can be defined that contains a choice tag. The choice tag uses the device filter created in the preceding section of this article by setting the Filter attribute to the name of the device filter. Within the choice tag, a ContentTemplate tag is defined that contains the control (or controls) that you want to render. In the case of a device that supports JavaScript, you will use an ASP.NET DropDownList control with the AutoPostBack property set to True. For other devices, you can define a default choice tag by not setting the filter attribute. The default choice contains a ContentTemplate tag, which, in turn, contains the SelectionList and Command mobile controls.     <asp:DropDownList id=&quot;SelectionList1&quot; runat=&quot;server&quot; OnSelectedIndexChanged=&quot;SelectionList1_SelectedIndexChanged&quot; AutoPostBack=&quot;True&quot;> <asp:ListItem Value=&quot;a&quot;>1</asp:ListItem> <asp:ListItem Value=&quot;b&quot;>2</asp:ListItem> <asp:ListItem Value=&quot;c&quot;>3</asp:ListItem> </asp:DropDownList> </ContentTemplate> </Choice> <Choice> <ContentTemplate> <mobile:SelectionList id=&quot;SelectionList1&quot; runat=&quot;server&quot; OnSelectedIndexChanged=&quot;SelectionList1_SelectedIndexChanged&quot;> <Item Value=&quot;a&quot; Text=&quot;1&quot;/> <Item Value=&quot;a&quot; Text=&quot;2&quot;/> <Item Value=&quot;a&quot; Text=&quot;3&quot;/> </mobile:SelectionList> <mobile:Command runat=&quot;server&quot; text=&quot;Submit&quot;/> </ContentTemplate> </Choice> </mobile:DeviceSpecific> </mobile:Panel> NOTE: In the preceding sample code, both the mobile SelectionList and ASP.NET DropDownList server controls have a OnSelectedIndexChanged event defined to the same function. Both of the controls also use the same ID, which is possible because templates are being used. This allows the developer to process information on postback to the server with one function instead of two, and also eliminates the need to write code for both of the controls.

Keywords: kbextensibility kbweb kbtemplate kbprb kbconfig kbservercontrols kbhtmldevice KB308975

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.