文字控制不更新

时间:2011-05-30 19:24:15

标签: c# asp.net file-upload upload uploadify

我正在使用一个名为uploadify的插件来向用户显示文件上传进度。 uploadify脚本调用default.aspx(异步)。在default.aspx的Page_Load方法中,我对通过它传递的其他表单数据运行验证检查。

如果验证检查失败,我想使用文字控件显示错误消息,然后退出。问题是文字控件没有使用验证错误消息进行更新。

已更新

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpContext context = HttpContext.Current;


        if (context.Request.Files["Filedata"] != null)
        {
            if (context.Request["Name"] == null)
            {
                litValidationErrors.InnerHtml = "Please enter a name";

                return;
            }
        }
    }
}


 <script type="text/javascript">
    $(document).ready(function ()
    {
        $('#file_upload').uploadify({
            'uploader': '/Plugins/Uploadify/uploadify.swf',
            'script': '/default.aspx',
            'cancelImg': '/Plugins/Uploadify/images/cancel.png',
            'folder': '/FileUploads',
            'auto': false,

            'onComplete': function (event, ID, fileObj, response, data)
            {
                var uploadifyResponse = $("#<%= litValidationErrors.ClientID %>", $(response));

                if (uploadifyResponse.length > 0)
                {
                    $("#<%= litValidationErrors.ClientID %>").css("display", "inline").text(uploadifyResponse.text());
                }
            }

        });


        $('#MainContent_superSubmit').click(function ()
        {
            var jsonFormData = {
                'Name': $('#MainContent_txtName').val(),
                'Password': $('#MainContent_txtPassword').val()
            };

            $('#file_upload').uploadifySettings('scriptData', jsonFormData);
            $('#file_upload').uploadifyUpload();
        });
    });
</script>


    <html>
    .....
    <asp:Button ID="superSubmit" runat="server" Text="Button"  />
 <span id="litValidationErrors" runat="server" style="display: none; color: #ff0000;"></span>
    </html>

2 个答案:

答案 0 :(得分:1)

将litValidationErrors控件从Literal更改为runat =“server”的范围,删除Visible =“false”并通过设置style =“display:none;”将其隐藏。另外,将onComplete事件处理程序添加到uploadify:

$(function () {
        $('#file_upload').uploadify({
            'uploader': '/Plugins/Uploadify/uploadify.swf',
            'script': '/WebForm1.aspx',
            'expressInstall': '/Plugins/UploadifyexpressInstall.swf',
            'cancelImg': '/Plugins/Uploadify/images/cancel.png',
            'folder': '/App_Data/FileUploads',
            'auto': false,

            'onComplete': function (event, ID, fileObj, response, data) {
                var uploadifyResponse = $("#<%= litValidationErrors.ClientID %>", $(response));

                if (uploadifyResponse.length > 0) {
                    $("#<%= litValidationErrors.ClientID %>").css("display", "inline").text(uploadifyResponse.text());
                }
            }
        });
    });

答案 1 :(得分:0)

为脚本添加回调函数,以更新文字控件的文本