How to give a POST on the page with UPLOAD property without going into looping?

0

Looking at the internet I saw some sites saying that when you have a Upload property on the page you can not give POST in it because it looping .

I have an application that creates / deletes folders and displays a POST message on the page so that it enters looping , and thus returning error .

MyquestionwouldbehowtogiveaPOSTonthepageinordertoupdateforminformationwithoutgoingintothislooping?

ExampleofUploadingFileUploadFileevent:

protectedvoidBtnCarregar_Click(objectsender,EventArgse){try{stringcaminho=ConfigurationManager.AppSettings["PastaRaiz"];
            var source = Directory.GetDirectories(caminho).Select(c => new DirectoryInfo(c).Name).ToList();
            if (ddlFolders.SelectedValue != null)
            {
                if (FileUpload1.HasFile)
                {
                    string fileName = FileUpload1.FileName;
                    if (!Directory.Exists(caminho + ddlFolders.SelectedValue + "/" + fileName))
                    {
                        FileUpload1.PostedFile.SaveAs(caminho + ddlFolders.SelectedValue + "/" + fileName);
                    }
                    else
                    {
                        mensagens.ExibirMensagem("Mensagem", "Arquivo já existente no diretório.", false, this.Page, this.GetType());
                    }
                }
            }
            mensagens.ExibirMensagem("Mensagem", "Arquivo  carregado com sucesso.", false, this.Page, this.GetType());

        }
        catch (Exception ex)
        {

            throw ex;
        }

    }
    
asked by anonymous 08.05.2018 / 22:39

1 answer

1

As said in the comments, this happens because clicking the bntCarregar button is invoking an event in the backend, which in turn is triggered by a post on the client side, the famous PostScript WebForms. In the browser is a common submit, but in ASP.NET this can trigger other events that change components and which in turn may be configured to perform a new postback when they have their status changed.

You should increase the appropriate treatment on the Page_Load() method of your page. E or map what's linking this loop.

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        //... Tratamentos necessários para o carregamento correto da sua página
    }
}

Note: My suspicion is that the loop is related to the ExibirMensagem() method, since it receives this.Page as a parameter

    
09.05.2018 / 18:10