Search code examples
c#asp.netradiobuttonlist

how to disable asp:radiobutton list via c#?


Please find below my code:

Please find below my aspx code:

<asp:RadioButtonList ID="rblCreateEvent" CssClass="eventdiv_spacing label" runat="server" Height="8px" Width="105px" RepeatDirection="Horizontal" onMouseUp="SelectEvent()" onClick="transportEnable();javascript:CheckEvent();">
    <asp:ListItem Value="0">Past</asp:ListItem>
    <asp:ListItem Value="1">Future</asp:ListItem>
</asp:RadioButtonList>

I want to disable it completely in server side so that user click on it should not call it's javascript functions.

I however achieved it by following server side code:

this.rblCreateEvent.Enabled = false;

It did disable my radio button list and grayed it out. Javascript functions dont get called, if I exactly click on radio buttons. However javascript functions get called, if I click on radio buttons text(for ex: here its 'Past' and 'Future').I want to disable this click as well in server side code.

So Ideally what I want is how to disable asp:radiobutton text click in server side?

I would appreciate any answers or comments. Thanks in advance!!!


Solution

  • Strange behaviour, but this seems to do the trick:

    this.rblCreateEvent.Enabled = false;
    this.rblCreateEvent.Attributes.Remove("onClick");