RadToolBarSplitButton +select +server-side

4 posts, 0 answers
  1. Bruce Hochstetler
    Bruce Hochstetler avatar
    155 posts
    Member since:
    Apr 2007

    Posted 24 Jun 2008 Link to this post

    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
  2. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 25 Jun 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bruce Hochstetler
    Bruce Hochstetler avatar
    155 posts
    Member since:
    Apr 2007

    Posted 25 Jun 2008 Link to this post

    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

  5. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 27 Jun 2008 Link to this post

    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
Back to Top