Radiobutton group

5 posts, 1 answers
  1. Lovella Bacaud
    Lovella Bacaud avatar
    20 posts
    Member since:
    Apr 2013

    Posted 23 Jul 2013 Link to this post

    Hi

    I want to create a radiobutton group in telerik and get the selected item. 

    Thanks
    Lovella
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 Jul 2013 Link to this post

    Hi

    Please have a look into the following code I tried which works fine at my end.

    ASPX:
    <telerik:RadButton ID="RadButton1" runat="server" GroupName="PostingType" OnClientClicked="OnClientClicked"
        ToggleType="Radio" ButtonType="ToggleButton" Text="Option1">
    </telerik:RadButton>
    <telerik:RadButton ID="RadButton2" runat="server" GroupName="PostingType" OnClientClicked="OnClientClicked"
        ToggleType="Radio" ButtonType="ToggleButton" Text="Option2">
    </telerik:RadButton>

    JavaScript:
    <script type="text/javascript">
        function OnClientClicked(sender, args) {
            var selectedoption = sender.get_text();
        }
    </script>

    Thanks,
    Shinu.
  3. rdmptn
    rdmptn avatar
    72 posts
    Member since:
    Aug 2011

    Posted 23 Jul 2013 Link to this post

    Or just use normal radio button groups and work with them as you would without RadControls (e.g. RadioButtonList) and add a RadFormDecorator to style them nicely.
  4. Lovella Bacaud
    Lovella Bacaud avatar
    20 posts
    Member since:
    Apr 2013

    Posted 23 Jul 2013 Link to this post

    Hi shinu. The sample you provided works fine. Please help me once more how can I pass the selected option to the server side code?
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 Jul 2013 Link to this post

    Hi,

    One option is you can add an ASP HiddenField and set its value as the selected radio button text from JavaScript and from the server side code you can access the HiddenField value which returns the selected radio button option. Please check the following sample code.

    ASPX:
    <telerik:RadButton ID="RadButton1" AutoPostBack="false" runat="server" GroupName="PostingType"
        OnClientClicked="OnClientClicked" ToggleType="Radio" ButtonType="ToggleButton"
        Text="Option1">
    </telerik:RadButton>
    <telerik:RadButton ID="RadButton2" AutoPostBack="false" runat="server" GroupName="PostingType"
        OnClientClicked="OnClientClicked" ToggleType="Radio" ButtonType="ToggleButton"
        Text="Option2">
    </telerik:RadButton>
    <asp:HiddenField ID="SelectedOption" runat="server" />
    <telerik:RadButton ID="RadButton3" runat="server" Text="Get Selected Otption" OnClick="RadButton3_Click">
    </telerik:RadButton>

    JavaScript:
    <script type="text/javascript">
        function OnClientClicked(sender, args) {
            var selectedoption = sender.get_text();
            //accessing the ASP HiddenField and setting its value
            document.getElementById("SelectedOption").value = selectedoption;
        }
    </script>

    C#:
    protected void RadButton3_Click(object sender, EventArgs e)
    {
        Response.Write("Selected Option is " + SelectedOption.Value);
    }

    Thanks,
    Shinu.
Back to Top