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

Radiobutton group

4 Answers 1272 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Lovella Bacaud
Top achievements
Rank 1
Lovella Bacaud asked on 23 Jul 2013, 12:29 PM
Hi

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

Thanks
Lovella

4 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 23 Jul 2013, 12:40 PM
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.
0
rdmptn
Top achievements
Rank 1
answered on 23 Jul 2013, 01:16 PM
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.
0
Lovella Bacaud
Top achievements
Rank 1
answered on 23 Jul 2013, 05:19 PM
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?
0
Shinu
Top achievements
Rank 2
answered on 24 Jul 2013, 04:26 AM
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.
Tags
General Discussions
Asked by
Lovella Bacaud
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
rdmptn
Top achievements
Rank 1
Lovella Bacaud
Top achievements
Rank 1
Share this question
or