开发者

ModalPopupExtender setfocus issue

I'm using a Ajax ModalPopupExtender to show a popup panel. The panel has a TextBox. I w开发者_如何学Pythonant 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.


Add the javascript below:

function pageLoad() {
    $find('modalPopupBehaviorID').add_shown(function () {
        $get("<%= TextBox1.ClientID %>").focus();
    });
}


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:

document.getElementById("TextBox").focus();

Hope this helps (and hope not to have been too obvious hehe)


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

                    <asp:Button ID="btnShow" runat="server" Text="Add New Test" OnClick="btnShow_OnClick" OnClientClick="return modalAdjust()"  /> 

//javascript

  function setFocus() {
              try {
                  document.getElementById('<%= TextBox_TestDescription.ClientID %>').focus();
              } catch (e) {
                  alert(e);
              }
          }

          function modalAdjust() {
              try {
                  setTimeout("setFocus();", 1);
              }
              catch (e) {
                  alert(e);
              }
          }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