如何将值从处理程序传递到aspx页面作为响应

How to pass a value from handler to aspx page as a response

本文关键字:aspx 响应 程序 处理      更新时间:2023-09-26

我在处理程序中添加文件名作为响应,在我的JavaScript中,我试图获取我添加到处理程序中的值,并将其保存到一个隐藏字段中。但是,隐藏字段值始终为null。我没有得到添加到响应中的文件名。如何从处理程序获得文件名作为响应

public class Upload : IHttpHandler, System.Web.SessionState.IRequiresSessionState   
{    
    public void ProcessRequest (HttpContext context) 
    {
        context.Response.Write(filename);
        context.Response.StatusCode = 200;
    }
}

    <script type="text/javascript">
        $(document).ready(function () {
            $("#<%=AFU_Video.ClientID%>").uploadify({
                'uploader': 'scripts/uploadify.swf',
                'script': 'Upload.ashx',
                'buttonText': 'Video',
                'cancelImg': 'images/cancel.png',
                'folder': 'D:'Media',
                'fileExt': '*.mp4',
                'fileDesc': 'Video Files (.mp4 Only)',
                'multi': true,
                'auto': true,
                'onComplete': function (event, ID, fileObj, response, data) {
                    document.getElementById("<%= Hidd_VideoLoc.ClientID %>").value = response.filename;

您正试图使用响应对象的filename属性,但由于返回的是纯文本,因此没有此类属性。

只需使用响应:

document.getElementById("<%= Hidd_VideoLoc.ClientID %>").value = response;