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

9/3/2010 9:50:25 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

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

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