Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

FileUpload Inside a Repeater Can't Find File

$
0
0

My code is like this :

<asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate><asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource4" OnItemCommand="Repeater1_ItemCommand"><HeaderTemplate><table ID="Table1"></HeaderTemplate><ItemTemplate><tr><td><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></asp:Panel></td></tr></ItemTemplate><FooterTemplate></table></FooterTemplate></asp:Repeater></ContentTemplate></asp:UpdatePanel>

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)
                {
                    try
                    {
                        string filename = Path.GetFileName(myFileUpload.FileName);
                        myFileUpload.SaveAs(Server.MapPath("~/") + filename);
                        myStatusLabel.Text = "Upload Success";
                    }
                    catch (Exception ex)
                    {
                        
                        myStatusLabel.Text = "Upload Fail" + ex.Message;
                    }
                }
                else
                {
                    
                    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,


Viewing all articles
Browse latest Browse all 5678

Trending Articles