ASP:RadioButtonList OnFocus OnBlur does not work

Last post 08-07-2009 6:43 AM by y_srikanth. 5 replies.

Sort Posts:

  • ASP:RadioButtonList OnFocus OnBlur does not work

    06-12-2006, 5:49 PM
    • Member
      10 point Member
    • deprez
    • Member since 06-12-2006, 9:42 PM
    • Posts 2
    Hello all,
    I hope someone might know a little javascript and asp to help.

    In a nutshell, I have the following code :

    <asp:RadioButtonList id="list" runat="server" 
    onfocus="notifyFocusChange('list_0','list_1');" onblur="notifyFocusLost();" >

    <asp:ListItem Value="Y"
    onfocus="notifyFocusChange('list_0','list_1');" onblur="notifyFocusLost();" >Yes</asp:ListItem>

    <asp:ListItem Value="N"
    onfocus="notifyFocusChange('list_0','list_1');" onblur="notifyFocusLost();" >No</asp:ListItem>

    </asp:RadioButtonList>
     
    Visual studio 2005 outputs the list events in a TABLE tag
    and the listItem events in a SPAN tag.
    I want them to end up on the INPUT tags so it will work correctly.

    If I use straight html inputs to start with it is a no brainer and works fine. However, I have lots of yes/no questions in 25+ forms and want the focus/blur events to work from asp controls so that I can easily update values on postbacks etc.

    Ideally, I want the onfocus/onblur to be only in the asp:radiobuttonlist tag.

    Please help.
    I can't find anything on the net for this problem.

    Thanks.
     




  • Re: ASP:RadioButtonList OnFocus OnBlur does not work

    06-12-2006, 10:02 PM
    • Member
      242 point Member
    • TonyBunce
    • Member since 10-29-2005, 4:48 AM
    • Posts 46
    Here is an artical about how to do it in 1.1
    http://aspnet.4guysfromrolla.com/articles/091405-1.aspx

    There might be some cool 2.0 way to do it, like a ControlAdapter but I'm not sure.

    You could also do some crazy javascript to loop through all the forum input controls and if it is part of your radio button list (the ID should somewhat match the ClientID of the list) then set the necessary properties.
    http://www.tonybunce.com
  • Re: ASP:RadioButtonList OnFocus OnBlur does not work

    06-13-2006, 9:37 AM
    • All-Star
      76,865 point All-Star
    • NC01
    • Member since 08-26-2005, 3:33 PM
    • Posts 14,327
    • TrustedFriends-MVPs

    Basically, here's how you'd have to write a client-side handler for a RadioButtonList. This one finds the checked item, but should get you started.

    <script language=JavaScript>
    <!--
    function isChecked(listControlId)
    {
     var tableBody = document.getElementById(listControlId).childNodes[0];

     for (var i=0;i<tableBody.childNodes.length; i++)
     {
      var currentTd = tableBody.childNodes[i].childNodes[0];
      var listControl = currentTd.childNodes[0];

      if ( listControl.checked )
       alert('Checked: ' + currentTd.childNodes[1].innerHTML);
     }
    }
    // -->
    </script>

    NC...

  • Re: ASP:RadioButtonList OnFocus OnBlur does not work

    06-13-2006, 6:06 PM
    • Member
      10 point Member
    • deprez
    • Member since 06-12-2006, 9:42 PM
    • Posts 2
    Thanks Tony and NC.

    Still don't think this is a good solution.

    In the mean time, I have found a simple solution without "asp:radiobuttonlist".

    I created a web user control with 2 inputs.
    On the page_load I use the Input1.Attributes.Add("onfocus"," javascript...")
    to stuff my javascript call with appropriate clientIDs.

    Thanks for your help.

    ps I hope they fix this problem in future versions.


  • Re: ASP:RadioButtonList OnFocus OnBlur does not work

    06-13-2006, 8:30 PM
    • All-Star
      76,865 point All-Star
    • NC01
    • Member since 08-26-2005, 3:33 PM
    • Posts 14,327
    • TrustedFriends-MVPs

    There is no "fix" for a problem like that, as the main problem is that AFAIK, there is no onfocus or onblur event fired for the HTML radiobutton element, which this object translates into.

    NC...

     

  • Re: ASP:RadioButtonList OnFocus OnBlur does not work

    08-07-2009, 6:43 AM
    • Member
      10 point Member
    • y_srikanth
    • Member since 05-12-2009, 12:26 AM
    • Mumbai
    • Posts 5

    Good job...

Page 1 of 1 (6 items)