Problem
I am using the jQuery UI dialog box to show a dialog box with some ASP.NET text fields and a button in it. However, since jQuery moves the div for the dialog box outside the form, I need to move it back to the form again (see this one to find out why), so ASP.NET still works. This move causes a problem when the field does not receive focus when called.
If you look at the pattern below, the line marked as line B should set the focus, however the line marked with line A breaks this. If I comment on line A, this will work. No matter where I move line B (to the dialog, line A, etc.), it still cannot set the focus.
Having set the focus, I mean that the cursor is in the text box that is blinking, ready for type.
Q uestion How to set focus in this scenario?
Samples
HTML body sample
<body>
<form id="form1" runat="server">
<div id="popup">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</div>
</form>
</body>
jQuery sample
$(document).ready(function() {
var dlg = $("#popup").dialog();
dlg.parent().appendTo(jQuery("form:first"));
$("#TextBox2").focus();
});
source
share