Question

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;
}
Was it helpful?

Solution

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.

OTHER TIPS

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.

This is an issue in v27 of Chrome, updating to the latest version should fix this.

http://googlechromereleases.blogspot.co.uk/2013/06/stable-channel-update_18.html

The JavaScript function mypostback doesn't work if the listbox has SelectionMode="Multiple"

Disable the AutoPostBack for the ListBox, use the onClick attribute of the ListBox to run a javascript doing __doPostBack for it. It is a work around. I think Google should fix this Chrome bug (ver 27, and 28, ...). It, AutoPostBack True of ListBox, works fine at all other browsers. TY Pien.

<script type="text/javascript">
function mypostback(id, parameter)
{
  __doPostBack(id, parameter)
}
</script>

<asp:ListBox ID="lstbox_id" runat="server" onclick="mypostback('lstbox_id','')">
</asp:ListBox>

It's definitely a bug in Chrome (e.g. v.27.0.1453.110 m). See this answer too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top