Problem with selected property of Toggle state

5 posts, 0 answers
  1. Vaneeth
    Vaneeth avatar
    4 posts
    Member since:
    Sep 2012

    Posted 19 Sep 2012 Link to this post

    Hello , I am using a toggle button and trying to set toggle state programmatically. But always the tagglestate[1] is selected on page load. Can you please explain how this works

    My sample code

    Aspx page

     

    <telerik:RadButton ID="btnPlayStop" runat="server" ButtonType="ToggleButton" ToggleType="CheckBox"

     

     

    Width="30px" Height="30px" AutoPostBack="true" ForeColor="Black" OnToggleStateChanged="btnPlayStop_CheckedChanged" Visible='<%# !IsAddNewMode %>' >

     

     

    <ToggleStates>

     

     

    <telerik:RadButtonToggleState ImageUrl="~/Images/button_green_stop.png" HoveredImageUrl="~/Images/button_green_stop.png"

     

     

    Text="Stop" />

     

     

    <telerik:RadButtonToggleState ImageUrl="~/Images/button_play_green.png" HoveredImageUrl="~/Images/button_play_green.png"

     

     

    Text="Play" />

     

     

    </ToggleStates>

     

     

    </telerik:RadButton>

     



    Code behind

     

    if (IsAutomationEnabled)

     

    {

    btnPlayStop.ToggleStates[1].Selected =

    false;

     

    btnPlayStop.ToggleStates[0].Selected =

    true;

     

    }

    else

    {

    btnPlayStop.ToggleStates[1].Selected =

    true;

     

    btnPlayStop.ToggleStates[0].Selected =

    false;

     

     

    }


    Even though it goes into the correct loop on debugging , always togglestate[1] is selected on page load. Please help

    Thanks an dRegards,
    Vaneeth
  2. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 21 Sep 2012 Link to this post

    Hi Vaneeth,

    The Selected property of a RadButtonToggleState determines which state will be enabled when the button's property Checked is set to true. For example, if you want the Play state to be checked when the page is loaded, you should configure
    btnPlayStop.ToggleStates[1].Selected = true;
    and the Checked property should be set to true
    <telerik:RadButton ID="btnPlayStop" runat="server" ButtonType="ToggleButton" ToggleType="CheckBox"
        Width="30px" Height="30px" AutoPostBack="true" ForeColor="Black" Checked="true">
        <ToggleStates>
            <telerik:RadButtonToggleState Text="Stop" />
            <telerik:RadButtonToggleState Text="Play" />
        </ToggleStates>
    </telerik:RadButton>


    All the best,
    Slav
    the Telerik team
    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. Ruby
    Ruby avatar
    23 posts
    Member since:
    Mar 2012

    Posted 08 May 2013 Link to this post

     

    Hello, I am having a similar issue. I created a rad button with tooglestate 
    which changes state based on value from the database.<BR>Please see my attached 
    code. The state is always set to the first value even after database state has 
    been changed
      
       <telerik:RadButton ID="uxrbtnActiveState" runat="server" ButtonType="ToggleButton" ToggleType="CustomToggle"  Width="75px" CssClass="togglebtn"   Enabled="false"  >
                                <ToggleStates>
                                    <telerik:RadButtonToggleState Text="Active" CssClass="greenbkgd"  Value="1"  />
                                    <telerik:RadButtonToggleState Text="Deleted" CssClass="redbkgd"  Value="0"/>
                                </ToggleStates>
                            </telerik:RadButton>
    uxrbtnActiveState.SelectedToggleState.Value = IIf(dr.Item("active_employee").ToString = "Y", 1, 0)
    while uxrbtnActiveState.ToggleStates(0).Selected=true   is not working

    The value is pulled correctly but the state is not changing on the page at all. It is always set to "Active".

    Any help would be appreciated.

    Thanks
  5. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1493 posts

    Posted 13 May 2013 Link to this post

    Hello,

    I have tried to reproduce your issue but to no avail. You can watch a short video with the test in the attached archive and then notify me what I am missing.

    Could you please, try to reproduce the unexpected behavior with the VS example located in the attached archive and then tell us what changes you have made, so that we can proceed further with the investigation?

    Kind regards,
    Danail Vasilev
    the Telerik team
    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.
  6. Ruby
    Ruby avatar
    23 posts
    Member since:
    Mar 2012

    Posted 13 May 2013 Link to this post

    The issue has been resolved- I changed the tooglestates value and set the first one to 0 and second one to 1.

     

     

    <telerik:RadButton ID="uxrbtnActiveState" runat="server" ButtonType="ToggleButton" ToggleType="CustomToggle" Width="75px" CssClass="togglebtn" Enabled="false" >

     

     

     

    <ToggleStates>

     

     

     

    <telerik:RadButtonToggleState Text="Active" CssClass="greenbkgd" Value="0" />

     

     

     

    <telerik:RadButtonToggleState Text="Deleted" CssClass="redbkgd" Value="1"/>

     

     

     

    </ToggleStates>

     

     

     

    </telerik:RadButton>

    In the vb file my code works like this:

     

    uxrbtnActiveState.SelectedToggleState.Value = IIf(dr.Item(

     

    "active_employee").ToString = "Y", 0, 1)

     

    uxrbtnActiveState.ToggleStates(uxrbtnActiveState.SelectedToggleState.Value).Selected =

     

    True


    Thanks for your help!

     

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017