Active Server Pages Programming (ASP)/ASP.Net Focus

Advertisement


Question
How do I automatically set the focus on a asp.net page to a text box when the page loads?

Also how do I launch a command button such as search or submit when the enter button is pressed on a keyboard?

Answer
hi


you can use javascript at the end of the page and setfocus if you do the codebehind on vb.net  use the following script

Sub Set_Focus()
Dim strVal As String
strVal = "<script language=javascript>document.all('textBox1').focus()</script>"
RegisterStartupScript("focus", strVal )
End Sub

on page load you can do like this

Page.RegisterHiddenField( "__EVENTTARGET", "btnSearch")

Happy Programming!

-Srini

Active Server Pages Programming (ASP)

All Answers


Answers by Expert:


Ask Experts

Volunteer


Srini Nagarajan

Expertise

I can answer any kind of questions in ASP.NET, C#, VB.NET, SharePoint 2007, ASP, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience

Contact me if you need any custom development on ASP.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder.

©2012 About.com, a part of The New York Times Company. All rights reserved.