簡體   English   中英

文字控件不更新

[英]Literal control not updating

我正在使用一個名為 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>

將 litValidationErrors 控件從 Literal 更改為具有 runat="server" 的 span,刪除 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());
                }
            }
        });
    });

將回調 function 添加到您的腳本中,這將更新文字控制的文本

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM