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

6 posts, 0 answers
  1. Sam
    Sam avatar
    27 posts
    Member since:
    Sep 2013

    Posted 14 Jan 2014 Link to this post

    <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
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 14 Jan 2014 Link to this post

    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.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sam
    Sam avatar
    27 posts
    Member since:
    Sep 2013

    Posted 14 Jan 2014 Link to this post

    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
  5. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 17 Jan 2014 Link to this post

    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.
  6. Sam
    Sam avatar
    27 posts
    Member since:
    Sep 2013

    Posted 22 Jan 2014 Link to this post

    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
  7. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 23 Jan 2014 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017