Uploading image inside repeater C # asp.net

0

Hello, I'm new here and I need some help. I already researched the net and the solutions I found do not work. I have an image gallery editing screen, made with a repeater, on each image listed I have a button that opens an Ajax modalpopup with a Fileupload. This way I can replace the selected photo. The problem is that I can not upload the photo. I just can not find the Fileupload file in the button click on the code behind. Can someone help me? I've tried everything and I do not know what I'm doing wrong. html:

 <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <div class="card">
                <img src='<%# "../fotosanuncios/" + Eval("idAnuncio") + "/" + Eval("NomeFotoMini") %>'/>
                <div class="containerCard">
                <asp:LinkButton ID="LBSubstituir" runat="server" ToolTip="Substituir Foto"><i class="fa fa-pencil-square-o fa-lg" aria-hidden="true"></i></asp:LinkButton>&nbsp;&nbsp;&nbsp;&nbsp;
                 <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtenderSub" runat="server" BackgroundCssClass="modalBackground" TargetControlID="LBSubstituir" PopupControlID="PanelSubstituir" CancelControlID="BtCancelar" DropShadow="True"></ajaxToolkit:ModalPopupExtender>
                <asp:Panel ID="PanelSubstituir" runat="server" CssClass="modalPopup" style="width:400px;">
                    <asp:FileUpload ID="FileUpload2" runat="server" CssClass="cg-inputform" /><br />
                    <asp:Button ID="BtCancelar" Text="Cancelar" runat="server" CssClass="cg-inputGrey" />&nbsp;&nbsp;
                    <asp:Button ID="BtSalvar" Text="Salvar" runat="server" OnClick="BtSalvar_Click" CommandArgument='<%# Eval("idFoto") + "," + Eval("nomeFoto") + "," + Eval("nomeFotoMini") %>' CssClass="cg-inputGreen" />
                </asp:Panel>

                 <asp:LinkButton ID="LinkButtonRight" runat="server" OnClick="LinkButtonRight_Click" CommandArgument='<%# Eval("idFoto") + "," + Eval("nomeFoto") + "," + Eval("nomeFotoMini") %>' ToolTip="Girar a Direita"><i class="fa fa-repeat" aria-hidden="true"></i></asp:LinkButton>&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:LinkButton ID="LinkButtonLeft" runat="server" OnClick="LinkButtonLeft_Click" CommandArgument='<%# Eval("idFoto") + "," + Eval("nomeFoto") + "," + Eval("nomeFotoMini") %>' ToolTip="Girar a esquerda"><i class="fa fa-undo" aria-hidden="true"></i></asp:LinkButton>
            </div>
        </div>
    </ItemTemplate>

My codebehind

protected void BtSalvar_Click(object sender, EventArgs e)
        {



              int idAnuncio = Convert.ToInt32(this.Request.QueryString["idAnuncio"]);

                Button BtSalvar = sender as Button;

                string[] commandArgs = BtSalvar.CommandArgument.ToString().Split(new char[] { ',' });
                string idFoto = commandArgs[0];
                string NomeFoto = commandArgs[1];
                string NomeFotoMini = commandArgs[2];


                RepeaterI

tem di = BtSalvar.NamingContainer as RepeaterItem;
            FileUpload fUpload = di.FindControl("FileUpload2") as FileUpload;



            if (fUpload.HasFile)
            {
        //salva a foto

        }          

    }
    
asked by anonymous 06.06.2017 / 18:33

1 answer

0

Insert your code into an UpdatePanel with the UpdateMode="Conditional" attribute, below:

<asp:UpdatePanel ID="upGeral" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">

In the Page_Load method of your page enter the following code:

Page.Form.Attributes.Add("enctype", "multipart/form-data");
    
07.06.2017 / 20:23