ReadOnly RadNumericTextBox not firing OnFocus()

9 posts, 1 answers
  1. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 27 Nov 2011 Link to this post

    Hello,

    When I set ReadOnly=true on a RadNumericTextBox via markup, the client event OnFocus() does not fire.
    <telerik:RadNumericTextBox CssClass="FarmSerialNumber" ID="rntbAcreageFarmSerialNumber"
        runat="server" Width="40px" Value='<%# DoubleFromDb(Eval("FarmSerialNumber"), true) %>'
        ReadOnly='<%# DoubleFromDb(Eval("FarmSerialNumber"), true) != null %>' MinValue="1">
        <NumberFormat DecimalDigits="0" GroupSeparator="" />
        <IncrementSettings InterceptMouseWheel="false" />
        <ReadOnlyStyle ForeColor="Gray"></ReadOnlyStyle>
        <ClientEvents OnValueChanged="radNumericTextBox_ClientValueChanged" OnFocus="acreageControl_ClientFocus" />
    </telerik:RadNumericTextBox>

    The documentation does not mention that this doesn't fire when it is readonly.
    http://www.telerik.com/help/aspnet-ajax/input-client-side-onfocus.html

    To ensure that this is not a problem with the <input> element, I added this and it works fine.
    <input type="text" onfocus="alert('Yup.  Works')" readonly="readonly" />

    Is this a bug or by design?

    Thanks!
    Thad
  2. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 28 Nov 2011 Link to this post

    Hello Thad,

    By design focus and blur client events are not fired when the Input is ReadOnly.

    All the best,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 28 Nov 2011 Link to this post

    Hi Vasil,

    I would highly suggest reconsidering this design decision.  This is not a limitation of the html INPUT or asp.net TextBox control, so it should not be a limitation of the RadInput control.  I can come up with many perfectly valid reasons why someone would want JavaScript code to fire off when a ReadOnly control gets focus.

    Unfortunately, it sounds like the only workaround I have is to have two controls instead of one and display a readonly asp:textbox if there is a value already entered and display the telerik:radnumerictextbox if no value has been entered. 

    Thad
  5. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 28 Nov 2011 Link to this post

    Hi Vasil,

    I would highly suggest reconsidering this design decision.  This is not a limitation of the html INPUT or asp.net TextBox control, so it should not be a limitation of the RadInput control.  I can come up with many perfectly valid reasons why someone would want JavaScript code to fire off when a ReadOnly control gets focus.

    Unfortunately, it sounds like the only workaround I have is to have two controls instead of one and display a readonly asp:textbox if there is a value already entered and display the telerik:radnumerictextbox if no value has been entered. 

    Thad
  6. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 28 Nov 2011 Link to this post

    Hi Vasil,

    I would highly suggest reconsidering this design decision.  This is not a limitation of the html INPUT or asp.net TextBox control, so it should not be a limitation of the RadInput control.  I can come up with many perfectly valid reasons why someone would want JavaScript code to fire off when a ReadOnly control gets focus.

    Unfortunately, it sounds like the only workaround I have is to have two controls instead of one and display a readonly asp textbox if there is a value already entered and display the telerik radnumerictextbox if no value has been entered. 

    Thad
  7. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 28 Nov 2011 Link to this post

    Um, I keep getting an "Oops..." message when posting a reply, but it's posting anyway.  Sorry for the multiple posts.
  8. Answer
    Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 30 Nov 2011 Link to this post

    Hello Thad,

    The design is such because the control is actually not in focus, you see that it's styling remain ReadOnly, and its value is the display value and so on.

    However you see the cursor because the visible HTML input is focused. If you want to check if it is visible you could attach a handler to the onfocus DOM event of the visible input element.
    For example this code should work for you:
    <script type="text/javascript">
      function focused(sender, e)
      {
        alert("focused");
      }
    </script>
    <telerik:RadTextBox runat="server" onfocus="focused(this,event)" ReadOnly="true">
    </telerik:RadTextBox>


    Best wishes,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
  9. Thad
    Thad avatar
    106 posts
    Member since:
    Sep 2010

    Posted 01 Dec 2011 Link to this post

    Hi Vasil,

    That is a very acceptable workaround.  Thank you!

    Is it possible to at least add a note into the documentation regarding the fact that the control differs from the base controls?  Or a sample into the troubleshooting/application scenarios?  That would be very useful.

    Thanks!
    Thad
  10. Vasil
    Admin
    Vasil avatar
    1547 posts

    Posted 02 Dec 2011 Link to this post

    Hi Thad,

    Thank you for the suggestion, we added a note in the events section of the help about the Input, It will be visible after the next upload of the site.

    Best wishes,
    Vasil
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017