0

所以我已经被这个问题困住了好几个小时,搜索了论坛,尝试了人们建议的一切,但我就是无法让它工作。

我有一个(相当大的)网络表单。表单上的某处是一个 updatePanel,其中包含一个 CuteSoft Ajax Uploader 控件。当上传文件时,该控件在我的代码中调用一个函数 - 这工作正常。在该函数中,我对 updatePanel 中的内容进行了一些更改(添加缩略图等),但是这些更改永远不会反映在前端。

这是表格(去掉了不相关的部分):

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VehicleSubmissionWizard.ascx.cs"
    Inherits="MaxAdmin.UserControls.VehicleSubmissionWizard" %>
...
<div id="template3" style="display: none;">
    <div class="top-section">
        <div id="column-left">
            ...
        <div id="column-right">
            ...
    <form runat="server" id="form1" action="">
    <%--Panel 1--%>
    <asp:Panel runat="server" ID="pnlSubmissionWizard1">
        ...
    </asp:Panel>
    <%--/Panel 1--%>
    <%--Panel 2--%>
    <asp:Panel runat="server" ID="pnlSubmissionWizard2">
        ...
            <h2>
                Vehicle images</h2>
            <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"
                AjaxFrameworkMode="Enabled" ClientIDMode="Static" EnableViewState="true" LoadScriptsBeforeUI="true"
                ScriptMode="Auto" ViewStateMode="Enabled">
            </asp:ScriptManager>
            <asp:UpdatePanel runat="server" EnableViewState="false" ID="upImageUpload" UpdateMode="Conditional">
                <Triggers>
                    <%--                    <asp:AsyncPostBackTrigger ControlID="Uploader" 
                           EventName="FileUploaded" />
                    --%>
                </Triggers>
                <ContentTemplate>
                    <input id="hdnImages" class="imagesUpload" type="hidden" />
                    <asp:HiddenField ID="hdn" runat="server" />
                    <CuteWebUI:Uploader ID="Uploader" runat="server" EnableViewState="false" MaxFilesLimit="3"
                        MaxFilesLimitMsg="Please upload a maximum of 3 photos" InsertButtonStyle-Width="280px"
                        MultipleFilesUpload="true" InsertText="Upload Photos [Max 3 Photos at up to 4mb each]"
                        OnFileUploaded="Uploader_FileUploaded" OnUploadCompleted="Uploader_Complete">
                        <ValidateOption MaxSizeKB="4096" AllowedFileExtensions="jpg,gif,png" />
                    </CuteWebUI:Uploader>
                    <div id="attachmentsDiv">
                        <CuteWebUI:UploadAttachments EnableViewState="false" runat="server" ID="Attachments"
                            MaxFilesLimit="3" Visible="false">
                            <ValidateOption MaxSizeKB="4096" AllowedFileExtensions="jpg,gif,png" />
                        </CuteWebUI:UploadAttachments>
                    </div>
                    <br />
                    <asp:Panel ID="pnlImageDetails_1" runat="server" CssClass="display_none" Style="float: left;
                        margin-bottom: 0">
                        <div class="uploadedImage" style="clear: both; float: left; margin: 5px 20px 5px 75px;">
                            <div style="text-align: center">
                                <asp:Image ID="imgUploadedImage1" runat="server" />
                            </div>
                            <div style="text-align: center">
                                <asp:LinkButton ID="btnRemoveImage_1" runat="server" OnCommand="RemoveImage_Click"
                                    CommandName="1" Text="Remove Image" CssClass="RemoveLinkButton" Style="margin-left: 15px;" />
                            </div>
                        </div>
                    </asp:Panel>
                    <asp:Panel ID="pnlImageDetails_2" runat="server" CssClass="display_none" Style="float: left;">
                        <div class="uploadedImage" style="clear: both; float: left; margin: 5px 20px 5px 20px;">
                            <div style="text-align: center">
                                <asp:Image ID="imgUploadedImage2" runat="server" />
                            </div>
                            <div style="text-align: center">
                                <asp:LinkButton ID="btnRemoveImage_2" runat="server" OnCommand="RemoveImage_Click"
                                    CommandName="2" Text="Remove Image" CssClass="RemoveLinkButton" Style="margin-left: 15px;" />
                            </div>
                        </div>
                    </asp:Panel>
                    <asp:Panel ID="pnlImageDetails_3" runat="server" CssClass="display_none" Style="float: left;">
                        <div class="uploadedImage" style="clear: both; float: left; margin: 5px 20px 5px 20px;">
                            <div style="text-align: center">
                                <asp:Image ID="imgUploadedImage3" runat="server" />
                            </div>
                            <div style="text-align: center">
                                <asp:LinkButton ID="btnRemoveImage_3" runat="server" OnCommand="RemoveImage_Click"
                                    CommandName="3" Text="Remove Image" CssClass="RemoveLinkButton" Style="margin-left: 15px;" />
                            </div>
                        </div>
                    </asp:Panel>
                    <script language="javascript" type="text/javascript">
                        var Image_Count = $('#<%= hdn.ClientID %>').val(); 
                    </script>
                </ContentTemplate>
            </asp:UpdatePanel>
            ...
    </asp:Panel>
    <%-- / Panel 2--%>
    <%--Panel 3--%>
    <asp:Panel runat="server" ID="pnlSubmissionWizard3">
        ...
    </asp:Panel>
    <%-- / Panel 3--%>
    <%-- Panel 4--%>
    <asp:Panel Visible="false" runat="server" ID="pnlSubmissionWizard4">
        ...
    </asp:Panel>
    <%-- / Panel 4--%>
    </form>
    ...
