Search
Categories
  ASP.NET
Visual C#
Visual Basic
.NET Framework
ADO.NET
AJAX
LINQ
Java
 
Tutorial Rating
 
5.0 out of 5


Total Votes: 1
         
1 2 3 4 5
 




Setting Controls Focus in ASP.NET 2.0

Author: Waqas Anwar - Posted Date: 04-March-2008 - Category: ASP.NET   
Bookmark and Share
One of the very important features of current successful websites is providing better user experience to the users. As a developer you need to make sure that your website user interface is simple and easy to use. One way you can achieve this is by providing better focus management of your controls. Controls such as textboxes, listboxes or drop down lists should get focus automatically at the page load time to save user time on extra mouse clicks.
 

ASP.NET 2.0 provides three different ways you can set focus on any control in your page.

Set Focus using defaultfocus attribute of Web Form

<form id="Form1" runat="server" defaultfocus="TextBox1">
    <asp:TextBox id="TextBox1" runat="server" />
    <asp:TextBox id="TextBox2" runat="server" />
    <asp:Button id="Button1" runat="server" text="Button1" />
</form>


Set Focus using Page.SetFocus() method

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Page.SetFocus(TextBox1);
End Sub


Set Focus using Focus() method of Controls
 
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    TextBox1.Focus();
End Sub





RELATED TUTORIALS

  Cross Page Posting in ASP.NET 2.0

LEAVE YOUR COMMENTS LEAVE YOUR COMMENTS
 Name (required)  
 Email (required
 Website


 

 


 
 
 

Categories

My Portfolio

Website Links


Copyright @ 2009 EzzyLearning.com