Advertisement

04.16.2008 at 03:00AM PDT, ID: 23326482
[x]
Attachment Details

ASP.Net drop down list postback event can be cancelled by escape key

Asked by EricTViking in .NET, Programming for ASP.NET, Microsoft Visual Basic.Net

Tags: ASP.NET, 2.0

I have found a problem with an asp.net app whereby if you select a value in a drop down list that is set to auto postback, and press the escape key just after selecting the value, the selected value appears in the drop down list, but the postback doesn't fire.

This is easily reproduced by dropping a drop down list onto a form along with a label. Add a few values to the drop down list and in the page load event set the label text to the drop down list selected value.

When you select values in the drop down list, the textbox value changes. If you select a value in the drop down list but press escape quickly before the postback occurs the label doesn't get updated and still shows the old value.

How can I prevent this happening?

Simple test app is as follows (HTML and codebehind)...
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
        </asp:DropDownList>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
</body>
</html>
 
 
 
Partial Class _Default
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack Then
            Me.Label1.Text = Me.DropDownList1.SelectedItem.Text
        End If
    End Sub
End Class
[+][-]04.16.2008 at 02:34PM PDT, ID: 21372203

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET, Programming for ASP.NET, Microsoft Visual Basic.Net
Tags: ASP.NET, 2.0
Sign Up Now!
Solution Provided By: arhame
Participating Experts: 1
Solution Grade: A
 
 
[+][-]04.16.2008 at 02:43PM PDT, ID: 21372260

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.16.2008 at 03:02PM PDT, ID: 21372414

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 08:07AM PDT, ID: 21377905

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 08:12AM PDT, ID: 21377990

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.18.2008 at 07:41AM PDT, ID: 21386203

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.18.2008 at 07:46AM PDT, ID: 21386247

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628