0

PROBLEM

When i put

<asp:FileUpload ID="FileUpload1" runat="server" class="multi" /> <br /> <asp:Button ID="btnUpload" runat="server" Text="Upload All" /> outside the update panel everything works fine,but as soon as i put it back into the update panel...it stops working.

ASPX CODE

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="try.aspx.vb" Inherits="AdminPanel_try" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../js/multi-upload/jquery-1.3.2.js" type="text/javascript"></script>
    <script src="../js/multi-upload/jquery.MultiFile.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
        <asp:FileUpload ID="FileUpload1" runat="server" class="multi" /> 
        <br />
        <asp:Button ID="btnUpload" runat="server" Text="Upload All" />
        </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnUpload" EventName="Click" />
            </Triggers>
        </asp:UpdatePanel>

    </div>
    </form>
</body>
</html>

CODE BEHIND

Partial Class AdminPanel_try
    Inherits System.Web.UI.Page
    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        Try
            ' Get the HttpFileCollection
            Dim hfc As HttpFileCollection = Request.Files
            For i As Integer = 0 To hfc.Count - 1
                Dim hpf As HttpPostedFile = hfc(i)
                If hpf.ContentLength > 0 Then
                    hpf.SaveAs(Server.MapPath("MyFiles") & "\" & System.IO.Path.GetFileName(hpf.FileName))
                    Response.Write("<b>File: </b>" & hpf.FileName & "  <b>Size:</b> " & hpf.ContentLength & "  <b>Type:</b> " & hpf.ContentType & " Uploaded Successfully <br/>")
                End If
            Next i
        Catch ex As Exception

        End Try
    End Sub
End Class

NOTE: i am using this tutorial kindly check this link

user1150440
  • 439
  • 2
  • 10
  • 23

1 Answers1

0

The UpdatePanel does not support all ASP.NET controls, FileUpload being one of them (http://msdn.microsoft.com/en-us/library/bb386454.aspx).

There are several examples on the Internet, and even here on StackOverflow, that will show you how to support asynchronous file uploads in ASP.NET.

Community
  • 1
  • 1
sellmeadog
  • 7,437
  • 1
  • 31
  • 45