I was just playing about with the treeview control adapter, having used the default template project provided from the site. I just stuck a treeview on the default.aspx page, which doesn't have a server form (which I realised was the problem), and then bound
it to a sitemap. The control seemed to render, but I got javascript errors when I tried clicking on any of the buttons to expand and collapse the nodes. I couldn't figure out what I'd done wrong, but then I removed the mapping to the adapter in the browsers
file and got the following error:
Control 'TreeView1' of type 'TreeView' must be placed inside a form tag with runat=server.
The problem was obvious from this message, but the adapted rendering had failed to throw this error. Fortunately I've got a copy of .NET Reflector, so I could see inside the RenderContents method
of the System.Web.UI.WebControls.TreeView class, and I noticed the following call:
So I thought I'd try my luck at putting that code into the RenderContents method of the adapter, as follows:
protected override
void RenderContents(HtmlTextWriter writer)
{
TreeView treeView = Control
as TreeView;
if (this.Page !=
null)
{
this.Page.VerifyRenderingInServerForm(treeView);
}
.....
And guess what, it works! I had a similar problem with another control, and I was scratching my head trying to figure out what was wrong, when I found that there are subtle differences like this which could cause a lot of development time
to be lost. After all, the only difference between the tailor-made and adapted rendering should be the mark-up itself...
Could anybody have a look at putting this code into the next release?
cheers
bugCSS Control AdaptersTreeview ExpandToState OnLoadbugs and stuffCSS Control Adapters Treeviewadapter
I'm currently working on a project which will probably require other controls. I haven't used the others to be able to encounter the issue, but the easiest way to test each one is to instantiate and populate a web control outside a server form, and then
try commenting out the adapter mapping in the browsers file. If you get the error with the default asp.net rendering, but not the css adapter rendering, then the css adapter rendering is wrong. You'll need to add the following, or equivalent code, to the RenderContents
method:
if (this.Page !=
null)
{
this.Page.VerifyRenderingInServerForm(control);
}
I think there was another related but different issue I came across with the CSS adapters, where the ASP.NET form validation was failing, because there it was missing a call to a routine in the framework - I'll post that too when I get a moment.
willb75
Member
2 Points
3 Posts
Control must be in server form
Feb 06, 2008 09:39 AM|LINK
I was just playing about with the treeview control adapter, having used the default template project provided from the site. I just stuck a treeview on the default.aspx page, which doesn't have a server form (which I realised was the problem), and then bound it to a sitemap. The control seemed to render, but I got javascript errors when I tried clicking on any of the buttons to expand and collapse the nodes. I couldn't figure out what I'd done wrong, but then I removed the mapping to the adapter in the browsers file and got the following error:
Control 'TreeView1' of type 'TreeView' must be placed inside a form tag with runat=server.
The problem was obvious from this message, but the adapted rendering had failed to throw this error. Fortunately I've got a copy of .NET Reflector, so I could see inside the RenderContents method of the System.Web.UI.WebControls.TreeView class, and I noticed the following call:protected internal override void RenderContents(HtmlTextWriter writer)
{
base.RenderContents(writer);
if (this.Page != null)
{
this.Page.VerifyRenderingInServerForm(this);
}
...
So I thought I'd try my luck at putting that code into the RenderContents method of the adapter, as follows:
protected override void RenderContents(HtmlTextWriter writer)
{
TreeView treeView = Control as TreeView;
if (this.Page != null)
{
this.Page.VerifyRenderingInServerForm(treeView);
}
.....
And guess what, it works! I had a similar problem with another control, and I was scratching my head trying to figure out what was wrong, when I found that there are subtle differences like this which could cause a lot of development time to be lost. After all, the only difference between the tailor-made and adapted rendering should be the mark-up itself...
Could anybody have a look at putting this code into the next release?
cheers
bug CSS Control Adapters Treeview ExpandToState OnLoad bugs and stuff CSS Control Adapters Treeview adapter
vik20000in
All-Star
25882 Points
3993 Posts
MVP
Re: Control must be in server form
Feb 06, 2008 11:18 AM|LINK
that looks like a pretty good finding. I will look at this myself later. :-)
www.vikramlakhotia.com
Please mark the answer if it helped you
bdemarzo
Member
435 Points
168 Posts
Re: Control must be in server form
Feb 06, 2008 05:57 PM|LINK
Can you confirm whether other CSS adapted controls have the same potential issue?
- blog: www.sidesofmarch.com
willb75
Member
2 Points
3 Posts
Re: Control must be in server form
Feb 07, 2008 12:18 PM|LINK
I'm currently working on a project which will probably require other controls. I haven't used the others to be able to encounter the issue, but the easiest way to test each one is to instantiate and populate a web control outside a server form, and then try commenting out the adapter mapping in the browsers file. If you get the error with the default asp.net rendering, but not the css adapter rendering, then the css adapter rendering is wrong. You'll need to add the following, or equivalent code, to the RenderContents method:
if (this.Page != null)
{
this.Page.VerifyRenderingInServerForm(control);
}
I think there was another related but different issue I came across with the CSS adapters, where the ASP.NET form validation was failing, because there it was missing a call to a routine in the framework - I'll post that too when I get a moment.