Click here to Skip to main content
12,761,216 members (31,928 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET
My aspx code is---

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
background-color: Gray;
filter: alpha(opacity=50);
opacity: 0.50;
background: #333;
padding: 10px;
border: 2px solid #ddd;
float: left;
font-size: 1.2em;
position: fixed;
top: 50%; left: 50%;
z-index: 99999;
box-shadow: 0px 0px 20px #999; /* CSS3 */
-moz-box-shadow: 0px 0px 20px #999; /* Firefox */
-webkit-box-shadow: 0px 0px 20px #999; /* Safari, Chrome */
border-radius:3px 3px 3px 3px;
-moz-border-radius: 3px; /* Firefox */
-webkit-border-radius: 3px; /* Safari, Chrome */
.close {
DISPLAY: block;BACKGROUND: url(Images/close.png) no-repeat 0px 0px;
LEFT: -12px;WIDTH: 26px;TEXT-INDENT: -1000em;POSITION: absolute;
TOP: -12px;HEIGHT: 26px;
<script type = "text/javascript">
function Success() {
document.getElementById("lblMessage").innerHTML = "File Uploaded";


function Error() {
document.getElementById("lblMessage").innerHTML = "Upload failed.";
<form id="form1" runat="server">

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<asp:Button ID="btnUpload" runat="server"
Text="Upload File" onclick="btnUpload_Click"/>

<asp:ModalPopupExtender runat="server"

<asp:Panel ID="popUpPanel" runat="server" CssClass="pnl">

<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
ThrobberID="loader" Width="400px"/>
<asp:Image ID="loader" runat="server"
ImageUrl ="~/loading.gif"

<asp:Label ID="lblMessage" runat="server"/>

<asp:Button ID="btOK" runat="server" Text="OK" />
<asp:LinkButton ID="LinkButton1" runat="server" CssClass="close"
OnClientClick="$find('modelPopupExtender1').hide(); return false;"/>

my .cs file is..i have add OnClientUploadError="Error" but until its not showing error message when file is not uploaded...please help me.
protected void UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
//string path = Server.MapPath("~/Uploads/") + e.FileName;
string path =Server.MapPath("~/Uploads/") + e.FileName;
catch (Exception)
{ }
Posted 4-Jan-13 1:42am
Updated 4-Jan-13 3:12am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This is your code:
<asp:ajaxfileupload id="AjaxFileUpload1" runat="server" xmlns:asp="#unknown">
ThrobberID="loader" Width="400px"/>

Where is OnClientUploadError="Error"?
Rate this: bad
Please Sign up or sign in to vote.

Solution 3


With asp:AjaxFileUpload the OnClientUploadError not fired. I have similar bug.

Test this example:

The code validate the size of file onClient. When Size > 1000000 fire exception. The exception not fired OnClientUploadError="uploadError" and the file was upload to the server.

I need to validate the size of file onClient to prevent the fileupload on the server (including temporary file uploaded to the server)

<script type="text/javascript">

    function uploadError(sender, args) {
        //Good practice to put try,catch block. it will avoid javascript error at window status.
            var ArchivoNombre = args.get_fileName();
            var MensajeError = args.get_errorMessage();
            var Mensaje = "Archivo no cargado: " + ArchivoNombre + " / ERROR..." + MensajeError;

            //Desarrollar algún proceso en el servidor: grabar en base de datos, etc.
            //  En este caso, se crea una variable de sesión.
            //PageMethods.RegisterUploadError(MensajeError, Mensaje, OnSucceeded, OnFailed);

    function uploadComplete(sender, e) {

        var Peso = context.get_fileSize();
        var ArchivoNombre = context.get_fileName();

        /*Validation for file size*/
        if (parseInt(Peso) > 1000000) {

            var Mensaje = "Archivo excede el tamaño límite de 2 Mb. Archivo : " + ArchivoNombre + " Peso(bytes): " + Peso;
            var displayElement = document.getElementById("ResultId");
            displayElement.innerHTML = Mensaje;

            var err = new Error();
   = 'Error Uploading';
            err.message = 'Excedió el límite.';
            throw (err);

        else {



Some HTML:

    <form id="form1" runat="server">
        <asp:toolkitscriptmanager id="ToolkitScriptManager1" runat="server" xmlns:asp="#unknown">
        <asp:ajaxfileupload id="AjaxFileUpload1" runat="server" xmlns:asp="#unknown">
        onuploadcomplete="AjaxFileUpload1_UploadComplete" />


 protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs file)
        //Grabar en disco
        string rutaUploads = HttpContext.Current.Server.MapPath("Uploads\\");
        string FullNombre = rutaUploads + file.FileName;



This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 16 Dec 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100