This is a migrated thread and some comments may be shown as answers.

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

5 Answers 40 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Sameer
Top achievements
Rank 1
Sameer asked on 21 Feb 2013, 05:02 PM
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

5 Answers, 1 is accepted

Sort by
0
MasterChiefMasterChef
Top achievements
Rank 2
answered on 21 Feb 2013, 08:59 PM
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
0
Sameer
Top achievements
Rank 1
answered on 22 Feb 2013, 02:04 PM
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
0
Eyup
Telerik team
answered on 27 Feb 2013, 01:24 PM
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.
0
Sameer
Top achievements
Rank 1
answered on 05 Mar 2013, 04:00 PM
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
0
Eyup
Telerik team
answered on 07 Mar 2013, 01:15 PM
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.
Tags
Ajax
Asked by
Sameer
Top achievements
Rank 1
Answers by
MasterChiefMasterChef
Top achievements
Rank 2
Sameer
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or