Seems something I came across a while ago. We had some problems similar to this on pages with only one input field, and thought it was a flaw in IE.
Anyway something like this: <Thomas/> > -----Original Message----- > From: Ken Schaefer [mailto:[EMAIL PROTECTED]] > Sent: 20. januar 2003 06:13 > To: dotnet > Subject: Re: A Saturday morning puzzle > > > What if you create wrap the code into a (clientside) > function, then call > this from the <body>'s onLoad() event? > > The only thing I can think of is that the javascript is somehow being > intepreted too early (I know you said that it's being written > to the same > place in the source...) > > Cheers > Ken > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > From: "Chris" <[EMAIL PROTECTED]> > Subject: A Saturday morning puzzle > > > To set a login webform's focus to the username input text > control on load, > the following code works fine in the form's Page_Load. > > Dim sb As StringBuilder = New StringBuilder() > sb.Append("<script > language='javascript'>document.getElementById('txtUserName').focus() > </script>") > RegisterStartupScript("Focus", sb.ToString) > > > However if the same code is wrapped in a static method in a > class in the web > project, it no longer works. > > > Public Shared Sub SetFocus(ByVal pg As Page, ByVal ctrl As > System.Web.UI.Control) > Dim sb As StringBuilder = New StringBuilder() > sb.Append("<script language='javascript'>document.getElementById('" & > ctrl.ID & "').focus() </script>") > pg.RegisterStartupScript("Focus", sb.ToString) > End Sub > > > When called like this from Page_Load: > > > myClass.SetFocus(Page, txtUserName) > > > the focus does not get set on the control. The interesting > thing is that > the page output (the HTML source viewed in the browser) is identical > whichever way this code is used. Both the method and the inline code > produce this: > > > <script > language='javascript'>Document.getElementById('txtUserName').focus() > </script> > > > in exactly the same place in the page's HTML in the browser. > > Is the explanation for this scientific or occult? > > > > --- > You are currently subscribed to dotnet as: [EMAIL PROTECTED] > To unsubscribe send a blank email to > %%email.unsub%% > > --------- > Administrated by 15 Seconds : http://www.15Seconds.com > List Archives/Search : http://local.15Seconds.com/search > Subscription Information : http://www.15seconds.com/listserv.htm > Advertising Information: http://www.internet.com/mediakit/ > > > --- You are currently subscribed to dotnet as: [email protected] To unsubscribe send a blank email to [EMAIL PROTECTED] --------- Administrated by 15 Seconds : http://www.15Seconds.com List Archives/Search : http://local.15Seconds.com/search Subscription Information : http://www.15seconds.com/listserv.htm Advertising Information: http://www.internet.com/mediakit/
