TreeView and CSS Control Adapters

Hello All,

I am using CSS control Adapter for my TreeView. The Intention is to emit <ul> and <li> tags instead of tables.

But I am getting this error

************************************************************************************** **************************************************************************************

Server Error in 'xyz' Application.

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Source Error:

Line 116:                    Panel panel = new Panel();
Line 117: panel.Controls.Add(_viewState);
Line 118: Page.Form.Controls.Add(panel);
Line 119: string script = "document.getElementById('" + _viewState.ClientID + "').value = GetViewState__AspNetTreeView('" + Extender.MakeChildId("UL") + "');";
Line 120: Page.ClientScript.RegisterOnSubmitStatement(typeof(TreeViewAdapter), _viewState.ClientID, script);


Stack Trace:

[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
System.Web.UI.ControlCollection.Add(Control child) +2058223

System.Web.UI.Control.SaveViewStateRecursive() +2066087
System.Web.UI.Control.SaveViewStateRecursive() +160
System.Web.UI.Control.SaveViewStateRecursive() +160
System.Web.UI.Control.SaveViewStateRecursive() +160
System.Web.UI.Page.SaveAllState() +466
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1676


Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
 

************************************************************************************** ************************************************************************************** 

What is the issue ??

Thank you  

0
ShailAtlas
8/29/2007 4:10:08 PM
asp.net.navigation-controls 13714 articles. 0 followers. Follow

6 Replies
886 Views

Similar Articles

[PageSpeed] 45

Hi,

ShailAtlas:


Line 116:                    Panel panel = new Panel();
Line 117: panel.Controls.Add(_viewState);
Line 118: Page.Form.Controls.Add(panel);

What's the value of the _viewstate? Doed it includes <% = blah blah %> notation?

You can try to use this  <%# blah blah %>  in stead of <% = blah blah %>.

 

Hope it helps.


Amanda Wang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Amanda
8/31/2007 3:26:14 AM

 Hello Amanda,

Thanks for your reply.

The value of "_viewState" is not null.

 

But when I comment out these three lines

 

Line 116:                   /// Panel panel = new Panel();
Line 117: /// panel.Controls.Add(_viewState);
Line 118: /// Page.Form.Controls.Add(panel);
 
I do not get that previous error. But then value of "_viewState.ClientID" becomes null. 
Is it like this. If you do not add the viewState to a panel, its client ID will be null ???
Thank you 

0
ShailAtlas
8/31/2007 8:49:02 AM

Hi

What about the value of _viewState? I think the problem is related to the _viewState.

You can try to use a normal control, such as TextBox, label etc. It will not throw exception.

 For example:

Label lbl =  new Label();

lbl.Text = "Text Label"; 

Panel panel = new Panel();
panel.Controls.Add(lbl);

Page.Forms.Control.Add(panel);

If you can, would you please give more detail about the _viewstate's value, so we hope to reproduce your problem as possible as we can.


Amanda Wang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Amanda
9/3/2007 2:41:41 AM

I'm having the exact same issue.  I've created a blank project (using the CSS-friendly template), laid out my CSS, then after dropping in a tree-view I get the same error message.

The viewstate looks like this if I run the page without the treeview on it:

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEwMDUyNjYzMjhkGAEFDmN0bDAwJG1lbnVNYWluDw9kBQdXRUxDT01FZOypcqW8bZnxZh/1lGw5DdDlopt7" />

 

Obviously, when I do run the page with the treeview, the page does not provide me with enough info to get the viewstate, but the following is my error:

 

Server Error in '/cjca_cbs' Application.

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Source Error:

Line 115:                    Panel panel = new Panel();
Line 116: panel.Controls.Add(_viewState);
Line 117: Page.Form.Controls.Add(panel);
Line 118: string script = "document.getElementById('" + _viewState.ClientID + "').value = GetViewState__AspNetTreeView('" + Extender.MakeChildId("UL") + "');";
Line 119: Page.ClientScript.RegisterOnSubmitStatement(typeof(TreeViewAdapter), _viewState.ClientID, script);

Source File: c:\inetpub\wwwroot\cjca_cbs\App_Code\Adapters\TreeViewAdapter.cs    Line: 117

Stack Trace:

[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
System.Web.UI.ControlCollection.Add(Control child) +2105903
CSSFriendly.TreeViewAdapter.SaveAdapterViewState() in c:\inetpub\wwwroot\cjca_cbs\App_Code\Adapters\TreeViewAdapter.cs:117
System.Web.UI.Control.SaveViewStateRecursive() +2113767
System.Web.UI.Control.SaveViewStateRecursive() +160
System.Web.UI.Control.SaveViewStateRecursive() +160
System.Web.UI.Control.SaveViewStateRecursive() +160
System.Web.UI.Page.SaveAllState() +466
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1676


Version Information: Microsoft .NET Framework Version:2.0.50727.312; ASP.NET Version:2.0.50727.833
 

0
AstroPHX
11/9/2007 10:51:12 PM

Ah ha.  OK, I found the code that's making the control barf, but not the reason.

Imagine the (pseudo)code looks like this:

[header]

[menu]

[leftnav]

[body]

[footer]

where

  • menu is the <asp:Menu> object
  • leftnav is the <asp:TreeView> object
  • body is the <asp:ContentPlaceHolder> object
  • and the footer contains the following code:
    &copy; <%= DateTime.Now.Year.ToString() %> MyCompany

The <%=...%> is making the TreeView only explode.  I can yank the TreeView and the Menu spits out CSS happily.  I can put the TreeView back in, yank out the footer code and the page spits out CSS happily. 

I call this a bug, not a feature.
 

 

0
AstroPHX
11/9/2007 11:34:28 PM

 God bless good search engines. Problem resolved.

http://forums.asp.net/p/1052121/1488821.aspx#1488821

 

 

0
AstroPHX
11/10/2007 12:03:02 AM
Reply:

Similar Artilces:

Trouble controlling .net controlls with CSS
 I am trying to control the :hover css property on <asp: Button> controls. Basically the css is working correctly to set the initial look of the button, but nothing is happening when I hover over the button. Here is my code:CSS:.sidebarButton{    width: 168px;     height: 45px;     background-color: #666666;     text-align: left;    font-weight: bold;    font-family: Century Gothic;    font-size: 13pt;    color: White;    border-style: none;  ...

Is CSS Control Adapters compatible with WebPart and WebPartZone controls?
Both WebPart and WebPartZone ultimately derive from WebControl, so it seems like this would work, but before I got into it deeply, was curious if anyone had tried it and if there are any issues? I don't think there is an esay way to make it works. This was a reply from Scott Guthrie: Unfortunately I don't think there is a super easy way to override WebParts -- since some of the layout does assume tables (since the CSS to-do this positioning with divs isn't super easy).  We are going to look at whether it is possible to build another control adapter for webparts in the f...

CSS friendly control adapter
Hi All,                     I am using a css file to control the look and feel of the treeview. The issue is the connecting lines are not showing up between nodes. Can some body point out what change needs to be done to my css.   The css content is as below:   .SimpleEntertainmentTreeView div.AspNet-TreeView ul li {white-space: nowrap; padding: 1px 0 1px 0; font-size:inherit;   } .SimpleEntertainmentTreeView div.AspNet-TreeView ul ul {margin: 2px 0 2px 10px; } .Simple...

Control Adapter for the Image control
I apologise if this is not the right group to ask, but I didn't see a better one...I'm trying to write a Control Adapter to override the rendering of the asp:Image control, mainly because I have some very image-heavy pages and I don't want the obligatory style="boder-width:0px;" that ASP.NET annoyingly applies to every image, thus adding to the overall page weight.This is what I'm trying to...public class ImageAdapter : WebControlAdapter { protected override void Render(HtmlTextWriter writer) { Image imageControl; imageControl = this.Control as Imag...

Sitemap control
How do i define which webpages can be rolled up or appear under other pages in the treeview navigation? My web.sitemap code: <?xml version="1.0" encoding="utf-8" ?><siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >    <siteMapNode url="Default.aspx" title="Home"  description="">         <siteMapNode url="tbe_JobManagerHome.aspx" title="Job Manager"  description="" />        <siteMapNode url="tbe_Project.aspx" title="Project Page"  description=...

Controlling Size of a TreeView Control
Hi guys,I have placed a Treeview control inside a table cel (into a master page). The toc itself is rather large, so the table cel adapts itself to the size of the Treeview control. But at this point it hides itself about 2 cm underneath my top banner, so the first few items in the toc cannot be entered. Is there a way to give the Treeview control a fixed size, so it starts using scrollbars if the toc becomes larger while expanding?Thx in advance,SubZero...

CSS Adapted Treeview control displaying all nodes on page load
Hi. I have decided to use the adapted Treeview control for a project I am working on at the moment. All the control will do is display lists of categories and sub categories, and eventually products at the bottom level. When I load my page up, everything is displayed, rather than the top level nodes. I have taken the control out and placed it in a small test project and exactly the same thing is happening. I am not using the App_Themes folder, I am linking directly to the CSS and Javascript files, and my CSS Treeview Adapter is in it's own .dll file. My code is below. If anyone could giv...

How do I control one control from another control?
I have a page page1.aspx which is within a master page. On page I have a table with two cells. Within each cell I have placed two controls (ascx) that I have developed. Now I'd like to be able to get these two controls to interact. One needs to update the other. One has some search criteria that the other one needs to update its gridview. One needs to make the other visible/not visible at certain times. Out of the box neither control can see each other at all. Is there a good article or someplace I can find some information on how to do this?  AllAboutFocus.com. Information Technolo...

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

css for rating control in control toolkit
 Hi All.Does anyone know where i can get the css and images for the rating control in the control toolkit?  Found them. They were in the toolkit...

TreeView control events restricted by other controls.
 I'm currently having a problem using a treeview control inside an update panel. I one update panels (containing the treeview) that is conditional update with triggers bound to a couple buttons. Those buttons are part of a second update panel which also contains a few labels, couple textboxes, and a dropdown list. That update panel updates conditionally when a node in the tree view is selected. When I select a node I populate the labels, text boxes, and select one of the values in the drop-down list. The problem is that if there's anything in the drop-down list or text-boxes it ...

Adding controls within Treeview control
I need to add text box , image button , additional checkbox (which is not given in tv control) , dropdown list , is it possible , if yes , please post some code snippet or atleast waysthanks for spending ur time...

Building a Control Adapter for the CheckBox control.
Hello all! I'm currently trying (and failing) to build a Control Adapter to modify how my CheckBox controls are rendered to the page. I don't like the way that by default they render inside a <span> tag. I'd like to change it so that they render inside a label tag. The good news is: I've managed to make the control render how I'd like; The bad news is: I've completely broken its functionality. I think the problem is that somehow I've stopped the ASP .NET engine recognising it. I get the following error:   Server Error in '/Bens' Applicatio...

Control CreateUser Wizard control with CSS
Hi there,can anybody tell me if its possible to align a CreateUser Wizard control using CSS? I presume i attached a class name to the CSS property of the control.But then what am i actually aligning? a Div? or similar... I believe there is some issues with centering DIVS on IE - can anyone confirm?If anybody can confirm what i should be doing to align the CreateUser Wizard control using CSS I would be really greatful...Currently I have3 divs - left, center, and right...the center div is where i have placed my Creatuserwizard but it flushed to the left...Not only that I have sent some CSS...

Web resources about - TreeView and CSS Control Adapters - asp.net.navigation-controls

Live-Beta TreeView Demo: Frameless Layout with Highlighting TreeView Demo: Frameless Layout with Highlighting ...
Welcome to our beta site for CBC Live mp3 streams! This is a form of online broadcast we are exploring right now, both from a technical best-practices ...

Visual Basic for Applications - Wikipedia, the free encyclopedia
Visual Basic for Applications ( VBA ) is an implementation of Microsoft 's event-driven programming language Visual Basic 6 and its associated ...

From the Saint
It's full steam ahead for events in the Saint today; although some have been postponed, others are getting bigger and better.

HOME - St. Catharines
St. Catharines is a city that offers many ammenities and opportunities to its residents. It is a place known for its friendliness, charm and ...

CrossFont Help
CrossFont Help

Examples - AlloyUI
AlloyUI is a framework built on top of YUI3 that provides a simple API for building high scalable applications.

allworldsoft.com — all software.
Xara X1 1.1 DL Xara X is an advanced graphic illustration package for Windows, that offers unrivaled redraw speed and a user interface which ...

CrossFont Help
CrossFont Help

Evolution of the Windows Interface
... a 3D button, comboboxes. Windows 95 introduced a slew of new 3D controls, such as rich text edit, toolbars/statusbar, progressbar, treeview/listview, ...

Silverlight - Blackboard
Silverlight is a development platform for creating rich media applications and business applications for the Web, desktop, and mobile devices.Microsoft ...

Resources last updated: 12/14/2015 6:03:32 AM