Ajax introduced two new controls AsyncFileUpload and SeaDragon, in this article we will see about Asynchronous file upload control, with its different properties and usage.
AsyncFileUpload: by using this control we can upload a file asynchronously (without postback). The file uploading results can be checked both in the server and client sides.
SeaDrago: The Seadragon control can be used for viewing Deep Zoom images. Use your mouse to pan and zoom around the image.
One thing we need to note that this control can work with only .Net 3.5 or greater.
Let's see it's properties:
Methods : Only one method "SaveAs" to save the file
Events:
It's enough to understand the control, events, methods and properties. Now let's see control in action
Here is the code which will only upload images of type jpg, gif and png
HTML and JavaScript:
<asp:scriptmanager ID="scriptmanager1" runat="server" />
<div>
<asp:AsyncFileUpload
ID="AsyncFileUpload1"
runat="server"
Width="400px"
UploadingBackColor="#345678"
CompleteBackColor="#FFFFFF"
OnClientUploadError="UploadError"
OnClientUploadComplete="UploadCompleted"
UploaderStyle="Modern"
ThrobberID="imgWait"
OnUploadedFileError="AsyncFileUpload1_UploadedFileError"
OnUploadedComplete="AsyncFileUpload1_UploadedComplete" />
</div>
<div>
<asp:Image ID="imgWait" runat="server" ImageUrl="/images/process.gif" />
</div>
<div style="color:Green">
<asp:Label ID="lblMessage" runat="server" Text="" EnableViewState="false" />
</div>
<script type="text/javascript">
var msg = document.getElementById('<%=lblMessage.ClientID %>');
alert(msg);
function UploadCompleted() {
msg.innerHTML = "Successfully uploaded!!!";
}
function UploadError() {
msg.innerHTML = "Failed to upload your file!";
}
</script>
And Here is the code behind:
protected void AsyncFileUpload1_UploadedFileError(object sender,
AsyncFileUploadEventArgs e)
{
lblMessage.Text = "Could not upload file!";
}
protected void AsyncFileUpload1_UploadedComplete(object sender,
AsyncFileUploadEventArgs e)
{
string contentType = AsyncFileUpload1.ContentType;
if (contentType == "image/jpeg" || contentType == "image/gif"
|| contentType == "image/png")
{
string filename = System.IO.Path.GetFileName(AsyncFileUpload1.FileName);
AsyncFileUpload1.SaveAs(Server.MapPath("UploadedFiles/") + filename);
}
else
{
lblMessage.Text = "We support only images of type jpg, gif and png";
}
}
![]() |
Having 13+ years of experience in Microsoft Technologies (C#, ASP.Net, MVC and SQL Server). Worked with Metaoption LLC, for more than 9 years and still with the same company. Always ready to learn new technologies and tricks.
|
By Ali Adravi On 20 May, 13 Viewed: 6,708 |
How to post the data from json, in Angularjs $http.post we get this error. why we get this error only when we try to post the json object rather than query string. When we pass the parameter in query string same action method works as it should be. It's a very simple article so we are going to... By Ali Adravi On 12 Jul 2015 Viewed: 17,866
this blog has been... By Amin Rahdar On 26 May 2015 Viewed: 343
Ajax Rounded corners extender is used to give corner to any elements like panel and div etc. Most of the time you will need to give the padding to give some space between the border and content, same is used for margin to give some vertical and horizontal space between different controls, but if... By Alicia Gonzalez On 15 Jun 2013 Viewed: 861
Country will be filled on page load and once user will select any country we will fill states from that country and again when user will change state we will fill city for that state without postback ( asynchronously) with the help of update panel in asp.net. Create three methods to fetch... By Hamden On 04 May 2013 Viewed: 6,195
In this article we will discuss different way of show and hide (open and close) modal popup by using Ajax ModalPopupExtender, how to open/close a modal popup from code behind in asp.net or by using JavaScript, how to use multiple buttons to hide the modal popup in asp.net etc. Suppose we have a... By Jonathan King On 08 Apr 2013 Viewed: 28,698