How to disable the upload file input field after success upload

C

cschang

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.type =='file') {
document.form1.elements.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.type
=='file') { "
jScript = jScript & "
document.form1.elements.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top