bootbox.dialog - 使用ScriptManager.RegisterStartupScript时,主按钮没有获得焦点

时间:2016-05-30 13:18:42

标签: c# jquery focus scriptmanager bootbox

我正在使用bootbox来显示对话框。当我试图将实现放在JavaScript中时它工作正常

  $("#btnAdd").click(function () {
    bootbox.dialog({
                           message: "my message.",
                           title: "<i class='fa fa-times-circle red'></i> Error!",
                           buttons: {
                               main: {
                                   label: "Got It!",
                                   className: "btn btn-success btn-primary"
                                  
                               }
                           }
                       });
      });

在上述情况下,按钮会自动对焦,以便按Enter键关闭它。

但是,因为我有一些值作为参数插入我决定制作一个C#函数并实现它

public void ShowMessagebox(string msg,string type,Page mypage)
        {
            string title="";
            switch(type)
            {
                case "success":
                    title="<i class='fa fa-check-circle green'></i> <span class='green'> Success!</span>";
                    break;
                case "error":
                    title="<i class='fa fa-times-circle red'></i> Error!";
                    break;
                case "info":
                    title="<i class='fa fa-info-circle orange2'></i> Information!";
                    break;
            }
            ScriptManager.RegisterStartupScript(mypage, this.GetType(), "myfunction", "bootbox.dialog({message: \"" + msg + "\",title: \"" + title + "\",buttons: { main: {label: \"Got It!\",className: \"btn-primary btn-success\"}}});", true);
        }

现在这样可以正常工作。但我的问题是按钮没有聚焦,我无法按回车键关闭对话框。

即使我已经放了$(“。btn-primary”)。focus()但没有用!。

任何人都可以请帮助

提前致谢

1 个答案:

答案 0 :(得分:0)

我得到了答案

我只是用jquery ready函数包装代码,它工作正常!

谢谢