1

I have an asp.net page which has a panel with default button and update panel and dropdownlist inside the update panel. While I fill the form when I select an item with up/down keys and press enter to select it the form is being submitted. How can I fix this?

EDIT Some code:

<asp:SqlDataSource ID="sdsCountries" runat="server" ConnectionString="cs"
SelectCommand="SELECT CountryID, Title FROM Countries"/>

<asp:DropDownList ID="ddlCountries" runat="server" DataSourceID="sdsCountries"
DataValueField="CountryID" DataTextField="Title" AutoPostBack="True"
OnSelectedIndexChanged="ddlCountries_SelectedIndexChanged"/>

<asp:UpdatePanel ID="upState" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:SqlDataSource ID="sdsStates" runat="server" ConnectionString="cs"
    SelectCommand="SELECT StateID, Title FROM States WHERE CountryID=@CountryID">
            <SelectParameters><asp:ControlParameter Name="CountryID"
         ControlID="ddlCountries" PropertyName="SelectedValue" DefaultValue="1"/>
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:DropDownList ID="ddlStates" runat="server" DataSourceID="sdsStates"
        DataValueField="StateID" DataTextField="Title"/>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ddlCountries"
        EventName="SelectedIndexChanged" />
    </Triggers>
</asp:UpdatePanel>

2 Answers 2

2

On your dropdown list make sure the attribute "AutoPostBack" is not set to "true"

EDIT: Saw your comment. I am not great with ASP.Net Update panels as I usually handle the ajax stuff with jquery but I believe you will have to either put your ddlCountries dropdown list in it's own update panel or move it to the states update panel and set ChildrenAsTriggers attribute to true on that update panel.

2
  • But I need it enabled, because there is another dropdown for related data. For example Countries > States. ddlStates is populated with related items when ddlCountries is changed.
    – HasanG
    Nov 24, 2010 at 20:59
  • Not working. Best solution so far is to remove panel and default buton
    – HasanG
    Nov 26, 2010 at 10:13
1

set AutoPostBack to false

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.