</div>

代码隐藏看起来像这样:

...

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            //Uploader.FileUploaded += new CuteWebUI.UploaderEventHandler(Uploader_FileUploaded);
            Uploader.FileUploaded += Uploader_FileUploaded;
            Uploader.UploadCompleted += Uploader_Complete;
            Attachments.AttachmentRemoveClicked += Attachments_AttachmentRemoveClicked;
            Attachments.InsertButton.Style["display"] = "none";
            ((HiddenField)FindControl("hdn")).Value = "0";
        }

...

        protected void Uploader_FileUploaded(object sender, CuteWebUI.UploaderEventArgs args)
        {
            ...

                using (System.IO.Stream stream = args.OpenStream())
                {
                    // Check if file already exists - seems to do each image twice for some reason...
                    foreach (var ph in Photos)
                        if (String.Equals(ph.FileName, args.FileName))
                            return;

                    ...

                    // Show image thumbnail
                    ShowUploadedPhotoDetails(p, ImageCount);
                }
            }
            catch (Exception ex)
            {
               ...
            }
        }

    private void ShowUploadedPhotoDetails(Photo photo, int imageNo)
    {
        if (imageNo <= 3)
        {
            var imagePanel = (Panel)FindControl(String.Concat("pnlImageDetails_", imageNo));
            imagePanel.CssClass = "display_block";
            imagePanel.Visible = true;

            var uploadedImage = (System.Web.UI.WebControls.Image)FindControl(String.Concat("imgUploadedImage", imageNo));
            uploadedImage.ImageUrl = photo.ImageUrlThumb;
            uploadedImage.Visible = true;
            uploadedImage.CssClass = "CSS_CLASS";
        }
    }

        protected void Uploader_Complete(object sender, CuteWebUI.UploaderEventArgs[] args)
        {
            Uploader uploader = (Uploader)sender;
            uploader.InsertButton.Enabled = (Photos.Count < 3);

            // Force updatePanel to update
            upImageUpload.Update();
        }

因此,当上传图像时,上述两个函数都会触发。图像数据很好。调试分配给控件的值(例如:ImageUrl、CssClass 等)表明它们已正确分配给控件。但是这些值永远不会在前端刷新。

有什么我错过的想法吗?

非常感谢格雷格

4

2 回答 2

0

呸,我明白了!!!基本上我重建了整个表格,一步一步繁琐的小步骤。虽然我不确切知道是什么阻止了它的工作,但我怀疑它可能是由表单其他部分的按钮上设置的以下属性引起的:

PostbackUrl = ".."

将其添加回我的工作表单会导致 updatePanel 中断..但是从我原来的损坏表单中删除它并不能修复它,所以那里可能还有其他东西。

没有更改任何代码,因此它与事件排序等无关(尽管 TheGeekYouNeed 是个好主意。

这是一个从 Asp.Net 2.0 更新到 4.0 的项目。也许升级中的某些东西搞砸了。谁知道呢,反正至少它是固定的。呸!

于 2013-04-03T00:13:04.117 回答
0

如果 UpdatePanel 中有任何错误,包括 div 标签格式不正确等,则可能不会刷新面板。如果您没有让 UpdatePanel 刷新并且您已经尝试了所有常见的事情 .Update() 等,那么请检查您的 UpdatePanel 内容是否存在任何问题,它应该可以解决它。

于 2018-11-13T22:30:29.963 回答