Reputation: 645
I have a flash keyboard (not written by me and I know no flash) which is used by the users to type in to the web forms. The keyboard works fine and I am able to fill the fields properly.
When the keyboard obscures any field, I am scrolling the document (in EnsureNotObscured() method) so that input field is not obscured. This is where I am getting the issue. After scrolling the document, I can see that the input field still has the focus (cursor blinks) but when I type nothing appears.
IF I click the mouse in that field again then I am able to type in that field. What could be the reason for this behavior? I even tried explicitly setting focus using document.getElementById(field.id).focus() after scrolling the document in EnsureNotObscured() and still it doesnt work. I even tried doing blur of the field and then setting focus back but no success.
Upvotes: 2
Views: 4257
Reputation: 459
I'll help everyone with code of the answer given by user281693 -
jQuery(element).blur();
setTimeout((function(){
jQuery(element).focus();
}),100)
Where element is your text box.
Upvotes: 0
Reputation: 21
Does this same behavior happen in all browsers? I know I've had issues before with focus and scrolling with the mouse wheel in IE, but if I remember correctly this issue didn't happen in other browsers.
If it's just IE, I may be able to dig up some code I had to work around the issue.
Upvotes: 1
Reputation: 1
Just need to take care of z-index property. Set a z-index in such a manner so that the text box should be at the top
Upvotes: 0
Reputation: 2778
Horrible that an answer is even required here, but here's an IE8 safe way to make this lovely textbox issue go away:
/// <summary>
/// Sets focus to a control using either the Page or ScriptManager method depending on which is available.
/// </summary>
/// <param name="control"></param>
public static void SetFocus(WebControl control)
{
string javaScript = String.Format("setTimeout(function() {{ $get('{0}').blur(); setTimeout(function () {{ $get('{0}').focus(); }}, 1); }}, 1);", control.ClientID);
[ClientScript or ScriptManager].RegisterStartupScript(control, control.GetType(), "setFocus", javaScript, true);
}
Happy coding.
Brian
Upvotes: 0
Reputation: 645
I got it working. I got it by blurring the field and setting the focus back after a timeout. I cannot write here why is it working because it involves our own javascript framework. Thanks for your time.
Upvotes: 2