【发布时间】:2016-04-05 14:37:10
【问题描述】:
为避免无根据的“重复”标记,让我先说一下 - 我已经搜索了很多答案,但只找到了像 this 这样没有答案的答案,或者 this 告诉我使用 @ 987654323@ 来自我后面的代码。这样做不正常工作。我会解释的。
我在更新面板中有一系列下拉控件,每个下拉控件都会影响之后的控件 - 城市、建筑物和房间。当用户在城市下拉菜单、鼠标或键盘中更改选择时,焦点会立即丢失,因为页面会执行部分回发。好的,所以我尝试输入CityListDropDown.Focus();,但这会导致页面重新定位自身,以便此控件位于页面可见区域的底部 - 而不是所需的行为。页面根本不应该移动。请注意,这仅在更新面板之前的页面上有很多其他内容时才重要,因此这些提示位于页面必须向下滚动到它们的下方。
那么,如何将焦点恢复到该城市下拉菜单,以便当用户使用键盘时,他们可以继续运送到下一个提示?建筑物下拉也是如此。
这是我的html:
<asp:UpdatePanel ID="RoomsUpdatePanel" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate>
<asp:DropDownList ID="CityListDropDown" runat="server" class="form-control input-sm" Width="140" AutoPostBack="True" OnSelectedIndexChanged="CityListDropDown_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="BuildingListDropDown" runat="server" class="form-control input-sm" AutoPostBack="True" Width="100" OnSelectedIndexChanged="BuildingListDropDown_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="RoomListDropDown" runat="server" class="form-control input-sm" AutoPostBack="False" Width="175">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
这是我的代码:
protected void CityListDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
LoadBuildingList();
LoadRoomList();
CityListDropDown.Focus();
}
protected void BuildingListDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
LoadRoomList();
BuildingListDropDown.Focus();
}
【问题讨论】: