Invalid string in FileUpload control prevents form postback

by neo_savvy 6/10/2009 8:37:00 AM

Discovered this problem in IE7 (probably exists in IE6 too) where the FileUpload control textbox allows invalid user input that prevents the form from posting back to the server. This is not a problem in IE8 and FF where the FileUpload control textbox renders properly in readonly mode. You can work around this problem by adding javascript  to the 'onkeypress' and 'onkeydown' event handler to prevent users from typing any potentially invalid string. The javascript function (which uses cross-browser javascript keycode detection) below will block all typing except tabs - this should allow users to still tab over controls.

function blockAllExceptTab(e) {
   
    if (!e) var e = window.event
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
   
    var result = (code == 9);
    return result;
}

Add this code to your page OnInit event handler:

this.myFileUpload.Attributes.Add("onkeypress", "return blockAllExceptTab(event);");
this.myFileUpload.Attributes.Add("onkeydown", "return blockAllExceptTab(event);");

Hope this helps.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Related posts

Comments

Add comment


 

  Country flag





Live preview

3/9/2010 11:01:43 PM

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

About the author

Chyke Ucheya Chyke Ucheya
I'm a Software Engineer at a leading Technology Consulting firm in Atlanta, GA.

E-mail me Send mail

Calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Sign in