file upload control with read only property

Posted: January 24, 2008 in ASP.NET, Javascript
Tags: , ,

 

There may be circumstances when you would like to use file upload control to upload different file using your web application, at the same time you need to set this control as read only so that no one can change the text inside the textbox in a file upload control. You can achieve this by following code.

<input type=”file” id=”file1″ onkeypress=”javascript:return false;” onkeydown=”javascript:return false;” name=”file1″ />

If your file upload control is server control then you can also set its attribute runtime as describe below:

file1.Attributes.Add(“onkeydown”, “javascript:return false;”);

file1.Attributes.Add(“onkeypress”, “javascript:return false;”);

You can set this attribute in a Page_Load event of web page. Just by using simple javascript you can achieve file upload control with read only property.

Whether you found this article useful or not? please provide your valuable comments.

Advertisements
Comments
  1. Supreet says:

    This is exactly what i was looking for. Thanks for the help.

  2. Moetmea says:

    This article is 100% helpful for me.

    Thanks . 🙂

  3. brinda says:

    Hi..
    This is perfactly working in the IE. but in the mozila it is giving side effect. after selecing the file from browse control if i press any key then value from the browse control disappear.
    Any solution for that?

    Thanks
    Brinda parikh

  4. jay says:

    Yeah, Ireally appreciate your help. It really helped me.
    God bless you.
    Take care.

  5. mmx says:

    Hello what about calculate size of file before upload ?

  6. harry says:

    thodu motu ane saru coding lakho ae javascript nahi pan notepad ni text file lage chhe

  7. Juan Carlos says:

    Thank you, it’s just what I was looking for. It works fine.

  8. Rajesh says:

    Thank you, it’s just what I was looking for. It works fine

  9. Ashok N says:

    Thank you, it’s just very nice and very usefull to me. It’s easily solved my problem.

  10. Ashok N says:

    I need one favor. i.e., I am able to do CUT and PASTE with mouse.

  11. jesh says:

    thanks for the info.. Also works with DevEx UploadControl v9.x. 🙂

  12. Akif Patel says:

    A Simple way with built in attribute:

    Thnx….

  13. Akif Patel says:

    A Simple way with built in attribute:
    contentEditable=”false”

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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