在文本字段中按enter键时,ASP.NET多视图会自动切换/跳转到其他页面

ASP.NET multiview switches / jumps automatically to other page when pressing enter in a textfield

本文关键字:其他 视图 字段 文本 enter 键时 NET ASP      更新时间:2023-09-26

我有一个带有两个视图的MultiView,
每个视图都包含一个按钮,当单击
时,该按钮会转到另一个视图,作为视图中的第一个元素,然后再转到一个或多个TextBox。类似:

<asp:Button ID="userConfSwitch" runat="server" Text="Configure Users" Width="128"
                OnClick="SwitchToUserConfig" />
            <br />
            <asp:TextBox ID="TextBox1" runat="server" Width="400px"></asp:TextBox>

在视图中。

现在,每当我在文本框中按enter键时,"多视图"就会切换到另一个视图。如果我一开始有另一个按钮,比如:

<div style="display: none">
                <asp:Button runat="server" Text="seeing this is a bug" />
            </div>

点击时不会切换视图,当我按下回车键时不会发生任何事情。
是什么导致了这种情况(错误或"功能")?如果没有隐藏的按钮,我该如何禁用它?

您可以将Button属性"UseSubmitBehavior"更改为"false"。