ASP.NET - Set Visible Radiobuttonlist on Radcombobox change event
Asked By goldy gupta on 27-Jun-12 07:50 AM
I have Radcombobox
<telerik:RadComboBox ID="RadYear" MarkFirstMatch="true" AllowCustomText="true" EmptyMessage="Select Year"
Skin="Metro" runat="server" DataTextField="ass_year" DataValueField="id" DataSourceID="SqlDataSource1" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged">
</telerik:RadComboBox>
On Client changed i am doing like this
function OnClientSelectedIndexChanged() {
document.getElementsByName("<%=RadioButtonList1.ClientID%>").style.visibility = 'visible';
}
I have Radiobuttonlist whose deafult visibility is False i want to make it true on selection changed of Radcombobox
<asp:RadioButtonList name="RadioButtonList1" ID="RadioButtonList1" runat="server" Visible="true" AutoPostBack="True"
RepeatDirection="Horizontal">
<asp:ListItem Text="Girls" Selected="True" Value="Girls"></asp:ListItem>
<asp:ListItem Text="Boys" Value="Boys"></asp:ListItem>
</asp:RadioButtonList>
But i am not able to find control of radiobuton list through javascript
TSN ... replied to goldy gupta on 27-Jun-12 08:56 AM
hi...
you can have a small change in the code using the Jquery,in Jquery we have built in fuction which helps in hiding and showing the Controls
here is the code
function OnClientSelectedIndexChanged() {
var rbl = $("#<%= RadioButtonList1.ClientID %>");
rbl.Show(); // which makes the visibile = true for the control
}
you can use .Hide() to hide the control
Vikram Singh Saini replied to goldy gupta on 27-Jun-12 09:47 AM
Asp.net controls that are marked visible false are not rendered in page output. You can check the source code of the rendered page. There would be no control as Radiobuttonlist.
Modify your radiobuttonlist as:
<asp:RadioButtonList name="RadioButtonList1" ID="RadioButtonList1" runat="server" AutoPostBack="True"
RepeatDirection="Horizontal" CssClass="hidden">
<asp:ListItem Text="Girls" Selected="True" Value="Girls"></asp:ListItem>
<asp:ListItem Text="Boys" Value="Boys"></asp:ListItem>
</asp:RadioButtonList>
Note: We have removed the attribute Visible. And added CssClass.
Here is the css class hidden declaration:
.hidden
{
visibility:hidden;
}
This will make radiobuttonlist to render in output but it would be hidden. The rest of code is fine and work smoothly. Let us know back the action result.