Thursday, March 22, 2012

Setting the default focus on a web control

Please forgive what seems to me a very simple question, but, in VB6 I know how to set the default focus on a specific control when the page starts up. However, how do I do this on an ASP.net page? I have tried all the properties I can think of and I just can not get it to work. I have looked in all the books I have and nothing on "focus". Please help.Well, I don't know of ASP.Net way, but Javascript works fine. If you need to know how to do it, check out www.google.com. They make the focus go to the textbox when the page loads through Javascript. Here is their function:

<script>
<!--
function sf(){document.f.q.focus();}
// -->
</script>

<body onLoad=sf()>

Just to note, f is the name of the form, and q is the textbox.
That worked! Thanks!

0 comments:

Post a Comment