Developing Matt

My Technical Journal

i’m…losing…focus…

with 2 comments

In visual studio 2003 (with asp.net 1.3) focus was a real problem. If you set focus on something that was invisible, or set something invisible that had focus the program crashed. This is all fixed in asp.net 2.0 so you can again support your lazy programming style. Put don’t kick back the foot rest just yet. If your client is using IE 6.0 or earlier I would still stay away from it. The strange behavior is that if they click on the control that should have focus, it won’t… your focus will be in the address bar, which is what Microsoft apparently ended up doing for focus that they didn’t know what else to do with. My ‘solution’ ended up being giving up on setting focus to anything BUT a constantly visible control.

Advertisements

Written by matt

August 6, 2007 at 2:53 pm

Posted in Asp.net, javascript

2 Responses

Subscribe to comments with RSS.

  1. Saw this, thought you might be interested:

    Private Sub SetFocus(ByVal ctrl As Control)
    ‘ Define the JavaScript function for the specified control.
    Dim focusScript As String = “” & _
    “document.getElementById(‘” + ctrl.ClientID & _
    “‘).focus();”

    ‘ Add the JavaScript code to the page.
    Page.RegisterStartupScript(“FocusScript”, focusScript)
    End Sub

    You can now call the custom SetFocus() function from any event handler to change the control focus as needed:
    SetFocus(myTextBox)

    http://www.ondotnet.com/pub/a/dotnet/2003/09/15/aspnet.html

    Cog

    August 28, 2007 at 1:47 pm

  2. here’s another javascript focus command. in the body of the html
    onLoad=”self.focus();document.form1.ELEMENT_NAME.focus()”

    matt

    September 7, 2007 at 6:50 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: