locked
bootbox.dialog - The main button is not getting focus when using ScriptManager.RegisterStartupScript RRS feed

  • Question

  • User1194656299 posted

    I am using bootbox for displaying dialog boxes. When I am trying to put the implementation in JavaScript it is working fine

    $("#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"
                                      
                                   }
                               }
                           });
          });
    

    In the above case the button automatically focused so that we can press enter key to close it.

    But Since, I have some values to be inserted as parameter I have decided to make a C# function and implement it

    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);
            }

    Now this will work fine. But my problem is that the button is not getting focus and I cannot close the dialog by pressing enter key.

    Even I have put $(".btn-primary").focus() but no use!.

    Can anyone please help

    Thanks in advance

    Monday, May 30, 2016 2:06 PM

Answers

  • User-474980206 posted
    Register startup script, just puts the script code before the end form. As the html has not been fully parsed, you can not set the focus. Wrap the the code with jquery ready function.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 30, 2016 3:01 PM

All replies

  • User-474980206 posted
    Register startup script, just puts the script code before the end form. As the html has not been fully parsed, you can not set the focus. Wrap the the code with jquery ready function.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 30, 2016 3:01 PM
  • User1194656299 posted

    Thank you @bruce. It worked !!! Smile

    Monday, May 30, 2016 3:18 PM