asp:DropDownList 在选择输入时提交页面

发布于 2024-10-04 10:21:22 字数 1382 浏览 0 评论 0原文

我有一个 asp.net 页面,其中有一个带有默认按钮的面板、更新面板以及更新面板内的下拉列表。当我使用向上/向下键选择一个项目并按 Enter 键选择它时填写表单时,表单正在提交。我该如何解决这个问题?

编辑 一些代码:

<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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

裸钻 2024-10-11 10:21:22

在您的下拉列表中,确保属性“AutoPostBack”未设置为“true”

编辑:看到您的评论。我不太擅长 ASP.Net 更新面板,因为我通常使用 jquery 处理 ajax 内容,但我相信您必须将 ddlCountries 下拉列表放在它自己的更新面板中,或者将其移至状态更新面板并将 ChildrenAsTriggers 属性设置为在该更新面板上为 true。

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.

葬花如无物 2024-10-11 10:21:22

将 AutoPostBack 设置为 false

set AutoPostBack to false

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文