ASP.NET AJAX DragPanelExtender
ASP.NET AJAX DragPanelExtender
Hi,
In this post, I will show you how to create and use the DragPanel Control of ASP.NET AJAX.
The DragPanel Control allow you to move the panel around your web page in your ASP.NET application.
So lets start with creating new AJAX Control Toolkit Web Site in your Visual Studio. In previous post Using the ASP.NET AJAX Calendar Control you can see how to install the AJAX Control Toolkit.
The Panel Control
Lets drag a Panel Control into our page and call it PanelContainer, and in this panel drag another two panels: PanelHeader for the header, and PanelBody for the body.
The following html from specify how the Panel Container contains two embedded panels: one for the header and one for the body.
<body style="height: 100%;">
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:Panel ID="PanelContainer" runat="server" style="width: 200px;" BorderStyle="Double">
<asp:Panel ID="PanelHeader" runat="server" style="width: 100%; height: 100%;">
<div style="text-align: center">Panel Header...</div>
</asp:Panel>
<asp:Panel ID="PanelBody" runat="server" style="width: 100%; height: 100%; background-color: yellow">
<br />
Hello<br />
There<br />
!!<br />
</asp:Panel>
</asp:Panel>
</div>
</form>
</body>
Implement the DragPanelExtender Control
Drag a DragPanelExtender Control into the page, and specify the TargetControlID to the entire container - PanelContainer.
Also, we don't want to enable dragging from every point inside the container, but just from the header, so lets specify the DragHandleID to the PanelHeader.
The html page with the DragPanelExtender:
<body style="height: 100%;">
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="ScriptManager1" runat="server" />
<div>
<ajaxToolkit:DragPanelExtender ID="DragPanelExtender1" runat="server" TargetControlID="PanelContainer" DragHandleID="PanelHeader">
</ajaxToolkit:DragPanelExtender>
<asp:Panel ID="PanelContainer" runat="server" style="width: 200px;" BorderStyle="Double">
<asp:Panel ID="PanelHeader" runat="server" style="width: 100%; height: 100%;">
<div style="text-align: center">Panel Header...</div>
</asp:Panel>
<asp:Panel ID="PanelBody" runat="server" style="width: 100%; height: 100%; background-color: yellow">
<br />
Hello<br />
There<br />
!!<br />
</asp:Panel>
</asp:Panel>
</div>
</form>
</body>
Changing the Mouse Icon
For changing the mouse icon when dragging, we can use the following style:
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.dragIcon
{
text-align: center;
cursor: move;
font-weight: bold;
}
</style>
</head>
And add the drag icon into the div of the PanelHeader.
<asp:Panel ID="PanelHeader" runat="server" style="width: 100%; height: 100%;">
<div class="dragIcon" style="text-align: center">Panel Header...</div>
</asp:Panel>
Conclusion
In this post you have seen how easy to add drag and drop functionality on your web page using ASP.NET AJAX DragPanelExtender.

You can download the source code here.