Calendar demo

Source of: dynamicmenu.aspx
<%@ Import Namespace="System.Drawing" %>

<script runat="server">

    //
    // The server command handler which is fired then the menu item is chosen, that is a user clicks the menu item,
    // but after the client event has been handled.
    //
    protected void ItemContextMenu_Command(object sender, ActionEventArgs e) {
        ItemLabel.Text = '"'+e.Argument+"\" item selected...";
    }
    
</script>


    <script type="text/javascript" language="javascript">

        var GOTEST = 1;
        //
        // The event handler that is called by context menu just before menu appears on screen.
        //
        function itemContextMenu_MenuActivate(args) {
            //
            // Check the selected scheduler item, weather has any item clicked or clicked item is not of sum others items. 
            // If yes, the menu doesn�t appear. The menu appears only for regular items.
            //
            var schIt = SchObj.get_ClickedItem();
            if (schIt == null || schIt.get_ItemID() == "") {
                args.Cancel = true;
                return;
            }

            //
            // Remove all previous items from the menu.
            //
            MenuObj.Clear();

            //
            // Add the first item that appears a caption of the selected scheduler item.
            //
            var it = MenuObj.AddItem("");
            var s = SchObj.get_ClickedItem().get_Text();
            it.set_Text(s);
            it.set_CommandName("server request");
            it.set_CommandArgument(s);

            //
            // Add the second item that is initially disabled.
            //
            it = MenuObj.AddItem("Disabled menu item");
            it.set_Enabled(false);

            //
            // Add the third item that is hyperlink to the ComponentGo site.
            // Additionall, the item has an image on it.
            //
            it = MenuObj.AddItem("ComponentGo!");
            it.set_ImageUrl("conference.gif");
            it.set_NavigateUrl("http://www.componentgo.com");

            //
            // Add seperator line into menu.
            //
            MenuObj.AddSeparator();

            //
            // For each letter in scheduler item caption, create one menu item.
            //
            for (var i = 0; i < s.length; ++i) {
                it = MenuObj.AddItem("Letter: " + s.substr(i, 1).toUpperCase());

                it.set_CommandName("client alert");
                it.set_CommandArgument(it.get_Text());
            }
        }

        //
        // The client command handler which is fired then the menu item is chosen, that is a user clicks the menu item.
        //
        function itemContextMenu_Command(args) {
            //
            // Depending on command opens a message box with appropriate information. Setting the Cancel argument
            // to true value denies following sending command to the server, that is the server handler will not be fired.
            //
            if (args.Name == "client alert") {
                alert(args.Argument);
                args.Cancel = true;
            }
        }
        
    </script>

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <table width="100%">
                    <tr>
                        <td valign="top">
                            <gos:Scheduler ID="Sch" ObjectID="SchObj" runat="server" Height="293px" BackColor="SaddleBrown"
                                Caption="Dynamic menu building" Font-Names="Verdana" Font-Size="Small" FreeDateColor="IndianRed"
                                FreeTimeColor="PaleGoldenrod" HorizontalHeaderLine="1px Firebrick Solid" HorizontalLine="1px Firebrick Solid"
                                VerticalLine0="2px Firebrick Solid" VerticalLine1="1px Firebrick Solid" VerticalResourceLine="1px Firebrick Solid"
                                ForeColor="Navy" SplitterColor="Brown" VerticalLine2="1px Firebrick Dotted" LinkLine="1px Firebrick Solid"
                                BehaviorOptions="AllowOverlapItems, Default" ViewOptions="Default, InvisibleVerticalScrollBar, InvisibleHorizontalScrollBar">
                                <Columns>
                                    <gos:ResourceColumn Text="Caption">
                                    </gos:ResourceColumn>
                                </Columns>
                                <BodyStyle BackColor="LemonChiffon">
                                </BodyStyle>
                                <TimeLineStyle Font-Size="Small" BackColor="SaddleBrown" Font-Bold="True" Font-Names="Times New Roman"
                                    ForeColor="Linen">
                                </TimeLineStyle>
                                <CaptionStyle HorizontalAlign="Center" Font-Bold="True" Font-Size="Medium" BackColor="Peru"
                                    Font-Italic="True" Font-Names="Times New Roman" ForeColor="SeaShell">
                                </CaptionStyle>
                                <ResourceListStyle BackColor="BurlyWood" ForeColor="Brown">
                                </ResourceListStyle>
                                <ResourceHeaderStyle BackColor="Peru" Font-Bold="True" Font-Italic="True" Font-Names="Times New Roman"
                                    ForeColor="Maroon" HorizontalAlign="Center">
                                </ResourceHeaderStyle>
                                <DefaultItemStyle BackColor="SandyBrown" BorderColor="SaddleBrown" BorderStyle="Solid"
                                    BorderWidth="1px" ForeColor="Maroon" ContextMenuID="ItemContextMenu">
                                </DefaultItemStyle>
                            </gos:Scheduler>
                            <go:ContextMenuBox ID="ItemContextMenu" runat="server" Font-Names="Tahoma" Font-Size="8pt"
                                ObjectID="MenuObj" OnCommand="ItemContextMenu_Command">
                                <EventMenuActivate ClientScript="itemContextMenu_MenuActivate(args)" />
                                <EventCommand ClientScript="itemContextMenu_Command(args)" />
                            </go:ContextMenuBox>
                        </td>
                        <td valign="top" style='width: 250px'>
                            This demo presents a dynamic building of a context menu. Right click at the scheduler
                            item to display the context menu. Selecting first option of the menu fills follows
                            label with caption of scheduler item by using of MS AJAX.
                            <br />
                            <br />
                            Scheduler item:<br />
                            <asp:Label ID="ItemLabel" runat="server" ForeColor="#009933" Text="choose first option  of menu..."></asp:Label>
                            <br />
                            <br />
                            Selecting other options displays client alert windows without server request.<br />
                            Notice, every context menu has different number of items regards to dynamic building
                            of context menu by java script code.
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    <div style="font-size: 8pt">
        <p>
            The demo shows how to build context menu dynamically by client java script code.
            An appropriate scheduler items have linked the same context menu object. However,
            before the menu is shown the <i>MenuBox.MenuActivate</i> event is fired and the
            content of menu is modified. In this example the <i>itemContextMenu_MenuActivate</i>
            method handles the <i>MenuActivate</i> event. There are few client methods, like
            <i>Clear</i>, <i>AddItem</i>, <i>AddSeperator</i> designed for emitting new content
            of menu.
            <br />
            Another thing you can test here is a command handling. The menu commands are fired
            just after user clicks any menu items. The <i>MenuBox.Command </i>event is designed
            for this purpose. In this example, there are two handler methods:
        </p>
        <ul>
            <li>the <b>client</b>, java script �<i>function itemContextMenu_Command</i>� method,
                which is fired first in the web browser, </li>
            <li>and the second �<i>void ItemContextMenu_Command</i>� method, which is fired at the
                <b>server</b> code afterwards.</li>
        </ul>
        <p>
            The client handler displays an alert window for certain menu items that are marked
            by �<b>client alert</b>� command name. In order to deny following handling of event
            by the server code, the <i>Cancel</i> argument has to be set. The first menu item
            is ignored by the client handler and is passed follow to the server handler, which
            sets the label control with scheduler item name. Notice, the page is build of <b>MS
                AJAX</b> panel that allows updating two controls, scheduler and label, at the
            same time in one server request.
        </p>
    </div>

(C) ComponentGo! 2010 | Home | Site map | Partners | Links | Forum | info@componentgo.com