Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
Alert dialog never shows escape characters in asp.net ajax

I'm working on ASP.NET AJAX Web Application.

As part of the requirement, I need to show message to the end user with the uploaded file location. Everything is fine, but the alert message never shows "/" symbols in the path.

For the path: \\shrestasoft\intranet\CorrectionReports\ReportsWithAccount\CorrectionReportWithAccount-Dec-22-2021-12-31-36-PM.xlsx

Below is how my alert dialog is displaying:

\shrestasoftintranetCorrectionReportsReportsWithAccountCorrectionReportWithAccount-Dec-22-2021-12-31-36-PM.xlsx

enter image description here

I've written the below code:

    public static void ShowAlertWithFileLocation(object sender, string message)
    {
        message = "alert('" + message + "');";
        ScriptManager.RegisterClientScriptBlock((sender as Control), typeof(ScriptManager), "alert", message, true);
    }

I've tried to use HtmlUtility.HtmlEncode() method, but that did not work for me. Can someone suggest how can I get the appropriate filename with path?

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

The \ is considered a escape car. But in place of ' use ` and String.raw

eg this:

 message = "alert(String.raw`" + message + "`);";

note carefull - there is no () for String.raw - and you use ` and not '

So, you use the ` that left to 1 key on most keyboards.

eg:

 var s = String.raw`power\weight`
 alert(s)
about 4 years ago · Santiago Trujillo Relatório

0

The answer is very simple, but took more time for me to arrive to this conclusion. We just need to use new JavaScriptSerializer().Serialize(message); method.

Below is my modified code:

    public static void ShowAlertWithFileLocation(object sender, string message)
    {
        message = new JavaScriptSerializer().Serialize(message);
        message = "alert('" + message + "');";
        ScriptManager.RegisterClientScriptBlock((sender as Control), typeof(ScriptManager), "alert", message, true);
    }
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda