0

I have an aspx form which contains couple of textboxes, dropdownlists and checkboxes on it. I have not set the default focus on any of the control. When I open this in IE it works fine. but when the page opens in chrome it set focus on a textbox which is not the first element of the DOM. and when the page opens in FireFox, it set focus on first textbox in the DOM.

I don't want focus on any of the control, how can I fix this issue.

yasii
  • 121
  • 8
  • Take a look here, should help you sort out your issue. http://stackoverflow.com/questions/1140250/how-to-remove-focus-from-a-textbox-in-c-winforms – SQLGuru Feb 13 '13 at 12:09

3 Answers3

0

Can you try document.getElementById('yourElement').blur();?

  • This would have to be done on a page-by-page basis (as the first element that gets focused may be different on different pages). It's not really a viable solution. – sevenseacat Feb 13 '13 at 12:48
  • The original question was for one page ("I have an aspx..."), it didn't seem to be a request for one-shot solution over number of different pages. – Boris Georgiev Feb 14 '13 at 09:22
0

Take look at these links: http://msdn.microsoft.com/en-us/library/ms178231(v=vs.100).aspx or http://msdn.microsoft.com/en-us/library/ms178232(v=vs.100).aspx

Maybe it can help you.

Try setting default focus on from in aspx like this:

<form id="form1" runat="server" defaultfocus="TextBox1" >
  <div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <br />
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <br />
  </div>
</form>

Post your code for more informations.

re: I think that you must have focus on at least one control on page. You can set dummy control like input and set it's opacity in css to 0 and set defaultfocus on it.

freshbm
  • 5,540
  • 5
  • 46
  • 75
  • I don't want focus on any of the control. – yasii Feb 13 '13 at 13:23
  • " ... When a page is rendered to the browser, the browser determines which control should have the focus. In most cases, the browser initially puts focus on the browser window itself or the first control on the page. This is true even after a postback, because the page is being re-created on the server and the browser considers it a new page. (An exception is after a postback caused by a TAB key, as explained earlier in the "Tab Order" section of this topic.) ..." I'v found that on this page: http://msdn.microsoft.com/en-us/library/ms178231(v=vs.100).aspx – freshbm Feb 13 '13 at 14:40
  • Thank you so much, I have fixed the issue, actually I am using Jquery AutoComplete and it has a property Autofocus which was causing the issue. – yasii Feb 13 '13 at 17:27
0

You could add autofocus = false;

<input type="text" name="second" id="second" "autofocus = false" />
defau1t
  • 10,593
  • 2
  • 35
  • 47