PDA

View Full Version : file uploading



duke_1222
11-19-2006, 04:27 PM
Hi there,

I have a simple uplaod script using ASP.NET

It works very well - but what I would like to do is disable the page whilst it is uploading BIG files.

Ideally, hide the uplaod button and state

"BUSY UPLOADING your file.. please be patient"
with a GIF showing.. :mad: - so users know the pager hasn't crashed


Do I need to use Javascript to do this dynamically or ASP.nET?


See code below:




<%@ Page Language="VB"%>
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

If FileUpload1.HasFile Then
Try
FileUpload1.SaveAs(Server.MapPath("../uploaded_folder/" & FileUpload1.FileName))
Label1.Text = "File name: " & _
FileUpload1.PostedFile.FileName & "<br>" & _
"File Size: " & _
FileUpload1.PostedFile.ContentLength

Catch ex As Exception
Label1.Text = "ERROR: " & ex.Message.ToString()
End Try
Else
Label1.Text = "You have not specified a file."
End If
End Sub

</script>


<form>

<asp:Button ID="Button1" runat="server" Text="Upload file Now" OnClick="Button1_Click" />

<asp:Label ID="Label1" runat="server" ForeColor="Red"></asp:Label>



</form>


Any comments will be greatly appreciated!

tech_support
11-21-2006, 05:42 AM
You could just at the beginning of the script write "echo" or ASP.net equivalent of it.

codeexploiter
11-21-2006, 10:53 AM
You can achieve your goal using a progress bar i think.

Check the following items.

From DD 1 (http://www.dynamicdrive.com/dynamicindex11/xpprogressbar.htm)

From DD 2 (http://www.dynamicdrive.com/dynamicindex11/dhtmlprogress.htm)

From DD 3 (http://www.dynamicdrive.com/dynamicindex11/dhtmlprogress2.htm)

From webconcerns (http://www.webconcerns.co.uk/javascript/progressbar/progressbar.asp)

From java2s (http://www.java2s.com/Code/JavaScript/Development/ProgressBar1.htm)

mastergeek70
11-22-2006, 02:30 PM
Duke,

This is very easy. I modified your script, try this:



<%@ Page Language="VB" %>
<script runat="server">

' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Sub Page_Load

If Not IsPostBack Then
End If

' <main startup code>

End Sub

' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

If FileUpload1.HasFile Then
Try
FileUpload1.SaveAs(Server.MapPath("uploaded_folder/" & FileUpload1.FileName))
Label1.Text = "File name: " & _
FileUpload1.PostedFile.FileName & "<br>" & _
"File Size: " & _
FileUpload1.PostedFile.ContentLength

Catch ex As Exception
Label1.Text = "ERROR: " & ex.Message.ToString()
End Try
Else
Label1.Text = "You have not specified a file."
End If
End Sub

' =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

</script>
<html>
<head><title>ASP.NET Upload</title>

<script language="javascript">
<!-- hide HTML

function show_busy(){
document.all.pleasewaitScreen.style.pixelTop = (document.body.scrollTop + 200);
document.all.pleasewaitScreen.style.visibility="visible";
}

function hide_busy(){
document.all.pleasewaitScreen.style.visibility="hidden";
}
// unhide -->
</script>

</head>
<BODY onbeforeunload="show_busy();">

<DIV ID="pleasewaitScreen" class="test" STYLE="position:absolute;z-index:10;top:30%;visibility:hidden">
<TABLE BGCOLOR="#000000" BORDER="2" BORDERCOLOR="#000000" CELLPADDING="0" CELLSPACING="0" HEIGHT="100" WIDTH="303" ID="BusyTable"><TR>
<TD WIDTH="100%" HEIGHT="100%" BGCOLOR="whitesmoke" ALIGN="CENTER" VALIGN="MIDDLE">
<FONT FACE="Arial" SIZE="4" COLOR="blue"><B>Please Wait...<br>Application Is Busy.</B></FONT>
</TABLE>

<script language="javascript">
<!-- hide HTML
h=document.getElementById("pleasewaitScreen");
h.style.left=(window.screen.availWidth/2)-151;
// unhide -->
</script>

</DIV>

<form runat="Server">

<asp:Button ID="Button1" runat="server" Text="Upload file Now" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server" ForeColor="Red" Width="350px"></asp:Label><br />
<asp:fileupload id="FileUpload1" runat="server"></asp:fileupload>

</form>
</body>
</html>

duke_1222
11-24-2006, 12:11 AM
Thank you all for your comments..Very easy to understand and helpful..

Javascript really is the way to go..

:D

:o