Asp Focus on input jumping bug

牧云@^-^@ 提交于 2019-12-12 06:59:56

问题


I've got a web form using asp.net. In this form I have a lot of inputs. For one of the drop downs whenever you press it, the focus jumps to the next text box.

This is in a update panel, because there is some server side work required for filtering, hiding, etc.

If the User chooses Australia from visaType_filter then it hides visaType_dd and shows visaType_tb. If they choose NZ its the other way around.

Now my question:

Is there a bug or something that makes focus jump off of a drop down when you click on it to go to the next input (or control)?

Code:

<fieldset>
    <asp:UpdatePanel ID="visaTypeUpdatePanel" runat="server">
        <ContentTemplate>
            <label>Visa Type Number</label>
            <label>
                <asp:DropDownList ID="visaType_filter" runat="server" Width="40%" OnSelectedIndexChanged="visaType_filter_SelectedIndexChanged" AutoPostBack="true"/>
                <asp:TextBox ID="visaType_tb" runat="server" Width="40%" OnTextChanged="visaType_tb_blur" AutoPostBack="true"/>
                <asp:DropDownList ID="visaType_dd" runat="server" Width="40%"/>
                <asp:Literal ID="visaType_literal" runat="server" />
            </label>
        </ContentTemplate>
    </asp:UpdatePanel>
</fieldset>
<fieldset>

回答1:


I resolved my problem by using jQuery and Ajax in place of UpdatePanels.




回答2:


AFAIK, when UpdatePanel gets triggered, the focus does not get maintained. So ideally, you shouldn't be getting any focus at all.

Regardless of reason, you can work-around the issue using ScriptManager.SetFocus method to maintain focus on the drop-down.

You can also have client side solutions for maintaining focus - they essentially work by hooking into AJAX requests to remember the focused control before update panel is triggered and then restoring it back when update panel post-back is completed: see this link for one such solution.



来源:https://stackoverflow.com/questions/6853252/asp-focus-on-input-jumping-bug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!