Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Get DIV properties on server side.

I rolled my own treeview (didn't like the MS IEControls one) and everything is working great except the viewstate.  I can't figure out how to capture whether a node is expanded or not on the server side.

1) Page loads
2) All top level tree nodes are set as visible (<div style='display:block;'>) and all child nodes are set as invisible (<div style='display:none;'>).
3) User clicks around expanding nodes and selects a node.  Clicks a submit button that causes postback to server.

How can I get which nodes (div's) are now visible/invisible?

I've tried interrogating the attributes property in hopes I could get "style=display:block" but it's empty.

Note that the control does NOT postback when a user expands or contracts a node - this is the problem.  I need to know what happened on the client side when a post to the server is done.

Any ideas?

Saturday, January 22, 2005

Nevermind...added a hidden field client side to hold comma delimited list of client id's of all tree nodes that are visible.  When a node is expanded all it's children are added to the hidden field.  When a node is contracted all it's children are removed from the hidden field.  On post back just read hidden field to see if a node should be hidden or shown.

Saturday, January 22, 2005

Too early & no time before having to catch the train, but I think one of the HtmlWhateverControls would do the trick.  If not, asp:Panels render as DIVs, so perhaps you could go that route as well.

A comma-delimited list seems so 90s... :P

Greg Hurlman
Monday, January 24, 2005

" asp:Panels render as DIVs"

This may not always be true...

I think that the framework sometimes pushes out Tables if it thinks the browser cannot handle DIV.

I think we had to teach our server to hand out div's to firfox/moz etc

Monday, January 24, 2005

Yes, you're probably right; too much IE5.5SP2 corporate development for me I'm afraid.

But, having had chance to get to work and check the docs, it seems that the HtmlGenericControl should be able to give the server-side support for DIVs that you need.

Entirely too long MSDN link:

Greg Hurlman
Monday, January 24, 2005

Just to reiterate: there is no built-in control in .NET anywhere that will have DIVs posting back whether they were hidden or not.

You could write such a control, and instead of a comma delimited single field, you'd likely end up with one hidden edit control per DIV.

In the end, neither solution is particularly better than the other. One is more reusable, one is lighter on the wire. Your requirements may dictate which is best.

Brad Wilson (
Tuesday, January 25, 2005

*  Recent Topics

*  Fog Creek Home