使用asp.net在文件上传器ajaxcontrol上显示标签成功消息 [英] display label sucessful message on file uploader ajaxcontrol using asp.net
本文介绍了使用asp.net在文件上传器ajaxcontrol上显示标签成功消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有代码:
i have code:
<form id="form1" runat="server">
<div>
<div></div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<contenttemplate>
<asp:Label runat="server" ID="myThrobber" Style="display: none;"><img align="absmiddle" alt="" src="images/uploading.gif"/>
<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" OnUploadComplete="AjaxFileUpload1_UploadComplete"
OnClientUploadError="" ThrobberID="myThrobber" MaximumNumberOfFiles="1" AllowedFileTypes="" class="name_text1" Width="200px" />
<asp:Label ID="Label1" runat="server" Text="">
<asp:Button ID="BtnClose" runat="server" Text="Close"
onclick="BtnClose_Click" OnClientClick="Closepopup()"/>
<asp:Label ID="Label2" runat="server" Text="">
<br />
</contenttemplate>
</div>
</form>
.....................
i想要显示文件上传与否< Label2>请帮帮我...
.....................
i want to to display file upload or not on <Label2> please help me...
推荐答案
您已经在使用AjaxFileUpload1_UploadComplete事件。为什么不使用它?在此事件中设置标签的文本。
You are already using "AjaxFileUpload1_UploadComplete" event. Why not to use it? Set the label''s text in this event.
我同意 @Zafar Sultan 。
但我正在分享另一种方式在客户端进行。
如果你可以通过 AjaxFileUpload演示 [ ^ ]并最大化Link AjaxFileUpload事件,属性和方法,然后您将看到如下所有详细信息。
I agree with @Zafar Sultan.
But I am sharing another way to do it in client side.
If you can go through AjaxFileUpload Demonstration[^] and maximize the Link AjaxFileUpload Events, Properties and Methods, then you will see all the details like below.
活动
UploadedComplete - 在服务器上升起成功上传文件时在这种情况下,AjaxFileUploadEventArgs的实例在包含文件名,大小和内容类型的参数中传递。
属性
ThrobberID - 文件上传时显示的控件的ID。对于不支持HTML5文件API的浏览器,将显示图像。
ContextKeys - 可用于将信息传递给的字典上传文件时的服务器。
MaximumNumberOfFiles - 此属性允许您限制用户可以添加到上传的文件数queue。
AllowedFileTypes - 使用此属性可以限制可以上载的文件类型。您可以为此属性指定逗号分隔的文件扩展名列表。
IsInFileUploadPostBack - 在创建页面时,此属性的值为true响应AjaxFileUpload异步回发。
OnClientUploadComplete - 成功上载文件后在客户端执行的JavaScript函数的名称。
OnClientUploadError - 如果文件上传失败,则在客户端执行JavaScript函数的名称。
方法
SaveAs(字符串文件名) - 将上传文件的内容保存到文件系统。您的应用程序必须具有所需的写入权限。
Events
UploadedComplete - Raised on the server when a file is uploaded successfully. In this event an instance of AjaxFileUploadEventArgs is passed in the argument that contains file name, size and content type.
Properties
ThrobberID - The ID of a control that is shown while the file is uploading. The throbber image is displayed for browsers that do not support the HTML5 File API.
ContextKeys - A dictionary that can be used to pass information to the server when a file is uploaded.
MaximumNumberOfFiles - This property enables you to limit the number of files that a user can add to the upload queue.
AllowedFileTypes - This property enables you to restrict the types of files that can be uploaded. You can assign a comma delimited list of file extensions to this property.
IsInFileUploadPostBack - This property has the value true when a page is created in response to an AjaxFileUpload asynchronous postback.
OnClientUploadComplete - The name of a JavaScript function executed in the client-side after a file is uploaded successfully.
OnClientUploadError - The name of a JavaScript function executed in the client-side if the file upload failed.
Methods
SaveAs(string filename) - Saves the contents of an uploaded file to the file system. Your application must have the required Write permissions.
因此,您可以使用属性
1. OnClientUploadComplete 上传成功和
2. < b> OnClientUploadError 上传错误。
代码
标记将如下所示...
So, you can use the properties
1. OnClientUploadComplete for upload success and
2. OnClientUploadError for upload error.
Codes
Mark up will be like below...
<asp:AjaxFileUpload ID="AjaxFileUpload1"
runat="server"
OnUploadComplete="AjaxFileUpload1_UploadComplete"
OnClientUploadError="uploadError"
OnClientUploadComplete="uploadComplete"
ThrobberID="myThrobber"
MaximumNumberOfFiles="1"
AllowedFileTypes=""
class="name_text1"
Width="200px" />
JavaScript将是如下所示...
The JavaScript will be like below...
<script type="text/javascript">
function uploadComplete(sender) {
get( <%= Label2.ClientID%>)。innerHTML = 文件已成功上传;
}
function uploadError(sender){
get("<%=Label2.ClientID%>").innerHTML = "File Uploaded Successfully"; } function uploadError(sender) {
这篇关于使用asp.net在文件上传器ajaxcontrol上显示标签成功消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文