<%@ Register TagPrefix="ecd" Namespace="ASPNETExpert.WebControls.DemoControls" Assembly="ASPNETExpert.WebControls.DemoControls" %>
<%@ Register TagPrefix="ecd" TagName="Footer" Src="../../Controls/Footer.ascx"%>
<%@ Register TagPrefix="ecd" TagName="Header" Src="../../Controls/Header.ascx"%>
<%@ Register TagPrefix="ec" Namespace="ASPNETExpert.WebControls" Assembly="ASPNETExpert.WebControls" %>
<%@ Page language="c#" Inherits="ASPNETExpert.WebControls.Demo.Menu.Advanced.DragDrop._default" CodeFile="default.aspx.cs" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>ASP.NET Menu : ExpertMenu Demo : Drag-And-Drop Menu Item</title>
<link href="../../style.css" type="text/css" rel="stylesheet">
</HEAD>
<body xmlns:ec="urn:http://aspnetexpert.com/ExpertControls.xsd">
<form id="Form1" method="post" runat="server">
<script language="javascript">
function Drop(dragDrop) {
if(dragDrop.Source.OnClientBefore && dragDrop.Source.OnClientBefore.Drop)
return true;
var target = '';
if(dragDrop.Target)
target = (dragDrop.Target.GetType() == 'MenuSeparator' ? 'before separator' : 'onto "' + dragDrop.Target.Text + '"');
else
if(dragDrop.TargetBefore)
target = ' before ' + (dragDrop.TargetBefore.GetType() == 'MenuSeparator' ? 'separator' : '"' + dragDrop.TargetBefore.Text + '"');
else
if(dragDrop.TargetAfter)
target = ' after ' + (dragDrop.TargetAfter.GetType() == 'MenuSeparator' ? 'separator' : '"' + dragDrop.TargetAfter.Text + '"');
return confirm('Drop the item "' + dragDrop.Source.Text + '" ' + target + '?');
}
function RandomDrag() {
if(Math.random()<0.4)
return true;
alert('It is not time to drag!');
return false;
}
function RandomDrop() {
if(Math.random()<0.6)
return true;
alert('It is not time to drop!');
return false;
}
</script>
<ecd:Header runat="server" ID="Header1"></ecd:Header>
<ec:ExpertMenu runat="server" id="ExpertMenu1" Skin="Office03Olive" DragAndDropEnabled="true">
<OnClientBefore DropHandler="Drop" />
<TopGroup>
<Items>
<ec:MenuSeparator />
<ec:MenuItem Text="File">
<SubMenu>
<Items>
<ec:MenuItem Text="New... (droppable at random)" OnClientBefore-Drop="RandomDrop()" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_new.gif" />
<ec:MenuItem Text="Open..." DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_open.gif" />
<ec:MenuSeparator />
<ec:MenuItem Text="Send To (not draggable)" IsDraggable="False">
<SubMenu>
<Items>
<ec:MenuItem Text="Mail Recipient" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_mailRecipient.gif" />
<ec:MenuItem Text="Mail Recipient (for Review)..." DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_mailRecipientReview.gif" />
<ec:MenuItem Text="Mail Recipient (As Attachment)..." DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_mailRecipientAttachmnt.gif" />
<ec:MenuItem Text="Routing Recipient..." DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_routingRecipient.gif" />
<ec:MenuItem Text="Exchange Folder..." DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_exchangeFolder.gif" />
<ec:MenuSeparator />
<ec:MenuItem Text="Microsoft Office PowerPoint..." DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_powerPoint.gif" />
</Items>
</SubMenu>
</ec:MenuItem>
<ec:MenuSeparator />
<ec:MenuItem Text="Save" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_save.gif" />
<ec:MenuItem Text="Save As" />
<ec:MenuItem Text="Save as Web Page" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_saveAsWebPage.gif" />
<ec:MenuItem Text="File Search" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_fileSearch.gif" />
<ec:MenuSeparator />
<ec:MenuItem Text="Page Setup..." />
<ec:MenuItem Text="Print Preview" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_printPreview.gif" />
<ec:MenuItem Text="Print..." DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_print.gif" />
<ec:MenuSeparator />
<ec:MenuItem Text="Exit" />
</Items>
</SubMenu>
</ec:MenuItem>
<ec:MenuItem Text="Edit">
<SubMenu>
<Items>
<ec:MenuItem Text="Cut" Enabled="False" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_cut.gif" />
<ec:MenuItem Text="Copy" Enabled="False" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_copy.gif" />
<ec:MenuItem Text="Office Clipboard..." DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_clipboard.gif" />
<ec:MenuItem Text="Paste" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_paste.gif" />
<ec:MenuSeparator />
<ec:MenuItem Text="Find..." DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_find.gif" />
<ec:MenuItem Text="Clear (draggable at random)" OnClientBefore-Drag="RandomDrag()">
<SubMenu>
<Items>
<ec:MenuItem Text="Formats" />
<ec:MenuItem Text="Contents" />
</Items>
</SubMenu>
</ec:MenuItem>
</Items>
</SubMenu>
</ec:MenuItem>
<ec:MenuItem Text="View">
<SubMenu>
<Items>
<ec:MenuItem Text="Normal" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_normal.gif" />
<ec:MenuItem Text="Web Layout" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_webLayout.gif" />
<ec:MenuItem Text="Reading Layout" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_readingLayout.gif" />
<ec:MenuItem Text="Outline" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_outline.gif" />
<ec:MenuSeparator />
<ec:MenuItem Text="Ruler" Checked="True" IconLook-Base="CheckItem" />
<ec:MenuSeparator />
<ec:MenuItem Text="Document Map" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_documentMap.gif" />
<ec:MenuItem Text="Thumbnails" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_thumbnails.gif" />
<ec:MenuItem Text="Header and Footer" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_headerFooter.gif" />
</Items>
</SubMenu>
</ec:MenuItem>
<ec:MenuItem Text="Format">
<SubMenu>
<Items>
<ec:MenuItem Text="Font..." DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_font.gif" />
<ec:MenuItem Text="Paragraph..." DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_paragraph.gif" />
<ec:MenuItem Text="Bullets and Numbering..." DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_bullets.gif" />
<ec:MenuItem Text="Borders and Shading..." />
<ec:MenuSeparator />
<ec:MenuItem Text="Frames">
<SubMenu>
<Items>
<ec:MenuItem Text="Table of Contents in Frame" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_tableOfContents.gif" />
<ec:MenuItem Text="New Frames Page" />
</Items>
</SubMenu>
</ec:MenuItem>
<ec:MenuItem Text="Auto Format..." DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_autoFormat.gif" />
<ec:MenuItem Text="Styles and Formatting..." DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_stylesAndFormatting.gif" />
<ec:MenuItem Text="Reveal Formatting..." DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_revealFormatting.gif" />
</Items>
</SubMenu>
</ec:MenuItem>
<ec:MenuItem Text="Help">
<SubMenu>
<Items>
<ec:MenuItem Text="Microsoft Office Word Help" DualIconLook-InitLook-LeftIcon-ImageUrl="../../images/Office2003/icon_help.gif" />
<ec:MenuItem Text="Show the Office Assistant" />
<ec:MenuSeparator />
<ec:MenuItem Text="Microsoft Office Online" />
<ec:MenuItem Text="Contact Us" />
<ec:MenuSeparator />
<ec:MenuItem Text="Word Perfect Help" />
<ec:MenuSeparator />
<ec:MenuItem Text="Check for Updates" />
<ec:MenuItem Text="Detect and Repair" />
<ec:MenuItem Text="Activate Product..." />
<ec:MenuItem Text="Customer Feedback Options..." />
<ec:MenuSeparator />
<ec:MenuItem Text="About Microsoft Office Word" />
</Items>
</SubMenu>
</ec:MenuItem>
</Items>
</TopGroup>
</ec:ExpertMenu>
<br>
<asp:Button Runat="server" Text="Load Menu from XML" ID="DeserializeMenu" onclick="DeserializeMenu_Click" />
<br>
<ecd:DescriptionView runat="server" IconUrl="../../images/kv.gif" ID="Descriptionview1">
<ecd:Description id="Description1" runat="server">Set <b>DragAndDropEnabled="true"</b> in
<b>ExpertMenu</b> to enable drag and drop the menu items.</ecd:Description>
<ecd:Description id="Description2" runat="server">Process a server-side event
<b>MenuItemMove</b> to process the movement at the server.</ecd:Description>
<ecd:Description id="Description3" runat="server">You can also process drag and drop
events on the client-side controlling whether to enable dragging and dropping an item.</ecd:Description>
<ecd:Description id="Description4" runat="server">You can easily serialize / deserialize menu
configuration into / from XML.</ecd:Description>
</ecd:DescriptionView>
<ec:CodeViewTab id="CodeViewTab1" runat="server" ImagesBaseUrl="../../images/tab/">
<ec:TabItem runat="server" Text="aspx" ID="Tabitem1">
<pre class="aspcode">
<ecd:SyntaxHighlight runat="server" ContentType="ASPX" OutputFile="default.aspx" ID="Syntaxhighlight1"/>
</pre>
</ec:TabItem>
<ec:TabItem runat="server" Text="C#" ID="Tabitem2">
<pre class="aspcode">
<ecd:SyntaxHighlight runat="server" ContentType="C#" OutputFile="default.aspx.cs" ID="Syntaxhighlight2"/>
</pre>
</ec:TabItem>
<ec:TabItem runat="server" Text="VB" ID="Tabitem3">
<pre class="aspcode">
<ecd:SyntaxHighlight runat="server" ContentType="VB" OutputFile="default_vb.aspx.vb" ID="Syntaxhighlight3"/>
</pre>
</ec:TabItem>
</ec:CodeViewTab>
<ecd:Footer runat="server" ID="Footer1"></ecd:Footer>
</form>
</body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Xml;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace ASPNETExpert.WebControls.Demo.Menu.Advanced.DragDrop
{
///
/// Summary description for _default.
///
public partial class _default : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.ExpertMenu1.MenuItemMove += new ASPNETExpert.WebControls.MenuMoveEventHandler(this.ExpertMenu1_MenuItemMove);
}
#endregion
private void ExpertMenu1_MenuItemMove(object sender, ASPNETExpert.WebControls.MenuMoveEventArgs eventArgs)
{
eventArgs.HandleMove();
SaveMenu("MenuConfiguration");
}
protected void DeserializeMenu_Click(object sender, System.EventArgs e)
{
LoadMenu("MenuConfiguration");
}
private void SaveMenu(string keyName)
{
XmlTextWriter writer = null;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
try
{
writer = new XmlTextWriter(new StringWriter(sb));
writer.Formatting = Formatting.Indented;
writer.Indentation = 4;
writer.IndentChar = ' ';
ExpertMenu1.TopGroup.Serialize(writer);
}
finally
{
if(writer != null)
writer.Close();
}
Session[keyName] = sb.ToString();
}
private void LoadMenu(string keyName)
{
if(Session[keyName] == null)
return;
XmlDocument doc = new XmlDocument();
doc.Load(new StringReader(Session[keyName].ToString()));
ExpertMenu1.TopGroup.Items.Clear();
ExpertMenu1.TopGroup.Deserialize(doc.DocumentElement);
}
}
}
Imports System.Xml
Imports System.IO
Namespace ASPNETExpert.WebControls.DemoVB.Advanced.DragDrop
Partial Class default_vb
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub ExpertMenu1_MenuItemMove(ByVal sender As System.Object, ByVal e As ASPNETExpert.WebControls.MenuMoveEventArgs) Handles ExpertMenu1.MenuItemMove
e.HandleMove()
SaveMenu("MenuConfiguration")
End Sub
Private Sub DeserializeMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeserializeMenu.Click
LoadMenu("MenuConfiguration")
End Sub
Private Sub SaveMenu(ByVal keyName As String)
Dim writer As XmlTextWriter = Nothing
Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder
Try
writer = New XmlTextWriter(New StringWriter(sb))
writer.Formatting = Formatting.Indented
writer.Indentation = 4
writer.IndentChar = " "c
ExpertMenu1.TopGroup.Serialize(writer)
Finally
If Not writer Is Nothing Then
writer.Close()
End If
End Try
Session(keyName) = sb.ToString()
End Sub
Private Sub LoadMenu(ByVal keyName As String)
If Session(keyName) Is Noth