Microsoft JScript runtime error: Only properly formatted script tags can be registered
===

I am having a web page and i applied script manager on it. On the page load i am checking some condition and showing a Javascript ShowModalDialog from code and it is working fine.

    int isAnyNonProdTaskActive = _nonProduction.IsAnyTaskActive(UserIDFromDB);
                if (isAnyNonProdTaskActive > 0)
                {
                    //Displays and Logs Message
                    _loggerDetails.LogMessage = "EmployeeQuotient.Production.Page_Load()     One NonProduction incomplete task found, NonProductionTimeEntryID : " + isAnyNonProdTaskActive.ToString();
                    _writeLog.LogDetails(_loggerDetails.LogLevel_Info, _loggerDetails.LogMessage);

                    Session["TaskActiveNonProd"] = isAnyNonProdTaskActive;
                    Page page = HttpContext.Current.CurrentHandler as Page;

                    //Displays and Logs Message
                    _loggerDetails.LogMessage = "EmployeeQuotient.Production.Page_Load()     Opening ElapsedClockNonProd.aspx to complete the incomplete task id :" + isAnyNonProdTaskActive.ToString();
                    _writeLog.LogDetails(_loggerDetails.LogLevel_Info, _loggerDetails.LogMessage);

                    ScriptManager.RegisterStartupScript(page, page.GetType(), "OpenModalDialog", "<script type=text/javascript>window.showModalDialog('ElapsedClockNonProd.aspx?code=" + isAnyNonProdTaskActive.ToString() + "', null, 'unadorned:yes ;resizable:0 ;dialogWidth:300px ;dialogHeight:300px ;status:no ;scroll:no ;status=no;'); </script>", false);
                }

The same code i am applying on a Button on the same page then i am getting error.The error message is :-  Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: The script tag registered for type 'ASP.associates_production_aspx' and key 'OpenModalDialog' has invalid characters outside of the script tags: <script type=text/javascript>window.showModalDialog('ElapsedClockNonProd.aspx?code=464', null, 'unadorned:yes ;resizable:0 ;dialogWidth:300px ;dialogHeight:300px ;status:no ;scroll:no ;status=no;'); </script>. Only properly formatted script tags can be registered.

Guide me that how i fix this error.when ever i m refreshing that page, the pop up is opening from the pageload event but on the button click event it is throwing this error.