Tuesday, May 8, 2007

Fix: ASP.NET TextBox controls don't display properly in FireFox.

I have always had trouble displaying my ASP.NET TextBoxes properly. Through trial and error I found that the WIDTH and HEIGHT attributes in the controls do not translate over to FireFox. The following is how they are displaying:



This is how they should look and do look in IE:



The following is the code for the workaround:


private void TextboxFFHeightAndWidthFix()
{
 foreach(Control c in Page.Controls)
 {
  if(c is TextBox)
  {
   TextBox obj = (TextBox) c;
   obj.Style.Add("width",obj.Width.ToString());
   if(!obj.Height.IsEmpty)
   {
    obj.Style.Add("height",obj.Height.ToString());
   }
  }
 }
}

No comments: