开发者

asp:DropDownList submits page on selection enter

开发者 https://www.devze.com 2023-01-26 15:23 出处:网络
I have an asp.net page which has a panel w开发者_如何学Cith 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

I have an asp.net page which has a panel w开发者_如何学Cith 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>


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.


set AutoPostBack to false

0

精彩评论

暂无评论...
验证码 换一张
取 消