ASP.NET nested control scrolling when focus is set - asp.net

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.

Related

Firefox not displaying panel on refresh or postback

I have a curious issue. I have an ASP.NET web page that has a RadioButtonList with three RadioButtons. RadioButton1 hides both Panels. RadioButton2 displays Panel1 and hides Panel2 then RadioButton3 hides Panel1 and displays Panel2. Pretty straight forward. All of the logic that hide and display the Panels is in C# in the Code Behind. All of this works great in Chrome and IE. In Firefox; however, if you refresh the page in any way (another controls posts back or by hitting the browser's refresh button) while say RadioButton2 is selected and Panel1 is displayed the page comes back with the RadioButton2 still selected but both Panels are now hidden. In Chrome and IE a refresh of the page brings it back to it's original state. Meaning that all of the controls are set to their original values and RadioButton1 is selected and both Panels are hidden. Not necessarily ideal but a whole lot better than having the RadioButtons and Panels come back out of sync.
Not sure where to begin looking on this one. None of this is done in JavaScript. The panels and RadioButtons are not generated in code behind they are in the static HTML portion of the page.
Thoughts?
This sounds like you might be dealing with a page caching issue in Firefox. Have you tried disabling page caching for this page? For example, see this answer: Disable caching in Fire Fox in ASP.NET and C#
This is not really the answer I was hoping for because it seems incomprehensible to me that in 2014 we still have issues with browser inconsistencies but I put some code in the page to handle this and force it back into the proper state. This has solved the immediate problem.

Focus Jumps to Address

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!

How to save the listitems being added at client side when click the brower's back button?

I have two ListBoxes, left one and right one, and two Buttons in between Add and Remove. I wrote javascript function for Add/Remove to add selected items from left ListBox to the right ListBox. After submit the page, I click the Back Button in the browser, the items in the right ListBox are gone. I think the reason is probably because those items were added at the client side, server didn't know. It there anyway I could save those items so that when I click the Back button, they are still inad the ListBox?
I don't want to make the Add/Remove do a postback, since loading the page takes a while. I tried to put them in a updatepanel, but not working.
Update: I put the right ListBox in an UpdatePanel, and make the Add/Remove button PostBackTrigger, it worked. But this way caused a whole page postback? Why do I need UpdatePanel then? If I make the Add/Remove AsyncPostBackTrigger, it only caused partially postback, but when I clicked the Back button, my selection was gone. Any suggestion?
As per my knowledge, you cannot handle the browser "Back" button. You can disable the Back button instead in order to avoid the situation.
Could the jQuery BBQ: Back Button & Query Library solve your problem perhaps?

asp.net login layout and positioning

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!

Mulitple Modal Popups not working in IE 7

I have two modal popups on a page, both inside user controls, and both have different names, and different behavior id's. Also, the hidden buttons used with them have different id's. I use javascript to click those buttons to show the popup.
On load of the page, the first popup is hidden, but the second one is not, and is at the bottom of the page completely visible. When I click the link that is supposed to show the second popup, the first one is shown instead, but the javascript to load the default values into the first popup does not run, so I'm confused as to what is going on. Any ideas?
I have solved the issue. My situation is bit different. for you both pop ups are in a user control. But for me only one is in user control and other one is in the page itself. hope this will shed some light on your issue.
I gave different id's for
Hidden Target button (TargetControlID)
OK button (OkControlID)
Popup Panel (pnlPopup)
Model Popup control
Still if you are not sure, try your page in firefox with firebug installed. This will help you to identify any java-script errors.
Hope this helps.

Resources