开发者

Asp Focus on input jumping bug

开发者 https://www.devze.com 2023-03-23 16:02 出处:网络
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.

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_Selected开发者_运维知识库IndexChanged" 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>


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号