Doubt as to window.location.href ()

-1

I know that window.open() will open url in a new window and window.location.href() will open on the calling page. It turns out that when I use window.location.href() , I put in the page_load a javascript call ( alert() ) by code behind and did not fire. However, this page (called) generates a excel and this is happening, working perfectly. I put a loading in it (in apsx ) and also did not fire, because the page seems to run in the background, I do not know if this is true, but it seems that, but anyway alerts should be fired or not ?

This is the function that calls the page that loads the worksheet (Notice the various attempts on the else I made and none worked.

function AcaoAvancar() {

            if (ValidaFormulario()) {

                var dataInicial = $("#txt_dt_ref_inicial").val();
                var dataFinal = $("#txt_dt_ref_final").val();
                var tipoTabela = $('#ddl_tipotabela option:selected').val();
                var tabelas = RetornaTabelas();
                var classificacoes = RetornaClassificacoes();
                var grupos = RetornaGrupos();
                var autorizacao = $('#ddl_autorizacaoprevia option:selected').val();
                var formato = $("input[name='formato']:checked").val();

                var strOpcao = "dtinicial=" + dataInicial;
                strOpcao = strOpcao + "&dtfinal=" + dataFinal;
                if (tipoTabela != "") { strOpcao = strOpcao + "&tipotab=" + tipoTabela; }
                if (tabelas != "") { strOpcao = strOpcao + "&tabl=" + tabelas; }
                if (classificacoes != "") { strOpcao = strOpcao + "&class=" + classificacoes; }
                if (grupos != "") { strOpcao = strOpcao + "&grp=" + grupos; }
                if (autorizacao != "") { strOpcao = strOpcao + "&aut=" + autorizacao; }
                if (formato != "") { strOpcao = strOpcao + "&format=" + formato; }

                if (formato == "PDF")
                    window.location.href = "../../../hes/asp/hes1015b.asp?" + strOpcao;
                else {

                    window.location.href = '../../relatorios/Rel_ItensMaterialMedicamentoExcel.aspx?' + strOpcao;
                    //window.open('../../relatorios/Rel_ItensMaterialMedicamentoExcel.aspx?' + strOpcao);
                    //document.location.href = '../../relatorios/Rel_ItensMaterialMedicamentoExcel.aspx?' + strOpcao;
                    //$("#carregaLoad").load();
                }
            }
        }

This is the Page_Load where the database data is processed to the worksheet. This code is on the called page and it is the one that is being my problem. See I put some calls to some alerts and none were fired:

protected void Page_Load(object sender, EventArgs e)
        {           
            try
            {

                Page.ClientScript.RegisterStartupScript(this.GetType(), "mensagem", "Mensagem()", true);

                //Parametros do filtro
                string dataInicial = Request.QueryString["dtinicial"];
                string dataFinal = Request.QueryString["dtfinal"];
                string tipoTabela = Request.QueryString["tipotab"];
                string tabela = Request.QueryString["tabl"];
                string classificacao = Request.QueryString["class"];
                string grupo = Request.QueryString["grp"];
                string autorizacao = Request.QueryString["aut"];

                //Carregar Lista de objetos RelatorioItensMatMed
                List<RelatorioItensMatMed> listaItensMatMed = (new Rel_ItensMaterialMedicamento_BS()).get_Rel_ItensMatMed_BS(dataInicial, dataFinal, tipoTabela, tabela, classificacao, grupo, autorizacao);

                //Preencher os dados do arquivo csv
                StringBuilder cabecalho = new StringBuilder();
                cabecalho.Append("Data de Inclusão;");
                cabecalho.Append("Tipo de Tabela;");
                cabecalho.Append("Tabela;");
                cabecalho.Append("Codigo;");
                cabecalho.Append("TUSS;");
                cabecalho.Append("Descrição;");
                cabecalho.Append("Fabricante;");
                cabecalho.Append("Referência do Fabricante;");
                cabecalho.Append("Registro ANVISA;");
                cabecalho.Append("Classificação SIMPRO;");
                cabecalho.Append("Grupo Mat/Med;");
                cabecalho.Append("Grupo Estatístico;");
                cabecalho.Append("Autorização Prévia;");
                cabecalho.Append("Última Vigência;");
                cabecalho.Append("Valor;");
                cabecalho.Append("Prestador Tabela Própria;");

                Response.Write(cabecalho.ToString());
                Response.Write("\r");

                foreach (var item in listaItensMatMed)
                {
                    StringBuilder itens = new StringBuilder();
                    itens.Append(item.DataInclusao + ";");
                    itens.Append(item.TipoTabela + ";");
                    itens.Append(item.Tabela + ";");
                    itens.Append("\t" + item.Codigo + ";");
                    itens.Append(item.TUSS + ";");
                    itens.Append(item.Descricao + ";");
                    itens.Append(item.Fabricante + ";");
                    itens.Append(item.ReferenciaFabricante + ";");
                    itens.Append(item.RegistroAnvisa + ";");
                    itens.Append(item.ClassificacaoSimpro + ";");
                    itens.Append(item.GrupoMatMed + ";");
                    itens.Append(item.GrupoEstatistico + ";");
                    itens.Append(item.AutorizacaoPrevisa + ";");
                    itens.Append(item.UltimaVigencia + ";");
                    itens.Append("\t" + item.Valor + ";");
                    itens.Append(item.PrestadorTabelaPropria + ";");

                    Response.Write(itens.ToString());

                    Response.Write("\r");
                    //Response.Flush();
                }

                Page.ClientScript.RegisterStartupScript(this.GetType(), "mensagem", "Final()", true);

                Response.ContentType = "text/plain";
                Response.AppendHeader("Content-Disposition", "attachment; filename=relacao_materiais_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".csv");
                Response.End();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    
asked by anonymous 18.01.2016 / 22:07

1 answer

0

Hello, I do not know if I understand your question very well.

But when you load a new page, the current document is closed and starts loading a new document. Any code in your current document will no longer be active when the new page starts loading.

In order to trigger the alert when the new page loads, you will either need to insert the code into the new page document or else load this page into an iframe and see when it is loaded into the current document, so you can trigger the alert.

    
18.01.2016 / 22:18