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

RadToolBarSplitButton +select +server-side

3 Answers 165 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Bruce Hochstetler
Top achievements
Rank 2
Bruce Hochstetler asked on 24 Jun 2008, 11:16 PM
Hi,

I'm starting the painful process of converting to the new rad controls. One of the issues I'm having is the ability to select an item in the buttons collection of the RadToolBarSplitButton class on the server-side during the page load. Previously (old controls) I had a RadComboBox in the toolbar and would select the combo box item. I decided to try the new SplitButton and I'm trying to implement the same logic with no luck. I've tried setting the main split button's text and value, but after doing that the text/value never changes regardless of what selection I make from the drop down.

Thanks,
Bruce

3 Answers, 1 is accepted

Sort by
0
Erjan Gavalji
Telerik team
answered on 25 Jun 2008, 06:39 AM
Hi Bruce,

The reason for the RadToolBarSplitButton not displaying the text that's been set to it is the "DefaultButton" behavior. This behavior (turned on/off by using the EnableDefaultButton property) makes RadToolBarSplitButton use the properties of one of its child buttons. You can control which button to be used by the DefaultButtonIndex property.

To take the full control of the displayed text (and the value when the split button is clicked), all you need is set the EnableDefaultButton property to false.

I hope this helps.

Kind regards,
Erjan Gavalji
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bruce Hochstetler
Top achievements
Rank 2
answered on 25 Jun 2008, 03:59 PM

Hi Erjan,

Unfortunately the solution provided is not working for me. Here's the declaration:

<telerik:RadToolBar ID="MenuToolbar" runat="server" AutoPostBack="True"
     Skin
="Telerik" OnClientButtonClicking="MenuToolbarClientClicking">
<Items>
    <telerik:RadToolBarSplitButton runat="server" PostBack="true"
        
EnableDefaultButton="false">
        <Buttons>
            <telerik:RadToolBarButton Value="2" Text="2" runat="server"/>
            <telerik:RadToolBarButton Value="5" Text="5" runat="server"/>
            <telerik:RadToolBarButton Value="10" Text="10" runat="server"/>
            <telerik:RadToolBarButton Value="15" Text="15" runat="server"/>
            <telerik:RadToolBarButton Value="20" Text="20" runat="server"/>
            <telerik:RadToolBarButton Value="25" Text="25" runat="server"/>
            <telerik:RadToolBarButton Value="30" Text="30" runat="server"/>
        </Buttons>
    </telerik:RadToolBarSplitButton>
</Items>
</telerik:RadToolBar>

During the page load I get a cookie value that indicates what the user's last selection was.  I then get the split button by doing the following:

RadToolBarButton button = (RadToolBarSplitButton)MenuToolbar.Items[0];

Then I traverse the list of buttons:

int cookie_value = '15'; // default value
for (int i = 0; i<button.Buttons.Count; i++) {
    if (button.Buttons[i].Value == cookie_value) {
        button.Value = button.Text = cookie_value;
        button.DefaultButtonIndex = i;
    }
}

At this point the split button is set to the index of where the cookie value is. Now when I select a new value from the split button, say something like '5', which is at index 1. I get a postback, go into some code that gets the split button. When I interogate the button, the value/text is still set to the cookie_value (15). So I'm never able to determine what value has been selected after setting the DefaultButtonIndex initially. Basically all I want to do is initially set the selection at startup. After that be able to interrogate the value selected on the postback and save the value into a cookie.

Thanks,
Bruce

0
Peter
Telerik team
answered on 27 Jun 2008, 02:30 PM
Hi Bruce,

I am a bit confused. If I understand correctly what you try to achieve, then it is already offered as a built-in functionality of RadToolbar. Please, try the code below, and let us know if this is what you neeed:

aspx:
 <telerik:RadToolBar ID="MenuToolbar"   
         OnClientButtonClicking="MenuToolbarClientClicking"   
         runat="server" AutoPostBack="True"   
         Skin="Telerik" OnButtonClick="MenuToolbar_ButtonClick" >             
            <Items> 
                <telerik:RadToolBarSplitButton runat="server" EnableDefaultButton="True">  
                    <Buttons> 
                        <telerik:RadToolBarButton Value="2" Text="2" runat="server" /> 
                        <telerik:RadToolBarButton Value="5" Text="5" runat="server" /> 
                        <telerik:RadToolBarButton Value="10" Text="10" runat="server" /> 
                        <telerik:RadToolBarButton Value="15" Text="15" runat="server" /> 
                        <telerik:RadToolBarButton Value="20" Text="20" runat="server" /> 
                        <telerik:RadToolBarButton Value="25" Text="25" runat="server" /> 
                        <telerik:RadToolBarButton Value="30" Text="30" runat="server" /> 
                    </Buttons> 
                </telerik:RadToolBarSplitButton> 
            </Items> 
            <CollapseAnimation Duration="200" Type="OutQuint" /> 
        </telerik:RadToolBar> 
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> 

C#
 protected void Page_Load(object sender, EventArgs e)  
    {  
        if (!IsPostBack)  
        {  
            RadToolBarSplitButton button = (RadToolBarSplitButton)MenuToolbar.Items[0];  
 
            string cookie_value = "15"// default value  
            for (int i = 0; i < button.Buttons.Count; i++)  
            {  
                if (button.Buttons[i].Value == cookie_value)  
                {  
                    //button.Value = button.Text = cookie_value;  
                    button.DefaultButtonIndex = i;  
                }  
            }  
        }  
          
    }  
    protected void MenuToolbar_ButtonClick(object sender, RadToolBarEventArgs e)  
    {  
        RadToolBarSplitButton button = (RadToolBarSplitButton)MenuToolbar.Items[0];  
        button.DefaultButtonIndex = e.Item.Index;  
        Session["ValueOfLastClickedButton"] = e.Item.Value;  
            
    }  
    protected void Button1_Click(object sender, EventArgs e)  
    {  
        Response.Write("The value of the last clicked button is " + (string)Session["ValueOfLastClickedButton"]);  
    } 


Regards,
Peter
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ToolBar
Asked by
Bruce Hochstetler
Top achievements
Rank 2
Answers by
Erjan Gavalji
Telerik team
Bruce Hochstetler
Top achievements
Rank 2
Peter
Telerik team
Share this question
or