Archive for October, 2011

_foregroundElement.ParentNode is null exception

OK, here’s the situation, my parents went away on a week’s vacation…

No, wait, that was from “Parents Just Don’t Understand”.

Back to the 21st century, I was messing around with a Panel property connected to a ModalPopupExtender controls from the Ajax toolkit. I was trying to hide the panel in code behind, but I was running across this exception at run time:

      _foregroundElement.ParentNode is null or not an object

It turns out that the problem was that I was hiding the Panel using the Visibility property:

     myPanel.Visibility = false;

When I changed the way it was displayed, using a style instead, it worked:

     myPanel.Attributes["display"] ="none";
Advertisements

5 Comments

Dude, where is my MaxLength for multiline TextBoxes?

Have you tried to add a MaxLength property to a multiline TextBox control? I was doing this recently, adding that property in the code behind, and when I viewed the page, the property was gone. Poof, no error, no MaxLength property, nothing. As I found out, that wonderful property is not valid on TextBox controls with a TextMode of “MultiLine”. What to do, what to do…

There are a couple of ways to handle this. I decided to just chop off the last few characters in the TextBoxI know, it’s probably offensive to users with delicate egos, so call me cruel. I first created a JavaScript function in the ASPX page that truncated the value in the TextBox:

    function truncMaxLength(txtControl,maxLength){  
        try{  
            if(txtControl.value.length > maxLength)
                txtControl.value = txtControl.value.substring(0, maxLength);
           }catch(e){ 
           }  
    }

And to call this from code behind, I simply added it to the Attributes collection of the TextBox, using the “onblur” event to call it whenever the TextBox loses focus:

    rdMultilineTxtBox.Attributes.Add("onblur", "truncMaxLength(this,100);");

 

Leave a comment