Friday, September 24, 2010

How to make FileUpload control in ASP.Net to Read-Only?

We can make the ASP.Net FileUpload control readonly by setting the ContentEditable property to false.
<asp:FileUploadID="fuFile"ContentEditable="false"runat="server"/>

 The other way of achieving it by restricting users to type in any characters i.e. return false on key press, key up and on paste event to prevent users pasting any values directly.

Refer the below code snippet that helps in doing that,
        fuFile.Attributes.Add("onkeypress", "return false;");
        fuFile.Attributes.Add("onkeyup", "return false;");
        fuFile.Attributes.Add("onpaste", "return false;");

No comments:

Post a Comment