asp:DropDownList 在选择输入时提交页面
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的下拉列表中,确保属性“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.
将 AutoPostBack 设置为 false
set AutoPostBack to false