Click here to Skip to main content
Rate this: bad
good
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style>
.modalBackground
{
background-color: Gray;
filter: alpha(opacity=50);
opacity: 0.50;
}
.pnl{
background: #333;
padding: 10px;
border: 2px solid #ddd;
float: left;
font-size: 1.2em;
color:White;
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;
}
</style>
<script type = "text/javascript">
function Success() {
document.getElementById("lblMessage").innerHTML = "File Uploaded";

}

function Error() {
document.getElementById("lblMessage").innerHTML = "Upload failed.";
}
</script>
</head>
<body>
<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"
ID="modelPopupExtender1"
TargetControlID="btnUpload"
PopupControlID="popUpPanel"
OkControlID="btOK"
BackgroundCssClass="modalBackground">
 

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


<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server"
OnUploadComplete="UploadComplete"
OnClientUploadComplete="Success"
OnClientUploadError="Error"
ThrobberID="loader" Width="400px"/>
<asp:Image ID="loader" runat="server"
ImageUrl ="~/loading.gif"
Style="display:None"/>



<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;"/>
 

 





</form>
</body>
</html>
------------------------
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)
{
try
{
//string path = Server.MapPath("~/Uploads/") + e.FileName;
//System.Threading.Thread.Sleep(2000);
string path =Server.MapPath("~/Uploads/") + e.FileName;
AjaxFileUpload1.SaveAs(path);
}
catch (Exception)
{ }
}
Posted 4-Jan-13 0:42am
Edited 4-Jan-13 2:12am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This is your code:
<asp:ajaxfileupload id="AjaxFileUpload1" runat="server" xmlns:asp="#unknown">
OnUploadComplete="UploadComplete" 
OnClientUploadComplete="Success" 
ThrobberID="loader" Width="400px"/>
<asp:image id="loader" runat="server">
ImageUrl ="~/loading.gif" 
Style="display:None"/></asp:image></asp:ajaxfileupload>
 
Where is OnClientUploadError="Error"?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi.
 
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();
            err.name = 'Error Uploading';
            err.message = 'Excedió el límite.';
            throw (err);
 
        }
        else {
 
          //Etc...

 
        }
    }
</script>
 
 

Some HTML:
 
 
<body>
    <form id="form1" runat="server">
    <div>
        <asp:toolkitscriptmanager id="ToolkitScriptManager1" runat="server" xmlns:asp="#unknown">
        </asp:toolkitscriptmanager>
        
        <asp:ajaxfileupload id="AjaxFileUpload1" runat="server" xmlns:asp="#unknown">
        OnClientUploadComplete="uploadComplete" 
        OnClientUploadError="uploadError" 
        onuploadcomplete="AjaxFileUpload1_UploadComplete" />
 
        <div id="testuploaded" style="display: none; padding: 4px; border: gray 1px solid;">
            <h4>
                list of uploaded files:</h4>
            <hr />
            <div id="fileList">
            </div>
        </div>
 
    <p>
        <span style="background-color:Aqua" id="ResultId"></span>
    </p>
 
        <asp:button id="btnSubmit" runat="server" text="Postback" />
 
    </asp:ajaxfileupload></div>
    </form>
</body>
 

 

CodeBehind:
 
 

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

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 309
1 Richard MacCutchan 295
2 OriginalGriff 270
3 Sharmanuj 146
4 Magic Wonder 129
0 Sergey Alexandrovich Kryukov 5,969
1 OriginalGriff 5,005
2 CPallini 2,473
3 Richard MacCutchan 1,547
4 Abhinav S 1,507


Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 16 Dec 2013
Copyright © CodeProject, 1999-2014
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