[RESOLVED]FileUpload Inside a Repeater Can't Find File

My code is like this :

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource4" OnItemCommand="Repeater1_ItemCommand">
            <table ID="Table1">
                    <asp:BulletedList ID="BulletedList1" runat="server" DataSourceID="SqlDataSource6" DataTextField="WPName" DataValueField="WPName"></asp:BulletedList>
                    <asp:Button ID="Button2" runat="server" Text="Add KKP" CommandName="AddKKP"/>
                    <asp:Panel ID="Panel1" runat="server" Visible="false">
                        <asp:FileUpload ID="FileUpload1" runat="server" />
                        <asp:Button ID="Button3" runat="server" Text="Upload" CommandName="UploadKKP" />
                        <asp:Label ID="StatusLabel" runat="server" Text="Label"></asp:Label>

and CodeBehind :

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
            if (e.CommandName == "AddKKP")
                Panel myPanel = (Panel)e.Item.FindControl("Panel1");
                myPanel.Visible = true;                

            if (e.CommandName == "UploadKKP")
                Label myStatusLabel = (Label)e.Item.FindControl("StatusLabel");
                FileUpload myFileUpload = (FileUpload)e.Item.FindControl("FileUpload1");
                if (myFileUpload.HasFile)
                        string filename = Path.GetFileName(myFileUpload.FileName);
                        myFileUpload.SaveAs(Server.MapPath("~/") + filename);
                        myStatusLabel.Text = "Upload Success";
                    catch (Exception ex)
                        myStatusLabel.Text = "Upload Fail" + ex.Message;
                    myStatusLabel.Text = "myFileUpload Has No File";

The problem is, it always throw myStatusLabel.Text = "myFileUpload Has No File";

how can i fix it ?

Thanks for your help.

Best Regards,

Use ajax file upload instead


Fileupload control not work in update panel

I’m trying to use AJAXControlToolkit, but it get an error :

‘MsAjaxBundle’ is not a valid script name.  The name must end in ‘.js’.

how can i fix it ?


Refer below thread,


Hope this will helps..!!

Leave a Reply