Search code examples
asp.netweb-partsresize

Drag-and-drop resizing of ASP.Net web part


I'm working on a project that includes a page of ASP.Net web parts. It has been requested that the web parts be made resizable through clicking on a glyph in the lower right hand corner and dragging the web part to the desired size. Of course, the new size needs to be persisted. (Ideally, the other web parts would move and resize themselves to accommodate the changing web part, but let's tackle one challenge at a time.)

Is there an easy, or at least relatively well-tried, way to achieve this? I know the resizing could be done fairly easily with jQuery, but persisting the new size is the tricky part.


Solution

  • Are you using ASP.Net Personalization for your web parts? If so, you could define a class property in each of your web part controls (my controls are inheriting from UserControl and implementing IWebPart) to hold the size of the part. Then you can use your jquery solution or whatever on the client side, pass back the new size to the server side (using a hidden field or whatever) and assign the size to the property (also need to read the property on page load, of course). Voila, persisted web part size.

    This is all assuming you have implemented Personalization on your database. It's actually very easy to set up.. search using keywords aspnet_regsql and personalization.