Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to disable an HtmlIntputFile Control

Status
Not open for further replies.

cesark

Programmer
Joined
Dec 20, 2003
Messages
621
How can I disable an HtmlInputFile Control so that is not posted back when user submit the form?

I tried this:
Code:
Sub on_Button2_Click(Sender As Object, E As EventArgs)

image_path_QA.Disabled = True
...

End Sub


...

            <td><input type="file" id="image_path_QA" runat="server" size="15" /></td>

...

But it doesn’ t work, the file is posted back and the server ‘waits’ until the file added is totally uploaded. How can I ignore the control in the ‘on_Button2_Click’ subroutine?

Thanks
 
Didn't we just discuss this in thread855-1003484 where you said the solution I provided worked?!

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Ca8msm, it works. But if user add a file of e.g. 350 KB size, and presses the button to go back, he/she has to wait until the server has uploaded the entire file to decide not to save it. If I could disable the control, the server wouldn’ t have all that work only to decide ignore it.
 
I thought the idea of the "other" button was to not upload the file i.e. if the user clicks any other button apart from the sumbit button then the upload sub isn't fired.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
No, the problem is with the HtmlInputFile control itself. When you add a file in that control, regardless what you do with that control, when you submit the form the content of the control is sent back to the server. And the server load the entire file before decide what to do with it. This control works in this way, my question is if it is possible to disable it so that nothing of it is posted back

I though that disabling a control, as I am doing, I could avoid it is posted back. Isn’ t it?
 
OK - if you want to disable it you will have to tell your asp the name of the control, what it is and add a WithEvents handle. e.g.
Code:
Public WithEvents FileUpload1 As System.Web.UI.HtmlControls.HtmlInputFile
Then from your button, you will be able to access the control and set it's disabled status to True. e.g.
Code:
FileUpload1.Disabled = True

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
I tried:
Code:
<%@ Page Language="VB" Debug="True" %>


<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.SqlClient" %>


<script language="VB" runat="server">

Public WithEvents image_path_QA As System.Web.UI.HtmlControls.HtmlInputFile

...



Sub on_Button2_Click(Sender As Object, E As EventArgs)

image_path_QA.Disabled = True
...

End Sub

</script>

And when the page is load I receive the error:

Compilation Error
BC30260: 'image_path_QA' is already declared as 'Protected Dim image_path_QA As System.Web.UI.HtmlControls.HtmlInputFile' in this class.

Line 10: Public WithEvents image_path_QA As System.Web.UI.HtmlControls.HtmlInputFile
 
Visual Studion (I'm assuiming you are using this?) will have created the line
Code:
Protected Dim image_path_QA As System.Web.UI.HtmlControls.HtmlInputFile
automatically for you. Find it it the region marked "Web Form Designer Generated Code" and set it to public.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
I don' t use Visual Studio, I program all my pages in line, it' s more clear.
It must have other ways to do the same, since VS is only a tool that writes for you.
 
Visual Studio (I'm assuming you are using this?) will have created the line
Code:
Protected Dim image_path_QA As System.Web.UI.HtmlControls.HtmlInputFile
automatically for you. Find it it the region marked "Web Form Designer Generated Code" and set it to public.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
I think here this control can’ t be disabled with server side code, since once the control is available on the page, there is no way to tell the server ‘ingore that form element’ or ‘not receive it’, because the server will expect the form as it sent, at least the form will be posted back with all the form elements received (which I want to avoid, since I don’ t want to sent the image_path_QA element content when user presses the submit button_2). Only with client side code you can disable that control so that is not posted back. Isn’ t it?
 
You can disable a HTML control using the method I showed you above (i.e. adding a Public WithEvents declaration).

Whether the file is posted when the control is disabled or not you will have to look into.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
I generated (compiled) a class like this:
Code:
' VB Document

Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Public Class upload
Inherits System.Web.UI.Page

Public WithEvents image_path_QA As System.Web.UI.HtmlControls.HtmlInputFile

End Class

And was well generated. Then in the aspx page I put:
Code:
Sub on_Button2_Click(Sender As Object, E As EventArgs)

Dim var_path As upload
var_path.image_path_QA.Disabled = True
...

End Sub

But an error message says:

System.NullReferenceException: Object reference not set to an instance of an object.
Line 5826: var_path.image_path_QA.Disabled = True
 
Could you let me see the msdn page or the article where this technique is explained please?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top