ModalPopupExtender 设置焦点问题
我正在使用 Ajax ModalPopupExtender
来显示弹出面板。该面板有一个TextBox
。我想在弹出面板时将 setfocus
到该 TextBox
。是否有任何方法或机制将焦点设置到弹出扩展器。我尝试了很多方法来实现这一目标,但都失败了。请帮助解决这个问题。
I'm using a Ajax ModalPopupExtender
to show a popup panel. The panel has a TextBox
. I want to setfocus
to that TextBox
while popup the panel. Is there is any method or mechanism to set the focus to the popup extender. I have tried many ways to achieve this, but failed. Please help to resolve this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
添加下面的 JavaScript:
Add the javascript below:
由于您尝试了许多方法但没有成功,因此焦点代码很可能在面板和文本框存在之前稍微执行一点。
setTimeout('document.getElementById("TextBox").focus();',1);
Since you have tried many methods without any success, there is a good chance the focus code is executing a slight bit before the panel and text box exists.
setTimeout('document.getElementById("TextBox").focus();',1);
打开弹出窗口:
希望这有帮助(并希望不要太明显呵呵)
On opening popup:
Hope this helps (and hope not to have been too obvious hehe)
rkw 的回答等帮助我找到了一个复杂的解决方案。我必须使用超时并调用另一个函数才能将焦点正确放置在模式文本框中。不太复杂的解决方案对我不起作用。我相信,添加 setFocus() 可以让正确的执行队列达到我想要的目的。 ...希望这对其他人有帮助。正如 rkw 所建议的,完成任务只需要一毫秒。
//标记
//javascript
rkw 's answer among others helped me derive a convoluted fix. I had to use a timeout and a call to another function in order to properly place the focus in my modal textbox. Less convoluted solutions did not work for me. I believe, the addition of the setFocus() allowed for the proper execution queue to my desired end. ...hope this helps someone else. Like rkw suggested, only a millisecond was necessary to accomplish the task.
//markup
//javascript