简体   繁体   English

ASP.NET AJAX控件工具包文件上传

[英]ASP.NET AJAX Control toolkit file upload

I'm having some difficulty implementing the ajax control toolkit file upload. 我在实现Ajax控制工具包文件上传时遇到了一些困难。 This is what i have coming up and the following is my code. 这就是我要提出的内容,以下是我的代码。 I'm sorry for using VB, i was forced. 很抱歉使用VB,我被迫。 If you know a C# solution please provide it and i will convert the code. 如果您知道C#解决方案,请提供它,我将转换代码。 Thank you 谢谢

忙碌的猫

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm2.aspx.vb" Inherits="AMS.WebForm2" %>

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>

<form id="form1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" />

    <asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" />
    <asp:Image ID="loader" runat="server"
        ImageUrl="~/loading.gif" Style="display: None" />
</form>
</body>
</html>

Code behind 后面的代码

Imports System.Web.Script.Serialization
Imports AjaxControlToolkit

Public Class WebForm2
Inherits System.Web.UI.Page

Protected Sub UploadComplete(sender As Object, e As AjaxControlToolkit.AjaxFileUploadEventArgs)
    Dim path As String = Server.MapPath("Files/") + e.FileName
    AjaxFileUpload1.SaveAs(path)
End Sub
End Class

Your UploadComplete method will never be called because it is never handled. 您的UploadComplete方法将永远不会被调用,因为它永远不会被处理。 Add the UploadComplete event of the control like so: 添加控件的UploadComplete事件,如下所示:

Protected Sub UploadComplete(sender As Object, e As AjaxControlToolkit.AjaxFileUploadEventArgs) Handles AjaxFileUpload1.UploadComplete
    Dim path As String = Server.MapPath("Files/") + e.FileName
    AjaxFileUpload1.SaveAs(path)
End Sub

Since the file upload control is only saving the file to a temp location at this point since your handler is never called, I believe the error you're getting is related to not setting an HTTP handler . 由于文件上传控件目前仅将文件保存到临时位置,因为从未调用过您的处理程序,因此我认为您遇到的错误与未设置HTTP处理程序有关 Otherwise, please specify the error. 否则,请指定错误。

Straight from the sample on the ajaxtoolkit site: 直接来自ajaxtoolkit站点上的示例:

The AjaxFileUpload control uses an HTTP Handler named AjaxFileUploadHandler.axd This handler has the type AjaxControlToolkit.AjaxFileUploadHandler. AjaxFileUpload控件使用一个名为AjaxFileUploadHandler.axd的HTTP处理程序。此处理程序的类型为AjaxControlToolkit.AjaxFileUploadHandler。 You must add this handler to your Web.Config file in order for the AjaxFileUpload control to work. 您必须将此处理程序添加到Web.Config文件中,以便AjaxFileUpload控件起作用。

Here's the Web.Config configuration that you must add: 这是您必须添加的Web.Config配置:

 <httpHandlers> <add verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/> </httpHandlers> 

For IIS7: 对于IIS7:

 <validation validateIntegratedModeConfiguration="false" /> <handlers> <add name="AjaxFileUploadHandler" verb="*" path="AjaxFileUploadHandler.axd" type="AjaxControlToolkit.AjaxFileUploadHandler, AjaxControlToolkit"/> </handlers> 

http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/AjaxFileUpload/AjaxFileUpload.aspx http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/AjaxFileUpload/AjaxFileUpload.aspx

You must add the following in web.config to make it work. 您必须在web.config中添加以下内容以使其起作用。

<system.web>
    ....
    <httpHandlers>
        <add verb="*" path="AjaxFileUploadHandler.axd"
          type="AjaxControlToolkit.AjaxFileUploadHandler, 
          AjaxControlToolkit"/>
    </httpHandlers>
</system.web>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM