Digital Colony!

Setting Default Focus on ASP.NET Master Pages

In ASP.NET 2.0, the way to set focus on a particular form field is to add a defaultfocus declaration in the form tag.
<form id="Form1" defaultfocus="txtSearch" runat="server"> 
Since the form tag does not appear when using MasterPages, setting form focus is done in the code. This is the line that will accomplish the same focus in C#.
Page.Form.DefaultFocus = txtSearch.ClientID;

Labels: ,

 

Digital Colony Copyright © 1999-2008 XHTML   508
This site uses Blogger, which is not 100% XHTML compliant.
Try...Catch Disclaimer: For brevity many examples do not include error handling. That is your responsibility.