This is a migrated thread and some comments may be shown as answers.

Split Button, fire on menu click

3 Answers 158 Views
Button
This is a migrated thread and some comments may be shown as answers.
David Rhodes
Top achievements
Rank 1
David Rhodes asked on 23 May 2013, 10:17 AM
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>

3 Answers, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 28 May 2013, 09:43 AM
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.
0
David Rhodes
Top achievements
Rank 1
answered on 28 May 2013, 09:51 AM
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>
0
Danail Vasilev
Telerik team
answered on 30 May 2013, 11:54 AM
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.
Tags
Button
Asked by
David Rhodes
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
David Rhodes
Top achievements
Rank 1
Share this question
or