DevExpress control ASPxComboBox is returning -1 as selected index when encoderType is given in web.config
Here is my DevExpress control:
<dx:ASPxComboBox ID="txtPaymentProvider" runat="server" Width="170px">
<ClientSideEvents SelectedIndexChanged="function(s, e) { Common.PerformCallback(gvProviderSettings, 'Refresh'); Common.PerformCallback(gvOptionalSettings, 'Refresh'); }" />
<Items>
<dx:ListEditItem Text="Worldpay" Value="Web.PaymentProviders.HotelWorld, Library.Web.PaymentProviders" />
<dx:ListEditItem Text="RealEx" Value="Web.PaymentProviders.HotelReal, Library.Web.PaymentProviders" />
</Items>
</dx:ASPxComboBox>
And here is the code behind:
private void LoadProviderSpecificSettings()
{
if (txtPaymentProvider.SelectedIndex > -1)
{
HotelPaymentProvider provider = SessionManager.CurrentOperator.GetPaymentProvider(txtPaymentProvider.Items[txtPaymentProvider.SelectedIndex].Value.ToString());
}
}
If I disable the encoderType, everything then works as expected.
<httpRuntime enableVersionHeader="false" requestValidationMode="2.0" maxRequestLength="4096" executionTimeout="110" encoderType="System.Web.Security.AntiXss.AntiXssEncoder" requestPathInvalidCharacters="<,>,*,:" />
For someone facing this issue, I resolved this by removing the space in value attribute of
<dx:ListEditItem />. I am currently using an older version of DevExpress which is causing this issue so either you can update to newer one or can fix this bug like this. For reference I am attaching the link to DevExpress where a similar bug was reported.https://supportcenter.devexpress.com/ticket/details/T284458/aspxcombobox-selectedindex-is-always-1-when-text-contains-a-new-line