I am working on an ASP.NET 2.0 (VB) web application. I am having trouble controlling tab behavior.
TabIndex is set throughout the form and tabs as expected.
But,after making a change in a textbox and hitting Tab or Enter, the focus jumps to the web address bar instead of the next field.
I have tried:
1.SetFocus on the text change event
2.Saving last field name in a hidden textbox and set focus to saved textbox name on Page Load if Post back
3.SetFocus on Pre_render
Still, focus jumps to browser address bar on tab or enter.
I think it may be losing the tab index on post-back.
Any clues?
Thanks in advance, any help is appreciated
When you have AutoPostBack on a TextBox control with TabIndex assigned it could be a little complex to manipulate the Focus. Check out this tutorial which will show you a little trick to Shift Focus to the next control.
Good luck!
Related
I am trying a very simple thing. I have 3 textboxes and 3 labels. On text change i am setting the content of label.
The issue is when i insert some value in 1st textbox(e.g 50) change the focus to another textbox the values in label is reflected perfectly.
But the focus which i setted on 2nd textbox is lost. And the focus is lost somewhere.
I need to click again on 2nd textbox to get focus.
The same issue is reproduced if TAB is clicked to change focus.
I have made a small demo project for the same and attached. You can avail that from the below link
https://skydrive.live.com/redir?resid=A716D678775EEF95!115&authkey=!ABp6kAon_ZNDLBU
Please someone help me...what am i doing wrong??
Thanks in advance...
This is a rather common issue in ASP.NET, as described here: http://www.codeproject.com/Articles/17571/Maintain-focus-between-postbacks-in-ASP-NET-2-0-al or here: How do I maintain focus position in UpdatePanel after page partial post back. Those links also contain some suggestion on how to solve this issue.
One of the possible solutions is to keep track of control with focus, put information about it into a hidden field and manually restore the focus after postback. This method is described in the first link mentioned.
I have a nested control within a master page. When I explicitly set the focus on the first textbox on this control, the page shifts up to this first textbox. Is there a way to prevent the page from jumping up but still set the focus so the user doesn't have to click into the textbox? I want them to be able to start typing right when the page displays.
I think this is a browser setting, as it works automatic:
http://jsfiddle.net/KjCuM/
You could put a fix in place to then scroll back to the top of the page perhaps, but I think it makes sense for the control to be viewable on the screen if there is focus on it. Otherwise the user will not be able to see what they are submitting.
I'm using asp.net's login control; two textboxes with the labels on the left and a button beneath (the control renders as a table with 3 rows). When the user enters an incorrect login, the page is posted back and the failure text "incorrect login" is displayed by adding a row between the password textbox and the button.
The problem is that when the failure text is displayed, the new row that's inserted shifts the button down slightly.
It looks odd and off. How can I rearrange this so that when the failure text appears it doesn't shift the login button.
Thanks for your suggestions.
Check out the documentation for the Login control.
Assuming there isn't CSS or markup on the page causing the shifting, you should be able to control the style of the failure text via FailureTextStyle property.
Ok, if anyone gets to this page because of a layout problem with the login control, it's actually pretty easy to solve. By default, the control renders as a table and there's nothing you can do to change the layout of the default control because you don't have access to the HTML.
You need to switch the page to design mode and on the control, click "Convert to Template". When you go back to the source page, the HTML becomes accessible and you can see the HTML of the table that contains the various asp controls. Yank the table and put the control inside divs that you control!
I am unfortunately having to work with asp.net web forms. I have a label that has a different Text property every time the page loads. I have a button that is clicked. I have double clicked on the button and it has shown me a code view.
I get a reference to the label via labelID.Text, but it refers to the value of the text that is about to be displayed on the next page load. How would I get the text of the value when the button was actually clicked? Or is web forms not advanced enough for that.
Search where the labelID.Text is modified (maybe Page_Load event), and save the text before in a global variable.
It sounds like on every page load or postback, somewhere there is code which applies a new value to labelID.Text. Where is that work being done? Page_Load?
In any case, wherever that work is being done, you most likely have access to both the existing text value of the control, and the new text value you're about to give it.
I have a text box which I have extended with the AJAX Control Toolkit CalendarExtender. When I click on the text box, a calendar appears and I can select a date which then is added to the text box. So far so good.
This text box is used on a Grid View to filter the results in it. This was setup when I added a data source to the grid view.
This works fine other than the fact that after selecting the date in the date control, I then also have to hit enter in the text box for the grid view to update. Can I get to update as soon as the date is selected rather than having to press enter?
This is because the TextBox_TextChanged event is not being raised. This can only be raised when focus is taken off the textbox, and since focus was put on it, the text has changed.
One option would be to use jQuery to force a postback whenever text is changed in the textbox.
Something like:
$("input.textbox").change(function(){
__doPostBack();
});
This article may be of use for forcing Post Back from javascript:
http://weblogs.asp.net/yousefjadallah/archive/2010/06/27/insure-that-dopostback-function-implemented-on-the-page.aspx
If you want to refresh your grid without pressing the Enter key,
put your textbox's autopostback property to true.
Hope this helps.