Search Amazon:

Set focus to a particular control on an ASP.NET web page

With a little JavaScript you can set the focus to a particular control on your ASP.NET web page. The sample code takes the control as a parameter, builds the JavaScript on the fly, then tells your ASPX page's code to send the JavaScript to the browser. To have your server code send the JavaScript to the client browser you use the RegisterStartupScript command. You can learn more about RegisterStartupScript by clicking here.

VB.NET code to catch and handle unhandled exceptions:

   Public Sub SetFocus(ByVal control As Control)
      If control.Page.IsStartupScriptRegistered("setFocus") Then
         Return
      End If

      Dim sb As StringBuilder = New StringBuilder("")

      control.Page.RegisterStartupScript("setFocus", sb.ToString())
   End Sub

Sample call to give the focus to a TextBox:

   SetFocus(txtText1)
Sign In
  User Id 
  Password 


Submit Your Own Code and Articles




About TheScarms
About TheScarms

Ask me your programming questions

I read every email and answer all I can.

User Feedback: Be the first to add a comment! Items to Show:     

     
You must log in to post feedback.
Comment:    
 

If you use this code, please mention "www.TheScarms.com"

Email this page


TheScarms AppSentinel lets you securely copy protect and create evaluation versions of your software

TheScarms(tm) AppSentinel lets you quickly and easily create evaluation versions of your software and stop unauthorized copying and unregistered use of your programs!

Get your free
trial copy today!


      The World's Number 1 Web Host

© Copyright 2008 TheScarms