Results 1 to 5 of 5

Thread: file uploading

  1. #1
    Join Date
    Aug 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wink file uploading

    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.. - so users know the pager hasn't crashed


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


    See code below:



    PHP Code:
    <%@ Page Language="VB"%>
    <
    script runat="server">
        Protected 
    Sub Button1_Click(ByVal sender As ObjectByVal 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!

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    You could just at the beginning of the script write "echo" or ASP.net equivalent of it.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    You can achieve your goal using a progress bar i think.

    Check the following items.

    From DD 1

    From DD 2

    From DD 3

    From webconcerns

    From java2s

  4. #4
    Join Date
    Nov 2006
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Asp.net

    Duke,

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

    Code:
    <%@ 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>
    Last edited by mastergeek70; 11-22-2006 at 02:38 PM.

  5. #5
    Join Date
    Aug 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thanks!!

    Thank you all for your comments..Very easy to understand and helpful..

    Javascript really is the way to go..




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •