locked
Problem with line of code System.Web.UI.Page.RegisterStartupScript(string, string) RRS feed

  • Question

  • User-1004886483 posted

    Hi, when i load my solution i have the following alert :

    'System.Web.UI.Page.RegisterStartupScript(string, string)' est obsolète : 'The recommended alternative is ClientScript.RegisterStartupScript(Type type, string key, string script). http://go.microsoft.com/fwlink/?linkid=14202' C:\Projets\MYPROGWebsite\MYPROGWebsite\Transfertfichier.aspx.cs 168

    this is the code of the page Transfertfichier.aspx.cs :

        /// <summary>
        ///  Effacer les lettres temporaires du serveur
        /// </summary>
        private void ViderDossier(string folderPath)
        {
            try
            {
                if (!string.IsNullOrEmpty(folderPath))
                {
                    DirectoryInfo dir = new DirectoryInfo(folderPath);
                    foreach (FileInfo file in dir.GetFiles())
                    {
                        file.Delete();
                    }
                }
            }
            catch (IOException ex)
            {
                Page.RegisterStartupScript("Exception", "alert('" + ex.Message + "');");
            }
        }
        #endregion

    how to fix this?

    Wednesday, January 24, 2018 3:28 PM

All replies

  • User283571144 posted

    Hi devquestionsanswers,

    'System.Web.UI.Page.RegisterStartupScript(string, string)' est obsolète : 'The recommended alternative is ClientScript.RegisterStartupScript(Type type, string key, string script). http://go.microsoft.com/fwlink/?linkid=14202' C:\Projets\MYPROGWebsite\MYPROGWebsite\Transfertfichier.aspx.cs 168

    According to your error message, it shows you used the Page.RegisterStartupScript method which is out of date. It suggest you use ClientScriptManager.RegisterStartupScript Method.

    Please modify the codes as below:

        private void ViderDossier(string folderPath)
        {
            try
            {
                if (!string.IsNullOrEmpty(folderPath))
                {
                    DirectoryInfo dir = new DirectoryInfo(folderPath);
                    foreach (FileInfo file in dir.GetFiles())
                    {
                        file.Delete();
                    }
                }
            }
            catch (IOException ex)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "Exception", "alert('" + ex.Message + "');");
            }
        }

    Best Regards,

    Brando

    Thursday, January 25, 2018 8:38 AM