Tag: IE

IE7 and IE8 Control Focus issue on Page Load

I’m not sure why I didn’t figure this out sooner rather than later… Anyway, I thought I’d share this one with those of you who haven’t worked it out just yet. The title of this post is actually incorrect, but seeing as I have seen a lot of queries for the issue I’m about to explain, using IE7 and IE 8 as the name of the culprit, I thought I’d leave it at that.

The problem is when you want to set the focus to a specific control in ASP.NET on page load (or any other Page event for that matter), whether using client-side or server-side code, it just doesn’t work. Well, at least not all the time. The problem only arises when you use a ScriptManager control (I worked it out after quite a while), and the remedy is to use the SetFocus method of the ScriptManager control. Works all the time…

ScriptManager1.SetFocus("TextBox1")
Advertisements