AjaxUploadControl 不会触发 onuploadcomplete 方法 [英] AjaxUploadControl does not fire onuploadcomplete method

查看:45
本文介绍了AjaxUploadControl 不会触发 onuploadcomplete 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的站点上实现 AjaxUploadControl 功能,但它没有触发 OnUploadComplete 方法.相反,它只是说文件已 100% 上传,但文件不在指定的文件夹中.我在 OnUploadComplete 方法中设置了断点,并且已经能够确定永远不会到达该方法.当取消"按钮显示时,它几乎似乎跳入了无限循环,但是一旦尝试上传文件,屏幕上的任何按钮都不可点击.

.aspx 页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxTest.aspx.cs" Inherits="AjaxTest" %><!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="服务器"><title></title><身体><form id="form1" runat="server"><ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager><div><ajaxToolkit:AjaxFileUpload ID="ajaxUpload1" runat="server" OnUploadComplete="ajaxUpload1_OnUploadComplete"/>

</表单>

代码隐藏文件:

使用系统;使用 System.Collections.Generic;使用 System.Linq;使用 System.Web;使用 System.Web.UI;使用 System.Web.UI.WebControls;公共部分类 AjaxTest : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){}protected void ajaxUpload1_OnUploadComplete(对象发送者,AjaxControlToolkit.AjaxFileUploadEventArgs e){string filePath = "~/SiteImages/" + e.FileName;ajaxUpload1.SaveAs(MapPath(filePath));}}

非常感谢您的帮助!

解决方案

我发现了我遇到的问题.我试图在网站与网络应用程序中实现该功能.我创建了一个测试网络应用程序平台,它运行完美.我是 AJAX 的初学者,并没有意识到这会导致问题,但是,有没有人知道让此功能在网站中工作的解决方案.恐怕目前有太多内容无法轻松移植到网络应用程序.

I am trying to implement the AjaxUploadControl functionality on my site but it does not fire the OnUploadComplete method. Instead, it simply says file uploaded 100%, but the file is not in the specified folders. I have set breakpoints in the OnUploadComplete method and have been able to determine that this method is never being reached. It almost seems to be jumping into an infinite loop as the Cancel button displays, but none of the buttons on the screen are clickable once an attempt has been made to upload a file.

The .aspx page:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxTest.aspx.cs" Inherits="AjaxTest" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
        <ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </ajaxToolkit:ToolkitScriptManager>
    <div>
            <ajaxToolkit:AjaxFileUpload ID="ajaxUpload1" runat="server" OnUploadComplete="ajaxUpload1_OnUploadComplete" />
    </div>
    </form>
</body>
</html>

The codebehind file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class AjaxTest : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void ajaxUpload1_OnUploadComplete(object sender,   AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        string filePath = "~/SiteImages/" + e.FileName;
        ajaxUpload1.SaveAs(MapPath(filePath));
    }
}

Help is greatly appreciated!

解决方案

I discovered the problem that I am having. I was trying to implement the functionality in a website versus a web app. I created a test web app platform and it worked flawlessly. I am a beginner to AJAX and did not realize that this would cause issues, however, does anyone know a solution to get this functionality to work in a website. I'm afraid that there is too much to easily port over to web app at this time.

这篇关于AjaxUploadControl 不会触发 onuploadcomplete 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