Problems with Scriptmanager.Registerclientscriptblock

Asked

Viewed 295 times

0

My btnDownloadArchitect_Click function.

protected void btnDownloadArquivos_Click(object sender, EventArgs e)
{
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment; filename= " + nomeArquivo);
            Response.CacheControl = "Private";

           //Aqui dentro tem uma outra função qualquer.


            Response.Flush();
            Response.Clear();
            Response.ClearContent();
            HttpContext.Current.ApplicationInstance.CompleteRequest();

            EscreveErroNaTela();

}           

Inside the Typing() function has the following code.

ScriptManager.RegisterClientScriptBlock(this, GetType(), "Alerta", "alert('Alguns arquivos não puderam ser baixados. Clique no botão erros para maiores informações');", true);

This Scriptmanager.Registerclientscriptblock code works well, the problem is that in the btnDownloadArchies_Click function it has some conditions, and when entering this condition it fulfills some properties of Response, after a Flush, Clear, Clear content.

When it fills in these properties my Scriptmanager does not work, no alerts are displayed, which may be occurring?

1 answer

0

Hello, your problem is not in the instructions:

        Response.Flush();
        Response.Clear();
        Response.ClearContent();
        HttpContext.Current.ApplicationInstance.CompleteRequest();

        EscreveErroNaTela();

What is actually happening is when you add Header "Content-Disposition"="Attachment...", and changes the "Content-Type"="application/octet-stream".

This causes your browser to treat the answer in a different way, i.e., it will reload your page through the cache, and your response it will treat as a download, i.e., it will not interpret as an html response.

If we trace in the browser itself we can see this more clearly: Request Disposition

Note that in Response Header we have Content-Disposition as an attachment.

Requisição Vazia

Already in this image, as you can see in the detail of Response there is no content.

Now notice what happens when we remove the header and content-type of sponse we get a different sponse: Imagem sem o header e conent-types mencionados

Note in the image that we no longer have the header or content-type informed

inserir a descrição da imagem aqui

Also note that our Response now comes filled with html content resulting from server processing.

In order for you to get the desired result, you will have an additional job of dealing with two requests.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.