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

RadButton with ToggleType="Radio" won't checked correct one from code behind

5 Answers 289 Views
Button
This is a migrated thread and some comments may be shown as answers.
Sam
Top achievements
Rank 1
Sam asked on 14 Jan 2014, 06:15 PM
<telerik:RadButton runat="server" ID="RadButton1" ButtonType="StandardButton" ToggleType="Radio" GroupName="Group1" AutoPostBack="true">
                                        <ToggleStates>
                                            <telerik:RadButtonToggleState Text="Low Rate" PrimaryIconCssClass="rbToggleRadioChecked"></telerik:RadButtonToggleState>
                                            <telerik:RadButtonToggleState Text="Low Rate" PrimaryIconCssClass="rbToggleRadio"></telerik:RadButtonToggleState>
                                        </ToggleStates>
                                    </telerik:RadButton>
 
                                    <telerik:RadButton runat="server" ID="RadButton2" ButtonType="StandardButton" ToggleType="Radio" GroupName="Group1" AutoPostBack="true">
                                        <ToggleStates>
                                            <telerik:RadButtonToggleState Text="High Rate" PrimaryIconCssClass="rbToggleRadioChecked"></telerik:RadButtonToggleState>
                                            <telerik:RadButtonToggleState Text="High Rate" PrimaryIconCssClass="rbToggleRadio"></telerik:RadButtonToggleState>
                                        </ToggleStates>
                                    </telerik:RadButton>
protected void Page_Load(object sender, EventArgs e)
       {
               RadButton1.Checked = true;
           RadButton2.Checked = true;
       }

Can anyone tell me why RadButton2 not checked, but RadButton1 is checked?

Thanks,
-Sam

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 Jan 2014, 03:29 AM
Hi Sam,

In your code snippet both RadButton have the same GroupName 'Group1'. When two or more RadioButtons have the same GroupName, a user can only select one RadioButton at a time. So please try the following code snippet to check both RadioButton on PageLoad.

ASPX:
<telerik:RadButton runat="server" ID="RadButton1" ButtonType="StandardButton" ToggleType="Radio"
    GroupName="Group1" AutoPostBack="true">
    <ToggleStates>
        <telerik:RadButtonToggleState Text="Low Rate" PrimaryIconCssClass="rbToggleRadioChecked">
        </telerik:RadButtonToggleState>
        <telerik:RadButtonToggleState Text="Low Rate" PrimaryIconCssClass="rbToggleRadio">
        </telerik:RadButtonToggleState>
    </ToggleStates>
</telerik:RadButton>
<telerik:RadButton runat="server" ID="RadButton2" ButtonType="StandardButton" ToggleType="Radio"
    GroupName="Group2" AutoPostBack="true">
    <ToggleStates>
        <telerik:RadButtonToggleState Text="High Rate" PrimaryIconCssClass="rbToggleRadioChecked">
        </telerik:RadButtonToggleState>
        <telerik:RadButtonToggleState Text="High Rate" PrimaryIconCssClass="rbToggleRadio">
        </telerik:RadButtonToggleState>
    </ToggleStates>
</telerik:RadButton>

Thanks,
Princy.

0
Sam
Top achievements
Rank 1
answered on 15 Jan 2014, 03:38 AM
I thought it should select whatever last code run
 Like asp.net RadioButtonList does select whatever last line of code run

Thanks for your help
-sam
0
Danail Vasilev
Telerik team
answered on 17 Jan 2014, 08:59 AM
Hello Sam,

I have tried to reproduce the mentioned issue but to no avail - the second RadButton gets always checked as this is the last operation in the page_load method.

Could you please confirm that you have the latest official version of RadControls - 2013.3.1114 and if not does upgrading to it resolve the issue?

If the above steps is not helpful I can suggest that you try to reproduce the issue with the attached VS example and then tell us what changes you have made so that we can make an examination 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 the blog feed now.
0
Sam
Top achievements
Rank 1
answered on 22 Jan 2014, 01:24 PM
Hello Danail,

