Split Button, fire on menu click

4 posts, 0 answers
  1. David Rhodes
    David Rhodes avatar
    60 posts
    Member since:
    May 2005

    Posted 23 May 2013 Link to this post

    Hi,

    I have a split button (below), when I click on a RadMenuItem i'd like to postback immediately rather than changing the button text and the user then requiring to click again, how would I accomplish this?

    <telerik:RadButton ID="CloneSplitButton" AutoPostBack="false" runat="server" Text="Clone"
        EnableSplitButton="true" Height="22px" Enabled="true" CommandName="SaveReturn"
        UseSubmitBehavior="false" OnClientClicked="OnClientCloneSplitButtonClicked" OnClick="CloneSplitButton_Click">
    </telerik:RadButton>
    <telerik:RadContextMenu ID="CloneContextMenu" runat="server" OnClientItemClicked="OnClientCloneContextMenuClicked"
        EnableRoundedCorners="true">
        <Items>
            <telerik:RadMenuItem Text="New Quick Quote" />
            <telerik:RadMenuItem Text="New Subscription" />
        </Items>
    </telerik:RadContextMenu>
    <telerik:RadCodeBlock runat="server">
        <script type="text/javascript">
            function OnClientCloneSplitButtonClicked(sender, args) {
                if (args.IsSplitButtonClick()) {
                    var currentLocation = $telerik.getLocation(sender.get_element());
                    var contextMenu = $find("<%= CloneContextMenu.ClientID %>");
                    contextMenu.showAt(currentLocation.x, currentLocation.y + 22);
                    sender.set_autoPostBack(false);
                }
                else {
                    sender.set_autoPostBack(true);
                    window.setTimeout(function () {
                        sender.set_enabled(false);
                    }, 0);
                }
            }
            function OnClientCloneContextMenuClicked(sender, args) {
                var itemText = args.get_item().get_text();
                var splitButton = $find("<%= CloneSplitButton.ClientID %>");
     
                if (itemText == "New Quick Quote") {
                    splitButton.set_text("Clone to New Quick Quote");
                    splitButton.set_commandName("CloneQuickQuote");
                }
                else {
                    splitButton.set_text("Clone to New Subscription");
                    splitButton.set_commandName("CloneSubscription");
                }
            }
        </script>
    </telerik:RadCodeBlock>
  2. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1494 posts

    Posted 28 May 2013 Link to this post

    Hi David,

    You can perform a JavaScript postback on behalf of the CloneSplitButton in the OnClientCloneContextMenuClicked function. For example:
    function OnClientCloneContextMenuClicked(sender, args) {
     
        var itemText = args.get_item().get_text();
        var splitButton = $find("<%= CloneSplitButton.ClientID %>");
     
        if (itemText == "New Quick Quote") {
            splitButton.set_text("Clone to New Quick Quote");
            splitButton.set_commandName("CloneQuickQuote");
            __doPostBack("<%= CloneSplitButton.ClientID %>", "");
        }
        else {
            splitButton.set_text("Clone to New Subscription");
            splitButton.set_commandName("CloneSubscription");
            __doPostBack("<%= CloneSplitButton.ClientID %>", "");
        }
    }
    This in turn will trigger the server-side event handler of the CloneSplitButton. More information on using the __doPostBack is available in this forum thread.

    Regards,
    Danail Vasilev
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. David Rhodes
    David Rhodes avatar
    60 posts
    Member since:
    May 2005

    Posted 28 May 2013 Link to this post

    Hi,
    That works but does not fire the server-side click event of the Button (CloneSplitButton_Click), is there anything I can change to make that fire?
    <telerik:RadButton ID="CloneSplitButton" runat="server" EnableSplitButton="true" AutoPostBack="false" Text="Clone" UseSubmitBehavior="false" OnClientClicked="OnClientCloneSplitButtonClicked" OnClick="CloneSplitButton_Click">
    </telerik:RadButton>
  5. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1494 posts

    Posted 30 May 2013 Link to this post

    Hello David,

    I have tried to reproduce your issue but to no avail. You can find a short video with the test in the attached archive. Could you please have a look at it and then notify me what I am missing?

    You can also try to reproduce the issue with the attached example and then tell me what changes you have made, so I can investigate it locally.

    Regards,
    Danail Vasilev
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top