DotnetDude
DotnetDude

Reputation: 11807

Reordering the position of usercontrols on a ASP.NET page

I am working on a page that has user controls that are arranged in a particular layout. I am modifying that page to support reordering the position based on user's preferences. So, essentially, on load, I have information on where I need to position the different user controls.

I can think of 2 approaches:

Are there any other ways of accomplishing what I am trying to do?

Upvotes: 0

Views: 1048

Answers (2)

Ashwin Singh
Ashwin Singh

Reputation: 7345

I would recommend rearranging on the client-side because

  1. You will save a post-back.
  2. You will make the website seamless.

How can do you that

  1. Use a main div containing all controls and another containing a loading image. Toggle there visibility while rearranging the controls using javascript, or
  2. You can set visibility:hidden to your body and then after rearranging set visibility:visible

The drawback of this approach is that you will have to use absolute positioning.

Upvotes: 1

Brian Mains
Brian Mains

Reputation: 50728

There is an easier way; rendering is controlled by the parent container rendering them. It is possible to create a container, and have full control over the ordering of the rendering of its children (by overriding the RenderChildren method). It's not the easiest option, but it can work. The steps are:

  • Create a class that inherits from ContainerControl
  • Override the RenderChildren method
  • Within this method, it would render the children in the container, override it, do not call the base class version of it, and get the instances to the controls and render them. This is where the complication arises because you have to.

Upvotes: 0

Related Questions