Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
Both Server-side and Client-side events on a menu item
posted

Is there a way to handle both server-side and client-side events on a WebDataMenu ItemClick event.  On one menu item I want to run client-side script and not force a postback to the server.  The second menu item I want to post back to server and run the server side Item Click event.

I attempted to do it in the following code, but had inconsistent results. 

If you alternate between clicking the first client-side menu item, then click the second menu item, the server-side event does not always launch.

I also experience this issue if I keep clicking the second menu item only.  It doesn't always launch.

Also, why does the label I try to assign text to in the server-side event never get updated?

<head runat="server">
    <title>Untitled Page</title>

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

    function WebDataMenu1_MenuItem_Click(menu, eventArgs) {
        switch (eventArgs.getItem().get_key()) {
            case "Copy":
           
                //fetch the value string and copy to clipboard
                var message = menu.getItems().getItem(0).get_valueString();

                // set the clipboard
                window.clipboardData.setData('text', message);
               
                eventArgs.set_cancel(true);

                break;

            case "Regenerate":
           
                eventArgs.set_cancel(false);
               
                break;
        }
    }

function WebDataMenu1_onMouseClick(stmtID, asOfDate, client) { 

    var event = window.event;

    // we assume we have a standards compliant browser, but check if we have IE
    var target = event.target != null ? event.target : event.srcElement;

    var menu = $find("WebDataMenu1");

    var message = 
        'params.StmtID = ' + stmtID + '\n' +
        'params.AsOfDate = #' + asOfDate + '#\n' +
        'params.Client = ' + client
     
    menu.getItems().getItem(0).get_element().title = message;
    menu.getItems().getItem(0).set_valueString(message);

    menu.showAt(null,null, event);

 }
  
    </script>

    <script language="VB" runat="server">

        Sub WebDataMenu_ItemClick(ByVal sender As Object, ByVal e As Infragistics.Web.UI.NavigationControls.DataMenuItemEventArgs)

            lblMessage.Text = "You clicked the Regenerate menu item"

        End Sub
   
    </script>

</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <input id="btnHelloWorld" type="button" value="Hello World" oncontextmenu="BLOCKED SCRIPTWebDataMenu1_onMouseClick(1234, '5/31/2010', 1000)" />
        <asp:Label ID="lblMessage" runat="server"></asp:Label>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <ig:WebDataMenu ID="WebDataMenu1" IsContextMenu="True" runat="server" BorderWidth="1px"
                    OnItemClick="WebDataMenu_ItemClick">
                    <ClientEvents ItemClick="WebDataMenu1_MenuItem_Click" />
                    <Items>
                        <ig:DataMenuItem Key="Copy" Text="Copy Parameters to Clipboard" />
                        <ig:DataMenuItem Key="Regenerate" Text="Regenerate Statement on Server" />
                    </Items>
                </ig:WebDataMenu>
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>

I'm using Infragistics2.Web.v10.1, Version=10.1.20101.2039

Chad

  • 14517
    Suggested Answer
    Offline posted

    Hello Chad,

    This functionality was added in the latest service release (5/19/2010). Please download the service release and let me know if you have any other questions.

    Thanks,
    Valerie