Liq*_*uid 8 javascript asp.net listview asp.net-ajax
AsyncFileUpload在Listview Insert,Edit Itemtemplate和EmptyData Template中不起作用.
以上是我的客户端功能
function AttachmentUploadSuccessful() {
debugger;
var textError = $(".AttachmentError").text();
if (textError.length > 0) {
var text = $(".AttachmentError");
text.innerText = text.textContent = textError;
sender._onError(textError); // it will raise the OnClientUploadError event
return;
} else {
//alert(" File attachment is uploaded successfully.");
//CODE TO REMOVE FILE AND BACKGROUND COLOR OF FILE UPLOADER
$('.ModelBackgroundforCreateItem').hide();
$('.PopupPanel').hide();
var UploadControls = $('#<%= FileUpload.ClientID %> :input');
UploadControls.each(function () {
//$(this).val("");
$(this).css('background-color', '#fff');
});
//Updating Update panel by clicking button
$(".RefreshList").click();
}
}
function AttachmentUploadFailed() {
alert("An error occured while uploading File Attachment. ");
}
Run Code Online (Sandbox Code Playgroud)
.aspx文件中的标记
<asp:ListView ID="ListView2" runat="server">
<EmptyDataTemplate>
<table class="fileUpload" runat="server" id="FileUploadID">
<tr>
<td>
<div style="width: 350px; overflow-x: hidden;">
<asp:AsyncFileUpload runat="server" ID="FileUpload" ThrobberID="Throbber" OnClientUploadError="AttachmentUploadFailed"
OnClientUploadComplete="AttachmentUploadSuccessful" UploaderStyle="Traditional" UploadingBackColor="" Style="display: inline-block; margin-top: 5px;"
OnUploadedComplete="FileUpload_UploadedComplete">
</asp:AsyncFileUpload>
</div>
</td>
<td style="width: 30px">
<asp:Image ID="Throbber" ImageUrl="~/Image/AttachmentLoading.gif" Style="display: None; width: 20px;" runat="server" />
<br />
</td>
</tr>
</table>
</EmptyDataTemplate>
</asp:ListView>
Run Code Online (Sandbox Code Playgroud)
试图上传文件客户端事件OnClientUploadError被调用无法理解为什么它会给出错误.在简单页面和内部更新面板上工作相同的文件上传,但在列表视图内,它给客户端错误.通过以上链接问题没有得到确切的答案请帮帮我.
我可以在您共享的代码中看到两个问题:
var UploadControls = $('#<%= FileUpload.ClientID %> :input')ClientIDMode而且你的标记中没有属性,所以它是Inherit这两个问题有相同的根源:您正在使用AsyncFileUploader内部 a ListView,因此您的页面中将有多个具有该FileUploadid 的元素。
因此,首先必须将函数声明更改为:
function AttachmentUploadSuccessful(sender, e) { // then you can get the sender
Run Code Online (Sandbox Code Playgroud)
然后,要获取 the input,您将使用:
var UploadControls = $(sender._inputFile);
Run Code Online (Sandbox Code Playgroud)
最后,要解决第二个问题,您需要将ClientIDMode属性更改为AutoID,以便AsyncFileUploader能够正确找到其引用的客户端成员。
| 归档时间: |
|
| 查看次数: |
251 次 |
| 最近记录: |