Upload image inside Peater C# Asp.net

Asked

Viewed 164 times

0

Hello, I am new here and I am in need of a help. I already searched the net and the solutions I found do not work. I have an image gallery editing screen, made with a Repeater, in each image listed I have a button that opens a modalpopup Ajax with a Fileupload. This way I can replace the selected photo. The problem is that I can’t upload the photo. I just can’t find the Fileupload file on the button click on the Behind code. Can anyone help me? I’ve tried everything and I don’t 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

        }          

    }
  • Sorry I never worked with updatepanel, should I insert all the Repeater into the updatepanel? And because this way it takes the values of fileupload? Thanks!!

  • Repeateritem di = Btsave.Namingcontainer as Repeateritem;

1 answer

0

Enter your code inside an Updatepanel with the attribute Updatemode="Conditional", below:

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

In your page’s Page_load method enter the following code:

Page.Form.Attributes.Add("enctype", "multipart/form-data");
  • My problem is how to get fileupload. It is not passing the file to upload.

  • Take a look if this helps: https://stackoverflow.com/questions/8487984/adressing-a-fileupload-within-a-repeater

Browser other questions tagged

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