Skip to main content

How to use AsyncFileUpload in asp.net ajax


AsyncFileUpload in asp.net ajax



AsyncFileUpload is an asp.net ajax control. AsyncFileUpload control allow us to asynchronously upload files
to web server. this control provide a way to check file uploading results both in the server side and client side.




AsyncFileUpload control have the following useful properties those are CompleteBackColor, ContentType, ErrorBackColor,
FileContent, FileName, HasFile, OnClientUploadComplete, OnClientUploadError, OnClientUploadStarted, PostedFile,
ThrobberID, UploaderStyle, UploadingBackColor, and Width.




AsyncFileUpload ajax control CompleteBackColor property value is a color name which color show as AsyncFileUpload
control's background color when upload complete. ErrorBackColor property set a color name which color display as
control's background color when file upload occurs an error. UploadingBackColor property assign a color name which color
show as control's background color when file upload is in progress.




AsyncFileUpload control's ContentType property get the MIME content type of a file which file sent by a client browser.
FileName property get the client uploaded file name. HasFile property indicate whether AsyncFileUpload control contains a file.
FileContent property gets a stream object of client uploaded file. PostedFile property get a HttpPostedFile object that allow access
to the uploaded file.




AsyncFileUpload control's each OnClientUploadStarted, OnClientUploadError and OnClientUploadComplete property set a
javascript function name that can be executed in the client side. OnClientUploadStarted specified javascript function
executed when file uploading started. OnClientUploadError specified function executed when file upload failed. when file upload
complete then the OnClientUploadComplete property specified javascript function executed on client side.




AsyncFileUpload control's UploaderStyle property have two possible values those are Traditional and Modern. this property
change the appearance (look and feel) of AsyncFileUpload control.





AsyncFileUpload control provides two events those are UploadedComplete and UploadedFileError.
AsyncFileUpload control's UploadedFileError event fired when uploaded file is corrupted.
UploadedComplete event fire when file successfully uploaded. both event fired on server side.




AsyncFileUpload asp.net ajax control also provide a method named SaveAs. this method require a string argument which ask
a filename. SaveAs method allow us to save the contents of an uploaded file.





UsingAsyncFileUpload.aspx



<%@ Page Language="C#" AutoEventWireup="true" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<!DOCTYPE html>

<script runat="server">
protected void UploadComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
string filePath = Request.PhysicalApplicationPath+ "Image\\" + AsyncFileUpload1.PostedFile.FileName;
AsyncFileUpload1.SaveAs(filePath);
}
</script>
<script type="text/javascript">
function showConfirmation() {
document.getElementById('Label1').innerText = 'upload complete.';
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>How to use AsyncFileUpload in asp.net ajax</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:OrangeRed; font-style:italic;">Ajax AsyncFileUpload Example: How To Use AsyncFileUpload</h2>
<hr width="650" align="left" color="salmon" />
<asp:ScriptManager
ID="ScriptManager1"
runat="server"
>
</asp:ScriptManager>
<cc1:AsyncFileUpload
ID="AsyncFileUpload1"
runat="server"
OnUploadedComplete="UploadComplete"
OnClientUploadComplete="showConfirmation"
BackColor="Pink"
/>
<br />
<asp:Label
ID="Label1"
runat="server"
Font-Size="Large"
>
</asp:Label>
</div>
</form>
</body>
</html>












Popular posts from this blog

Restricting Jetpack Compose TextField to Numeric Input Only

Jetpack Compose has revolutionized Android development with its declarative approach, enabling developers to build modern, responsive UIs more efficiently. Among the many components provided by Compose, TextField is a critical building block for user input. However, ensuring that a TextField accepts only numeric input can pose challenges, especially when considering edge cases like empty fields, invalid characters, or localization nuances. In this blog post, we'll explore how to restrict a Jetpack Compose TextField to numeric input only, discussing both basic and advanced implementations. Why Restricting Input Matters Restricting user input to numeric values is a common requirement in apps dealing with forms, payment entries, age verifications, or any data where only numbers are valid. Properly validating input at the UI level enhances user experience, reduces backend validation overhead, and minimizes errors during data processing. Compose provides the flexibility to implement ...

jetpack compose - TextField remove underline

Compose TextField Remove Underline The TextField is the text input widget of android jetpack compose library. TextField is an equivalent widget of the android view system’s EditText widget. TextField is used to enter and modify text. The following jetpack compose tutorial will demonstrate to us how we can remove (actually hide) the underline from a TextField widget in an android application. We have to apply a simple trick to remove (hide) the underline from the TextField. The TextField constructor’s ‘colors’ argument allows us to set or change colors for TextField’s various components such as text color, cursor color, label color, error color, background color, focused and unfocused indicator color, etc. Jetpack developers can pass a TextFieldDefaults.textFieldColors() function with arguments value for the TextField ‘colors’ argument. There are many arguments for this ‘TextFieldDefaults.textFieldColors()’function such as textColor, disabledTextColor, backgroundColor, cursorC...

jetpack compose - Image clickable

Compose Image Clickable The Image widget allows android developers to display an image object to the app user interface using the jetpack compose library. Android app developers can show image objects to the Image widget from various sources such as painter resources, vector resources, bitmap, etc. Image is a very essential component of the jetpack compose library. Android app developers can change many properties of an Image widget by its modifiers such as size, shape, etc. We also can specify the Image object scaling algorithm, content description, etc. But how can we set a click event to an Image widget in a jetpack compose application? There is no built-in property/parameter/argument to set up an onClick event directly to the Image widget. This android application development tutorial will demonstrate to us how we can add a click event to the Image widget and make it clickable. Click event of a widget allow app users to execute a task such as showing a toast message by cli...