Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postback when scrolling ListBox in chrome

with scrolling list box, the page will refresh(unwanted).

this problem is only in chrome (Version 27). In other browsers it works properly.

.aspx file:

<asp:Label runat="server" ID="label1" ></asp:Label>
<asp:ListBox ID="ListBox1" runat="server"
    OnSelectedIndexChanged="ListBox1_SelectedIndexChanged"
    DataValueField="f1" DataTextField="f2" DataSourceID="SqlDataSource1" 
    Rows="15" AutoPostBack="true" >
</asp:ListBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    SelectCommand="sp1" SelectCommandType="StoredProcedure"
    ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>">
</asp:SqlDataSource>

.cs file :

protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    label1.Text = ListBox1.SelectedItem.Text;
}
like image 521
sohrab Avatar asked Mar 06 '13 23:03

sohrab


2 Answers

We've noticed this unfortunate bug only recently, on a page that had been working without issue for a very long time. It is specific to Google Chrome version 27, and I am currently using version 26.

The bug:(clicking anywhere inside of the control - the scroll bar being the focus of the issue - causes a complete postback [provided you set the AutoPostBack attribute to true])

The bug could be at a higher level of scripting, and I'm not sure it affects all of our listboxes. It seems unlikely as we have many, on multiple pages, and we would be getting calls if all of them exhibited this behavior.

Our solution contained two options, with another option being less classy: 1) Impractical: to wait for an update for Google Chrome, or use version 26 explicitly. This is impractical for a large userbase which doesn't have permissions for installation or the ability to roll back to a previous version. It also doesn't work if you, for whatever reason, absolutely must test against the latest version of Chrome.

2) We have access to Telerik controls which enable us to use RadListBox instead, slightly more viewstate overhead which may not be a good solution for you, if it's an option at all. This was the option we chose, as the RadListBox escapes the problem behavior.

A distant third, substantially less appealing solution: Find some other alternative for displaying your data, such as a dropdown list, possibly with a secondary subselecting control if you're dealing with a particularly large set of information. It's more work, in the interim, and you would likely wish to revert your changes when a fix was made.

I know all of these are mediocre solutions, but they're possible workarounds. Sorry if this isn't much help.

like image 70
Tony Fiorentini Avatar answered Oct 03 '22 03:10

Tony Fiorentini


This is a bug in some Chrome versions (as others have noted). I was getting the same behaviour on Chrome on an earlier v27 release.

You should upgrade Chrome to the latest version: my version is currently v 27.0.1453.116 m and the problem appears to be fixed in this release.

like image 33
Quango Avatar answered Oct 03 '22 01:10

Quango