Click here to Skip to main content
13,145,608 members (38,247 online)
Click here to Skip to main content
Add your own
alternative version


36 bookmarked
Posted 9 Sep 2003

How to set focus to a MS ASP.NET TreeView on form load

, 9 Sep 2003
Rate this:
Please Sign up or sign in to vote.
This article will provide some tips on setting focus to a TreeView control.


People have been having problems using the TreeView control from Microsoft, for ASP.NET:


This control can be download for free from the Microsoft website. This page contains an overview of the free web controls (not supported by MS).

We will cover the focus issues for this control in this article. The reason I chose to create this article is that there was not much information after searching multiple sites. Basically this article will explain the two main problems: trying to get a TreeView control to have focus and setting the colors properly, for hover and selected items.

Main information

Here is a list of problems trying to set focus to the Microsoft ASP.NET TreeView control:

  1. Even though you place the TreeView inside a form, you have to use the document object instead of the form object to set the focus. Here is the final code:
    Private Sub focusTreeview()
      Dim strBuilder As StringBuilder = New StringBuilder()
      strBuilder.Append("<script language="'javascript'">")
      'Following line does nothing
      RegisterStartupScript("FocusTreeview", strBuilder.ToString)
    End Sub

    After you use the code above, the TreeView will be selected on form load and user can properly select any item from the TreeView.

  2. Once you use the document's focus method, the colors stay in "light" mode no matter what you do, but, the TreeView is actually selected correctly.
  3. The "select" statement does not have any effect on the TreeView. So if you un-comment the line above, it will have no effect on the TreeView.
  4. The way to make the colors not be in "light" mode is by using the filter style attribute in the SelectedStyle and HoverStyle as follows:
    <iewc:treeview id="TreeView1"
    font-weight:bold;" HoverStyle="filter=none;background-color:green;">


  1. The filter=none has to go before the other style keywords, if not you will just get a grey color.
  2. Be sure to add Imports System.Text to the top of your code in order to use the StringBuilder object.
  3. The features described in this article only apply to MS Internet Explorer 6.x.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralOK! Usefull. Thanx! Pin
mkemals23-Aug-06 8:32
membermkemals23-Aug-06 8:32 
GeneralGenerate TreeView using TreeNodeSrc Pin
luisfer20-May-05 6:39
sussluisfer20-May-05 6:39 
GeneralProblem to set focus on a popup window Pin
Mindy0121-Apr-05 9:23
memberMindy0121-Apr-05 9:23 
Generalproblem in Tree view Pin
mtayyabasghar7-Apr-05 1:34
membermtayyabasghar7-Apr-05 1:34 
GeneralRe: problem in Tree view Pin
SeaWater7-Apr-05 1:40
memberSeaWater7-Apr-05 1:40 
GeneralRe: problem in Tree view Pin
mtayyabasghar7-Apr-05 18:54
membermtayyabasghar7-Apr-05 18:54 
GeneralRe: problem in Tree view Pin
SeaWater8-Apr-05 1:57
memberSeaWater8-Apr-05 1:57 
GeneralThanx Pin
mtayyabasghar15-Apr-05 18:48
membermtayyabasghar15-Apr-05 18:48 
GeneralTree View Expand and select node Pin
Lakkisetty19-Oct-04 1:24
memberLakkisetty19-Oct-04 1:24 
GeneralRe: Tree View Expand and select node Pin
SeaWater19-Oct-04 1:52
memberSeaWater19-Oct-04 1:52 
GeneralRe: Tree View Expand and select node Pin
lakkisetty19-Oct-04 19:12
memberlakkisetty19-Oct-04 19:12 
GeneralRe: Tree View Expand and select node Pin
Anonymous5-Sep-05 22:08
sussAnonymous5-Sep-05 22:08 
GeneralRe: Tree View Expand and select node Pin
js12389310-Jan-07 7:32
memberjs12389310-Jan-07 7:32 
GeneralRe: Tree View Expand and select node [modified] Pin
Merlin Rose5-May-09 2:34
memberMerlin Rose5-May-09 2:34 
GeneralRe: Tree View Expand and select node Pin
Merlin Rose5-May-09 2:42
memberMerlin Rose5-May-09 2:42 
GeneralCOM Interface for WebControl Pin
sonny-bob20-Dec-03 1:01
membersonny-bob20-Dec-03 1:01 
GeneralDisabling direction keys from moving focus Pin
bracoute23-Nov-03 18:45
memberbracoute23-Nov-03 18:45 
GeneralRe: Disabling direction keys from moving focus Pin
sambaraju16-Apr-04 19:45
membersambaraju16-Apr-04 19:45 
GeneralRe: Disabling direction keys from moving focus Pin
Vivivivivivivivivivian1-Jun-06 11:06
memberVivivivivivivivivivian1-Jun-06 11:06 
GeneralThank You Pin
jammyjarv21-Oct-03 21:20
sussjammyjarv21-Oct-03 21:20 
GeneralRe: Thank You Pin
SeaWater27-Oct-03 2:17
memberSeaWater27-Oct-03 2:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170915.1 | Last Updated 10 Sep 2003
Article Copyright 2003 by SeaWater
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid