postback when scrolling ListBox in chrome
Asked Answered
W

6

5

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;
}
Wilkinson answered 6/3, 2013 at 23:55 Comment(6)
Version 27 is very early beta - maybe is a bug of chrome ? - you have autopostback after all.Rafael
If you set AutoPostBack="true" equal to false does it still happen?Callahan
Please if you have older versions of Chrome, check it out.Wilkinson
When I set AutoPostBack="true" , the event ListBox1_SelectedIndexChanged will not be invoked. And the problem is resolved. But that event should be called.Wilkinson
My Chrome Version is 20. But it works fine for me. No postback when scrolling, only when click a new item.Bollix
thanks @Teddy. as Aristos said; maybe is a bug.Wilkinson
A
2

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.

Aminoplast answered 22/5, 2013 at 17:18 Comment(1)
A methodology workaround for this issue in Chrome 27: the user selects the currently highlighted element in the ListBox to give focus to the control. The user can then manipulate the scroll bar without triggering the postback event. This obviously isn't a sane workaround to hand to a customer, but it does allow the control to be operated for debugging purposes.Clubbable
C
2

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.

Clarino answered 19/6, 2013 at 15:8 Comment(0)
B
2

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

Bluster answered 27/6, 2013 at 8:42 Comment(0)
D
1

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>
Damaraland answered 29/5, 2013 at 20:14 Comment(0)
S
1

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

Stationer answered 1/6, 2013 at 17:54 Comment(0)
H
1

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

Hensley answered 20/6, 2013 at 11:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.