Peter Afonin
1/14/2003 6:43:00 PM
Tim,
I think your code is doing pretty much the same as this script:
<body bottomMargin="5" bgColor="darkcyan" topMargin="5"
onload="document.Form1.txtStart.focus();" rightMargin="0"
MS_POSITIONING="GridLayout">
i.e. set focus to the control on startup.
This is not what I expect. When user opens a form for data entry, he wants
to have a focus on the first textbox. Then he tabs through the textboxes,
fills out the form, and sets the focus on the button, so when he press Enter
the data is entered. And, unfortunately, unless this button is the first on
the form, I cannot set a focus on it.
Alternatively, I can have a button that is always a default, but, again,
unless it's a first button on the form, there is nothing I can do.
Thank you,
Peter
"Tim Hollingsworth" <timh@lasata.com.au> wrote in message
news:edYFhK5uCHA.440@TK2MSFTNGP12...
> Hi Peter
>
> ok so you have server side 'Button1' and 'Button2' contained in an HTML
form
> 'form1'. To set the focus to Button2, add this code to your Page_Load
> class:
> [C#]
>
> RegisterStartupScript("focus", "<script language=\"JavaScript\">\n\t" +
>
> "form1." + Button2.ClientID + ".focus();\n\t"
>
> + "<" + "/script>");
>
> [VB]
>
> RegisterStartupScript("focus", "<script language=""JavaScript"">" & vbCrLf
&
> _
>
> vbTab & "form1." & Button2.ClientID & ".focus();" & _
>
> vbCrLf & "<" & "/script>")
>
> cheers
> Tim
>
> "Peter Afonin" <pafo@specialtypulltabs.com> wrote in message
> news:uRwygg1uCHA.1644@TK2MSFTNGP09...
> > Hello:
> >
> > Is there a way to control tabs and set focus to the controls in ASP.Net?
> The
> > TabIndex property doesn't really do the work. I can use JavaScript in
some
> > situations to set focus to the control, but what to do, for instance, in
> > this case:
> >
> > I have several buttons (server controls) on the form, and I need one to
be
> a
> > default button which responds when the Enter key is pressed. I can play
> with
> > the TabIndex as much as I want, but only the very first button on the
form
> > will be a default button.
> >
> > I researched the newsgroups, and it seems that this is by design, and I
> > cannot change anything, which is hard to believe. But if it's true, is
> there
> > any way around it?
> >
> > I would appreciate any comments about it.
> >
> > Thank you,
> >
> > --
> > Peter Afonin
> >
> >
>
>
>