There is bug in the WebControlAdapter class that can be very annoying, so I thought I'd fill eveybody in on the details.
The WebControlAdapter by default calls base.Render in it's render method. On most occasions, this is no problem. However, for TextBox it is. Try adding a multiline textbox and adding a TextBox control adapter using the WebControlAdapter base class: the multine
textbox refuses to maintain it's state. All was working well for regular textboxes, so had a look at the .net internals to figure out what's going on. It turns out that the textbox rendering method has a conditional statement for rendering multiline textbox
controls which get's ignored when using the WebControlAdapter. So when writing an adapter for the textbox control, you always have to implement to render method, like so:
if (Extender.AdapterEnabled)
{
//base.Render(writer); // this causes a bug where multiline textboxes can't maintain state
base.RenderBeginTag(writer);
if (textbox.TextMode == TextBoxMode.MultiLine)
{
System.Web.HttpUtility.HtmlEncode(textbox.Text, writer);
}
else
{
base.RenderContents(writer);
}
base.RenderEndTag(writer);
}
Participant
1683 Points
479 Posts
Bug in Asp.Net 2.0 WebControlAdapter
Dec 27, 2007 11:14 AM|Rinze|LINK
There is bug in the WebControlAdapter class that can be very annoying, so I thought I'd fill eveybody in on the details.
The WebControlAdapter by default calls base.Render in it's render method. On most occasions, this is no problem. However, for TextBox it is. Try adding a multiline textbox and adding a TextBox control adapter using the WebControlAdapter base class: the multine textbox refuses to maintain it's state. All was working well for regular textboxes, so had a look at the .net internals to figure out what's going on. It turns out that the textbox rendering method has a conditional statement for rendering multiline textbox controls which get's ignored when using the WebControlAdapter. So when writing an adapter for the textbox control, you always have to implement to render method, like so:
if (Extender.AdapterEnabled)
{
//base.Render(writer); // this causes a bug where multiline textboxes can't maintain state
base.RenderBeginTag(writer);
if (textbox.TextMode == TextBoxMode.MultiLine)
{
System.Web.HttpUtility.HtmlEncode(textbox.Text, writer);
}
else
{
base.RenderContents(writer);
}
base.RenderEndTag(writer);
}
bug CSSFriendly adapters TextArea TextBox WebControlAdapter
Rinze Cats
---------
None
0 Points
2 Posts
Re: Bug in Asp.Net 2.0 WebControlAdapter
Oct 23, 2008 01:03 PM|schubboy|LINK
None
0 Points
1 Post
Re: Bug in Asp.Net 2.0 WebControlAdapter
Jan 07, 2011 03:13 PM|ThatMatthew|LINK
Thanks, Rinze! What a weird issue.