2

我有一个带有 HiddenField、UpLoad 控件和 DropDownList 的 UserControl,这些控件在 SharePoint 解决方案的 ASPX 页面上被引用。控件的标记是:

<ig:WebDropDown ID="WebDropDownDocumentType" runat="server" Width="135px" DataSourceID="DataSourceDocumentType" DataKeyFields="Id" ValueField="Id" TextField="Name" AutoPostBack="False" ClientEvents-SelectionChanged="WebDropDownDocumentType_SelectionChanged">
<asp:HiddenField ID="hdnDocumentType" runat="server" />
<ig:WebUpload ID="WebUploadSupportingDocuments" runat="server" ProgressUrl="/WebUploadStatusHandler.ashx" Height="100px" MaxSimultaneousFilesUploads="1" Width="100px" OnUploadFinished="WebUploadSupportingDocuments_UploadFinished" AutoStartUpload="True" OnUploadStarting="WebUploadSupportingDocuments_UploadStarting" >

当为 DropDownList 更改所选索引时,将调用一个 javascript 函数来设置 HiddenField 值。我还添加了一个警报来验证 HiddenField 是否包含该值并且它确实显示了预期值。这是功能:

function WebDropDownDocumentType_SelectionChanged(sender, e) {
        var wddObject = sender, 
        selectedIndex = wddObject.get_selectedItemIndex(), value;
        value = wddObject.get_items().getItem(selectedIndex).get_value();
        document.getElementById('<%=hdnDocumentType.ClientID %>').value = value;       
        alert(document.getElementById('<%=hdnDocumentType.ClientID %>').value);
    }

从 DropDownList 中选择一个项目后,我看到函数调用并验证警报中的值是否正确。然后我单击按钮选择要上传的文件并触发 UploadFinished 事件。当我在 UploadFinished 事件中设置断点并检查 HiddenField 的值而不是预期值时,它是一个空字符串。

string sDocumentType = hdnDocumentType.Value;

如果我不关闭页面并上传另一个文件,则它在下拉列表中具有所选项目的值。如果我然后从下拉列表中选择另一个项目并上传另一个文件,它具有上一个选择,然后在下一个文件上上传下一个选择。所以它第一次是一个空字符串,然后我上传的每个文件后面都有一个选择。

我不确定为什么该值没有持续存在,并且正在寻找有关如何解决该问题的建议。

4

1 回答 1

1

The cause of the problem can be upload component. It can use iframe to upload files to server (this is how for example Async File Upload from Ajax Control Toolkit and some other upload component work). This can be the cause of the problem why hidden field is empty (because request was done from iframe). If this is your case then you need to handle client side event which will notify you when upload is completed (of course if this component support them) and perform postback manually (or ajax request) to perform required actions.

于 2012-11-23T22:04:56.527 回答