Personal Blog of Mustafa Basgun

Utilize Read-Only TextBoxes in FileUpload Control of ASP.NET

with 9 comments

Nowadays, I am spending most of my work time on developing a “document depot” type of web application which has a heavy usage of FileUpload control. And, it was one of the requirements that users should not be able to modify the associated textbox after browsing the document from their hard drives. I believe it is a very good user-experience practice and it avoids some possible security issues as well. After walking around between some search results, I have found the following solution by assuming that FileUpload1 is the ID of the control:



As a result, users would be able to select a document only by using the Browse button.

I have tested the sample code with the latest versions of IE and Firefox, and everything seemed to be working fine with both browsers.


Written by Mustafa Basgun

January 28, 2008 at 5:00 PM

9 Responses

Subscribe to comments with RSS.

  1. Mustafa – Do you know a way of changing the text on the FileUpload button? Thanks.

    Mark W.

    January 28, 2008 at 8:54 PM

  2. Mark,

    As far as I know, there is no workaround to update the default caption of FileUpload button. It is a read-only property which I guess due to a matter of security. You can try your chance by asking it at the forum ( though.

    Mustafa Basgun

    January 28, 2008 at 11:48 PM

  3. Bassel Issa

    February 2, 2008 at 9:41 PM

  4. What about the problem of copy and paste text with the mouse?


    July 16, 2008 at 7:05 AM

  5. Good article.

    Abhiram Reddy Mekha

    September 16, 2008 at 10:25 AM

  6. How can we change the text inside the FileUpload control as normally we do?

    Ex: textbox1.text = “file.lio”


    November 15, 2008 at 4:57 AM

  7. I want to ask the same question as Supertorpe.

    What about mouse copy and paste?


    November 28, 2008 at 12:59 PM

  8. It seems like it would be better/easier to just add the following attribute:

    <asp:FileUpload id=”FileUpload1″ runat=”server” ContentEditable=”false” />

    It does what you want, works in IE and Firefox, and prevents the copy and paste issue others mentioned.


    December 5, 2008 at 9:12 AM

  9. Excellent article!

    Senthil Kumar

    February 13, 2009 at 4:20 AM

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: