Hi all,
I just ran into this building a Textbox control for my MVC framework, where just before finalizing the whole document I call PreRender on everything that inherits from ServerTag (which in turn inherits from DOMElement).
The only way i have found to change a DOMElement derived object's tagName is to replace it with a new one with all the attributes synced to the old one.
This is how that looks in code:
protected function PreRenderTextarea( WebPage $sender )
{
$textarea = $sender->createElement( 'textarea' );
foreach( $this->attributes as $attribute )
{
if ( $attribute->name == 'value' )
{
$textarea->nodeValue = $attribute->value;
}
else
{
$textarea->setAttribute( $attribute->name, $attribute->value );
}
}
$this->parentNode->replaceChild( $textarea, $this );
}
public function OnPreRender( WebPage $sender )
{
parent::OnPreRender();
$this->setAttribute( 'value', $this->Value );
switch( $this->Mode )
{
case 'normal' :
$this->setAttribute( 'type', 'text' );
break;
case 'password' :
$this->setAttribute( 'type', 'password' );
break;
case 'multiline' :
$this->PreRenderTextarea( $sender );
return;
break;
}
}
Is that really the only way to do it? This way has the rather unwanted side effect of nulling all the logic behind the control.