Drag and Drop Panel

IntroductionThis is a control which will help you to make pages that can be made customizable by the users. The Control exhibits similar properties like My MSN Drag n Drop. Backgrou

ITPro Today

March 30, 2005

3 Min Read
ITPro Today logo in a gray background | ITPro Today

Introduction

This is a control which will help you to make pages that can be made customizable by the users. The Control exhibits similar properties like My MSN Drag n Drop.

Background

I have seen many people posting their queries for the drag and drop feature like My MSN. Some of them have also posted
Microsoft is doing some thing with .armx extension. I dont know what Microsoft is doing. But here i have override System.Web.UI.WebControls.Panel Class

This control is very easy to use. The control exposes some public properties to set the draggable feature.


Using the code

I have just override System.Web.UI.WebControls.Panel Class. So user can use all the properties and methods exposed by
the Panel Class.
The control has three public properties:

Draggable - To mention the whether the panel has to made draggable or not.
PanelX - To get Panel current X coordinates.
PanelY - To get Panel current Y coordinates.

<%@ Register TagPrefix="cc1" Namespace="Drag" Assembly="Panel" %> true id="NewPanel1" style="position:absolute;  width:155px; height:115px; z-index:1;" runat="server"                                                                  cssClass="drag" align=center> 

The above example is very simple. To get a look like a My MSN. I have added a

with in the Panel to get the outer structure, and another table with in that for adding the contents with in the table. If this is not done then user can drag the Panel by clicking any clicking anywhere in the panel. This can be altered by the following line in the CS file.

The 1st parentElement selects the and 2nd parentElement selects the and 3rd parentElement selects the and 4th parentElement selects the which is rendered by Panel. You can also change the class "modhead" of the which is used drag the panel.

In order to remember the position of each panel the X and Y coordinates it has as to be saved once the user has moved panel from one position to another to the database.

I have set the ConnectionString in the web.Config. The connection is created and opened in the constructor. On mouseup I have updated the X and Y position with PanelId and UserId to the database.

The table structure:UserID  Varchar(50)PanelID Varchar(50)X         IntY         Int

It is possible to set the X and Y coordinates for the panel only in the CreateChildControls().

I have attached the Style.css which I got from My MSN website. You can add anything to this panel both in aspx page as well as in codebehind page as usual, and make them draggable in webpage.

I have hardcoded Draggable property to true because as defult when ever the page loads I have given draggable feature to all the panels as MY MSN.  

STEPS TO USE THE CONTROL:1. Extract the contents the ZIP file to a virtual directory.2. Copy the Dll to the Bin directory.3. Create the table "TEST" with the structure mentioned above.4. Change the ConnectionString in the web.Config file.5. Login with any username and password (both should be same ex: USER=test PASSWORD=test)6. Move the panels anywhere in the page.7. Logout and Login with the same username and password to see the customization.

Users can also include a PageId in the table and use the control throughout the project.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like