I have downloaded your sample and tried. it does checked the last operation in the page_load method.

One thing I realized that they not act like a radio button, they toggle on/off like a checkbox.  What do I missed? Here is the code below:
<telerik:RadButton runat="server" ID="RadButton1" ButtonType="StandardButton" ToggleType="Radio"
                                            GroupName="Group1" AutoPostBack="true" OnCheckedChanged="rblMeals_SelectedIndexChanged">
                                            <ToggleStates>
                                                <telerik:RadButtonToggleState Text="Low Rate" PrimaryIconCssClass="rbToggleRadioChecked"></telerik:RadButtonToggleState>
                                                <telerik:RadButtonToggleState Text="Low Rate" PrimaryIconCssClass="rbToggleRadio"></telerik:RadButtonToggleState>
                                            </ToggleStates>
                                        </telerik:RadButton>
 
                                        <telerik:RadButton runat="server" ID="RadButton2" ButtonType="LinkButton" ToggleType="Radio"
                                            GroupName="Group1" AutoPostBack="true" OnCheckedChanged="rblMeals_SelectedIndexChanged">
                                            <ToggleStates>
                                                <telerik:RadButtonToggleState Text="High Rate" PrimaryIconCssClass="rbToggleRadioChecked"></telerik:RadButtonToggleState>
                                                <telerik:RadButtonToggleState Text="High Rate" PrimaryIconCssClass="rbToggleRadio"></telerik:RadButtonToggleState>
                                            </ToggleStates>
                                        </telerik:RadButton>

The difference from your sample are I used AutoPostBack="True" and OnCheckedChanged

And I am using version: 2013.3.1114.40

Thank you,
-Sam
0
Danail Vasilev
Telerik team
answered on 23 Jan 2014, 03:19 PM
Hi Sam,

Could you please elaborate more into the actual and the expected behavior of the RadButton? By the phrase "they toggle on/off like a checkbox" do you mean that the states of the RadButtons are one and the same when they are clicked?

If that is so and you are setting the checked property of some of the buttons in Page_Load , then this behavior is expected - the last state set in the Page_Load will be preserved. In order to handle that you can either remove this configuration in the code behind or execute it only in the first page load. For example:
C#:
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        RadButton1.Checked = true;
        RadButton2.Checked = true;
    }
}
protected void rblMeals_SelectedIndexChanged(object sender, EventArgs e)
{
 
}
ASPX:
<telerik:RadButton runat="server" ID="RadButton1" ButtonType="StandardButton" ToggleType="Radio"
    GroupName="Group1" AutoPostBack="true" OnCheckedChanged="rblMeals_SelectedIndexChanged">
    <ToggleStates>
        <telerik:RadButtonToggleState Text="Low Rate" PrimaryIconCssClass="rbToggleRadioChecked"></telerik:RadButtonToggleState>
        <telerik:RadButtonToggleState Text="Low Rate" PrimaryIconCssClass="rbToggleRadio"></telerik:RadButtonToggleState>
    </ToggleStates>
</telerik:RadButton>
 
<telerik:RadButton runat="server" ID="RadButton2" ButtonType="LinkButton" ToggleType="Radio"
    GroupName="Group1" AutoPostBack="true" OnCheckedChanged="rblMeals_SelectedIndexChanged">
    <ToggleStates>
        <telerik:RadButtonToggleState Text="High Rate" PrimaryIconCssClass="rbToggleRadioChecked"></telerik:RadButtonToggleState>
        <telerik:RadButtonToggleState Text="High Rate" PrimaryIconCssClass="rbToggleRadio"></telerik:RadButtonToggleState>
    </ToggleStates>
</telerik:RadButton>


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 the blog feed now.
Tags
Button
Asked by
Sam
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sam
Top achievements
Rank 1
Danail Vasilev
Telerik team
Share this question
or