Question

Code

<asp:RadioButtonList ID="rdStatus" onclick="javacript:display();" runat="server" RepeatDirection="Vertical">
<asp:ListItem Text="Temporary Waiver" Value="T" Selected="True"></asp:ListItem>    
<asp:ListItem Text="Never Expires" Value="P"></asp:ListItem>    
<asp:ListItem Text="Expires after the close of:" Value="W"></asp:ListItem>
</asp:RadioButtonList>

My Problem:

  • during run this code html table is created for radio button list and on click event is placed on table.
  • even i disable the radiobutton list , the click event is occur. I need to avoid this issue . Please suggest some ideas.
Was it helpful?

Solution

On disable radio buttons add class as "disabled" to radio buttons & better way to use jQuery insted of javascript as bellow

jQuery("#rdStatus").click(function()`{  

    if(jQuery(this).hasClass("disabled"))
        return false;

    continue with you code here.............
}`);

OTHER TIPS

The code you wrote does exactly what you asked it to do: when the user clicks on the element, the function is run. There are two ways you can change it to get your desired efect:

  1. Use another event instead of onclick
  2. Stop the function execution

Another event

You might want to look towards the CHANGE event (https://developer.mozilla.org/en-US/docs/Web/Reference/Events/change)

Stop function

Inside the function you can check the state of your RadioButtonList. If it is disabled, you simply return; from the function instead of running the actual useful code. If you don't want to alter the original function, you can write a small wrapper that calls it only if the RadioButtonList is enabled and use the wrapper as handler for the 'click' event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top