Usage of defaultbutton logic is resulting in moving to the top of the page on other control clicks.

6 posts, 0 answers
  1. Sameer
    Sameer avatar
    8 posts
    Member since:
    Mar 2011

    Posted 21 Feb 2013 Link to this post

    Hello Telerik team,

    After we enter text in a RadTextbox, pressing the Enter key is triggering click event of Submit button. In order to avoid this, we included below dummy button logic within the aspx page:

    <form id="frm" runat="server" defaultbutton="btnIgnore">
    <asp:Button ID="btnIgnore" runat="server" Style="Position:Absolute; Top:-200px" Text="Ignore" Width="90px" EnableViewState="False" OnClientClick="javascript:return false;" />

    This change resolved Enter key issue but the side effect has been with AJAX repost like radio button or dropdown click taking the display to the top of the page.

    Could you please let us know if you have a workaround for resolving this issue i.e., to keep the display at the same place instead of moving to the top?


    Regards,
    Sameer
  2. MasterChiefMasterChef
    MasterChiefMasterChef avatar
    152 posts
    Member since:
    Jan 2013

    Posted 21 Feb 2013 Link to this post

    Hi Sameer,

    You will likely need to provide more code in order for us to diagnose why your  RadTextBox is re positioning itself after each AJAX callback. If you are having trouble distinguishing between the button click and the enter key submit events, why not direct each event to the same function, that way pressing the submit button does the exact same thing as pressing the enter key.

    Hopefully this helps,
    Master Chief
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sameer
    Sameer avatar
    8 posts
    Member since:
    Mar 2011

    Posted 22 Feb 2013 Link to this post

    Hi,

    Thanks for the reply. The problem is not with repositioning of the RadTextbox. Our default.aspx page has multiple pages due to which scrollbar needs to be used to move from top to bottom of the  page. We tried using DefaultButton with a dummy button as mentioned earlier to avoid Submit button click which works fine. However, when we click any control (like radio button) on 3rd or 4th page which does a AJAX repost, it takes the display all the way back to the 1st page. This forces us to use the scroll-bar to go back to the radio button to continue entering data.

    Before introducing this DefaultButton logic, display remained at the same control with the same AJAX repost without moving to the top of the page. Hope this post explains the actual problem better.

    Would appreciate if you can let us know any workaround for this if possible. Thank you.

    Regards,
    Sameer
  5. Eyup
    Admin
    Eyup avatar
    3009 posts

    Posted 27 Feb 2013 Link to this post

    Hello Sameer,

    Please try the following approach:
    <form id="form1"... defaultfocus="HiddenFocusButton">
      <asp:Button ID="HiddenFocusButton" runat="server" Text="Button" Visible="false" />

    That should do the trick. Please give it a try and let me know if it works for you.

    Kind regards,
    Eyup
    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.
  6. Sameer
    Sameer avatar
    8 posts
    Member since:
    Mar 2011

    Posted 05 Mar 2013 Link to this post

    Hello Eyup,

    I tried below defaultfocus fix but unfortunately it didn't work either. Could you please let us know if any other work-around if possible?

    Regards,
    Sameer
  7. Eyup
    Admin
    Eyup avatar
    3009 posts

    Posted 07 Mar 2013 Link to this post

    Hi Sameer,

    Pleas note that if you are using a content page or user control, you will need to define the ID of the DefaultFocus programmatically since it needs the UniqueID of the button:
    http://msdn.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlform.defaultbutton.aspx
    ( Remarks section )

    Alternatively, you can save the scroll position to persist it on ajax requests:
    Copy Code
    <telerik:RadAjaxManager ...> 
      <ClientEvents OnRequestStart="requestStarted" OnResponseEnd="responseEnded" />
    JavaScript:
    Copy Code
    var scrollPosition = 0;
    function requestStarted(sender, args) {
        scrollPosition = $(document).scrollTop();
    }
    function responseEnded(sender, args) {
        setTimeout(function () {
            $(document).scrollTop(scrollPosition);
        }, 2)
    }

    Hope this helps. Please give it a try and let me know about the result.

    All the best,
    Eyup
    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