IE loses focus on input field in modal

我怕爱的太早我们不能终老 提交于 2019-12-06 09:17:14

The focus has to be delayed. Even 1ms works.

setTimeout (function () {
$("#ContactFormName").focus();
}, 1);

For ASP.NET i've created an extension method:

public static void FocusDelayed(this WebControl control, Page page)
{
    ScriptManager.RegisterStartupScript(page, page.GetType(), "focusDelayed", "setTimeout (function () { document.getElementById(\"" + control.ClientID + "\").focus(); }, 500);", true);
}    

So, in the onload Page_Load of the popup I call it

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            controleName.FocusDelayed(Page);                
        }
    }    

Hope it helps somebody.

Cheers

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