Posts Tagged ‘file upload with read only’


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.