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

Problem with selected property of Toggle state

4 Answers 551 Views
Button
This is a migrated thread and some comments may be shown as answers.
Vaneeth
Top achievements
Rank 1
Vaneeth asked on 19 Sep 2012, 10:20 AM
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

4 Answers, 1 is accepted

Sort by
0
Slav
Telerik team
answered on 21 Sep 2012, 12:47 PM
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.
0
Ruby
Top achievements
Rank 1
answered on 08 May 2013, 06:23 PM

 

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
0
Danail Vasilev
Telerik team
answered on 13 May 2013, 09:21 AM
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.
0
Ruby
Top achievements
Rank 1
answered on 13 May 2013, 01:40 PM
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!

 

Tags
Button
Asked by
Vaneeth
Top achievements
Rank 1
Answers by
Slav
Telerik team
Ruby
Top achievements
Rank 1
Danail Vasilev
Telerik team
Share this question
or