Link Button to RadMenuItem

2 posts, 0 answers
  1. Bradley D.
    Bradley D. avatar
    4 posts
    Member since:
    Oct 2012

    Posted 15 Nov 2012 Link to this post

    I have code for an asp.net link button
    <asp:LinkButton ID="LinkButton4" runat="server" Text="Copy To Clipboard" OnCommand="LinkButton4_Command"
            OnClientClick="CopyToClipboard();"></asp:LinkButton>
    I want to use it in a rad menu that I created when the user clicks on its menu item

    <telerik:RadMenu runat="server" ID="AssociateMenu" Skin="Windows7" Width="200px"
          Flow="Vertical" EnableAutoScroll="False">
          <Items>
              <telerik:RadMenuItem ID="AddAssociateMenuItem" runat="server" Text="Add Associate"
                  NavigateUrl="~/Add_Associate.aspx" />
              <telerik:RadMenuItem ID="ManageUserMenuItem" runat="server" Text="Manage User Account"
                  NavigateUrl="~/Create_User.aspx" />
              <telerik:RadMenuItem ID="DeactivateAssociateMenuItem" runat="server" Text="Deactivate Associate"
                  NavigateUrl="~/Deactivate_Associate.aspx" />
                   <telerik:RadMenuItem ID="CopyClipboardMenuItem" runat="server" Text="Copy To Clipboard"
                  PostBack="False" />
                    <telerik:RadMenuItem ID="PrintLabelMenuItem" runat="server" Text="Print Mailing Label"
                  PostBack="False" />
                   
          </Items>
      </telerik:RadMenu>

    i want client side code to run for the CopyClipboardMenuItem and PrintLabelMenuItem

    function CopyToClipboard() {
                       //RadPageView pv = (RadPageView)this.FindControl("RadPageView1");
     
                       //UserControl uc = (UserControl)pv.FindControl("UserControl1");
                       var textboxVal = $get("<%= txtCopy.ClientID%>").value;
                       //var textboxVal = ((TextBox)pc.FindControl("txtCopy")).Text.Trim();
                       // var textboxVal = document.getElementById("txtCopy").value;
                       if (window.clipboardData && clipboardData.setData) {
                           clipboardData.setData("Text", textboxVal);
                           alert("item successfully copy to Clipboard");
                       }
                       else {
                           alert("works only in IE4+");
                       }
                   }


    function printLabel() {
                        // alert('test4');
                        //  jQuery.lightbox({ href: "#dialog3" });
                        jQuery.colorbox({ innerWidth: "390", innerHeight: "210", opacity: .85, inline: true, overlayClose: false, transition: "fade", speed: 1500, href: "#dialog3" });
     
                    }

    The code works when I use a linkbutton

    <asp:LinkButton ID="LinkButton4" runat="server" Text="Copy To Clipboard"
    OnCommand="LinkButton4_Command"
            OnClientClick="CopyToClipboard();"></asp:LinkButton>
        </br>
        <asp:LinkButton ID="LinkButton2" runat="server" Text="Print Mailing Label"
    OnCommand="LinkButton2_Command"
            OnClientClick="printLabel(); return false;" AutoPostBack="false"></asp:LinkButton>

    Is there a way to do this I have not found a solution that works. Thanks in advance for any help.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 15 Nov 2012 Link to this post

    Hi Bradley,

    I suppose you want to execute the JavaScript functions based on the clicked RadMenuItem. One suggestion is that you can attach a OnClientItemClicked event to the RadMenu and you can execute the JavaScript function based on the text of the clicked RadMenuItem. Following is the sample code snippet that I tried based on your scenario.

    ASPX:
    <telerik:RadMenu runat="server" ID="AssociateMenu" Skin="Windows7" Width="200px" OnClientItemClicked="OnClientItemClicked" Flow="Vertical" EnableAutoScroll="False">
        <Items>
            <telerik:RadMenuItem ID="AddAssociateMenuItem" runat="server" Text="Add Associate NavigateUrl="~/Add_Associate.aspx" />
            <telerik:RadMenuItem ID="ManageUserMenuItem" runat="server" Text="Manage User Account" NavigateUrl="~/Create_User.aspx" />
            <telerik:RadMenuItem ID="DeactivateAssociateMenuItem" runat="server" Text="Deactivate Associate" NavigateUrl="~/Deactivate_Associate.aspx" />
            <telerik:RadMenuItem ID="CopyClipboardMenuItem" runat="server" Text="Copy To Clipboard" PostBack="False" />
            <telerik:RadMenuItem ID="PrintLabelMenuItem" runat="server" Text="Print Mailing Label" PostBack="False" />
        </Items>
    </telerik:RadMenu>

    JS:
    <script type="text/javascript">
        function OnClientItemClicked(sender, args) {
            if (args.get_item().get_text()== "Copy To Clipboard") {
                CopyToClipboard()
            }
            else if (args.get_item().get_text() == "Print Mailing Label") {
                printLabel();
            }
        }
    </script>

    Please elaborate your scenario if it doesn't helps.

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top