5,662,937 members and growing! (283 online)
Email Password   helpLost your password?
Web Development » Custom Controls » General     Intermediate

Y.A.R.D

By Venkat Eswaran

Yet Another Real Drag ASP.NET Draggable Panel like My MSN.
Javascript, SQL, C#, HTMLWindows, .NET, .NET 1.1, Win2K, WinXP, Win2003, Visual Studio, ASP.NET, ADO, ADO.NET, WebForms, SQL 2000, IE 6.0, SQL Server, IE, Architect, DBA, Dev

Posted: 14 Mar 2005
Updated: 21 Mar 2005
Views: 36,284
Bookmarked: 51 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
16 votes for this Article.
Popularity: 4.86 Rating: 4.04 out of 5
2 votes, 12.5%
1
2 votes, 12.5%
2
0 votes, 0.0%
3
4 votes, 25.0%
4
8 votes, 50.0%
5

Introduction

This is a control that will help you to make pages that can be customized 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 that Microsoft is doing some thing with .armx extension. I don't know what Microsoft is doing. But here I have overridden the 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 overridden the System.Web.UI.WebControls.Panel class. So the users can use all the properties and methods exposed by the Panel class. The control has three public properties:

  • Draggable - To mention whether the Panel has to made draggable or not.
  • PanelX - To get Panel's current X coordinates.
  • PanelY - To get Panel's current Y coordinates.
<%@ Register TagPrefix="cc1" Namespace="Drag" Assembly="Panel" %> 
<cc1:NewPanel Draggable=true id="NewPanel1" style="position:absolute;  
    width:155px; height:115px; z-index:1;" runat="server"
        cssClass="drag" align=center>
</cc1:NewPanel >

The above example is very simple. To get a look like My MSN, I have added a <table> within the Panel to get the outer structure, and another table within that for adding the contents within the table.

If this is not done then the user can drag the Panel by clicking anywhere in the Panel. This can be altered by the following line in the CS file.

strRender.Append("if (event.srcElement.parentElement" + 
    ".parentElement.parentElement.parentElement.tagName==\"DIV\"){");

The first parentElement selects the <TD> and the second parentElement selects the <TR> and the third parentElement selects the <TABLE> and the fourth parentElement selects the <DIV> which are rendered by the Panel. You can also change the class modhead of the <TD> which is used to drag the Panel.

<%@ Register TagPrefix="cc1" Namespace="Drag" Assembly="Panel" %> 
<cc1:NewPanel Draggable=true id="NewPanel1" 
   style="position:absolute;  width:155px; height:115px; z-index:1;"
        runat="server"  cssClass="drag" align=center>
 <table cellspacing=0 cellpadding=0 border=0 width=100% height=100%>
 <tr class="ss" height=22>
 <td class="mod_tlc" width=6> </td><td class="modhead"  
   width=100%><asp:Label text="My Inbox" 
     cssClass="tan-bold"  runat="server/"></td><td class="mod_trc" 
        width=6> </td>
 </tr>   
 <tr>
 <td colspan=3>
 <table cellspacing=0 cellpadding=0 width=100% height=100%   
   class="tables"><tr><td>Your content goes here</td></tr>
 </table>
 </td>
 </tr>
 </table>
</cc1:NewPanel >

In order to remember the position of each Panel the X and Y coordinates have to be saved once the user has moved the Panel from one position to another in the database.

I have set the ConnectionString in the web.Config file. The connection is created and opened in the constructor. On mouse-up, I have updated the X and Y positions with PanelId and UserId in the database.

The table structure is as follows:

  • UserID Varchar(50)
  • PanelID Varchar(50)
  • X Int
  • Y Int

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

this.Style.Add("Top",myReader["y"].ToString());
this.Style.Add("Left",myReader["x"].ToString());

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

I have hard coded the Draggable property to true, because by default whenever the page gets loaded, I have given the draggable feature to all the Panels as MY MSN.

public bool Draggable
 {
  get
  {
       return _draggable;
  }
  set
  {
       _draggable = true;
  }
 }

Steps to use the control

  • Extract the contents of the ZIP file to a virtual directory.
  • Copy the DLL to the bin directory.
  • Create the table "TEST" with the structure mentioned above.
  • Change the ConnectionString in the web.Config file.
  • Login with any username and password (both should be same, e.g.: USER=test PASSWORD=test)
  • Move the Panels anywhere in the page.
  • 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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Venkat Eswaran



Occupation: Web Developer
Location: India India

Other popular Custom Controls articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 9 of 9 (Total in Forum: 9) (Refresh)FirstPrevNext
Generalcode chunk..memberBULU19822:00 21 Aug '06  
Generalworks fine in a virtual directory only not in a VS.NET projectmemberdental20051:34 5 Sep '05  
GeneralErrormembermadhu_r20:46 18 Aug '05  
GeneralRe: ErrormemberVenkat Eswaran8:13 23 Aug '05  
GeneralPanel Rendering During Design Timemembercmcauliffe16:39 1 Aug '05  
GeneralRe: Panel Rendering During Design Timememberdude_401213:19 27 Nov '05  
GeneralRe: Panel Rendering During Design TimememberSaltire13:27 10 Dec '05  
GeneralA little help...memberzulfi_k6:35 14 Jun '05  
GeneralRe: A little help...memberVenkat Eswaran17:14 14 Jun '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 21 Mar 2005
Editor: Rinish Biju
Copyright 2005 by Venkat Eswaran
Everything else Copyright © CodeProject, 1999-2008
Java | Advertise on the Code Project