PC Review


Reply
Thread Tools Rating: Thread Rating: 2 votes, 1.00 average.

How to disable the upload file input field after success upload

 
 
cschang
Guest
Posts: n/a
 
      14th Jan 2005
I used the example from MS of file upload doc to create an upload vb.net
page. The page includes three file upload inputs. I tried to disable
(make the input field disappear) after the file(s) was successfully
uploaded. If there were two files, then the 2 of three input should
disappear. If there is one, then one input should be disabled. I tried
to run a JavaScript function to do that, but failed. Nothing happen. I
also tried to write out a JavaScript function that did not work either.
Can any one help me? I only learn vb.net about a month. I tried to
use my ASP and JavaScript knowledge; apparently there are lots different.

here are part of the codes. In .aspx javascript section I have such
function disableInput(n)
{
vav j = 0 ;
for( var i =0; i< document.form1.elements.length; i++){
if( document.form1.elements[i].type =='file') {
document.form1.elements[i].style.visibility = 'hidden';
if ( (j + 1) == n )
return true;
}
}
}

In my .aspx.vb file
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If (Not IsPostBack) Then
...
Else
..
Button1.Attributes.Add("OnClick", "alert('The selected
file(s) has been loaded.\nThe Order will be refreshed to reveal the
file(s).');refreshOrder('" & [cart_id]() & "');self.close();")
End If
....
End Sub
Sub SubmitButton_Click(ByVal Source As Object, ByVal e As EventArgs)
Dim filepath As String =
ConfigurationSettings.AppSettings("FileStorage")
Dim MAXSIZE As Integer =
ConfigurationSettings.AppSettings("MAXSIZE")
Dim uploadedFiles As HttpFileCollection = Request.Files
Dim strFilenamesCollection As String = ""
Dim i As Integer = 0

Dim arrPostedFile As New ArrayList
Dim fullFileName As String
Span1.InnerHtml = Nothing

If totalUpload(uploadedFiles) Then
Do Until i = uploadedFiles.Count
Dim userPostedFile As HttpPostedFile = uploadedFiles(i)

Try
If (userPostedFile.ContentLength > 0) Then
....
userPostedFile.SaveAs(filepath & "\" & cart_id
& "~" & _
Path.GetFileName(userPostedFile.FileName))

.....
fullFileName = cart_id & "~" &
Path.GetFileName(userPostedFile.FileName)
arrPostedFile.Add(fullFileName)

End If

Catch ex As Exception
Span1.InnerHtml += "Error:<br>" & ex.Message
End Try
i += 1
Loop
Span1.InnerHtml += "Above file(s) has been saved.<br>"
....
Else
Span1.InnerHtml = "<font color=red><b>Total file uploaded
has exceeded " & MAXSIZE / 1000000 & " MB.</b></font>"
End If

End Sub
Private Sub disablePostedFileInout(ByVal n As Integer)
Dim jScript As String

jScript = "<script language='javascript'>"
' jScript = jScript & "function disableInput(" & n & " ) { "
jScript = jScript & " var j = 0; "
jScript = jScript & " for( var i =0; i<
document.form1.elements.length; i++){"
jScript = jScript & " if( document.form1.elements[i].type
=='file') { "
jScript = jScript & "
document.form1.elements[i].style.visibility = 'hidden'; "
jScript = jScript & " if ( (j + 1) == " & n & " ) return; "
jScript = jScript & " } ) "
jScript = jScript & "</script>"
RegisterStartupScript("DisableInput", jScript.ToString)

My question is how to call a javascript without using any control, such
as button.

C Chang
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to delegate IIS's FTP File Upload and Upload Failure Events from C#? ABC Microsoft C# .NET 0 24th Jan 2007 09:17 AM
upload large files using Frontpage upload form field =?Utf-8?B?SG9sbHl5bGxvSA==?= Microsoft Windows 2000 Registry 6 27th Oct 2005 12:28 AM
<INPUT = 'File'> upload problem Brian Henry Microsoft ASP .NET 10 22nd Jul 2004 07:36 AM
File Upload FP2002 - upload works but email and confirm don't rmc Microsoft Frontpage 1 24th Mar 2004 03:58 PM
File Upload (Email) and catching the Upload size of 4mb BTHOMASinOHIO Microsoft Dot NET 1 25th Nov 2003 03:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:15 PM.