Another useful way to do this is to create a custom page base class that
will emit the necessary javascript into the client code and inherit your
pages from this class.
I have used the following code in one of my projects to achieve this goal:
using System;
using System.Text;
using System.Web.UI;
namespace WillcockConsult ing.ProductCata logue.UI.Web.Ut ils
{
public class ProductCatalogu eWebPage : Page
{
protected void SetClientFocus( Control focusControl)
{
StringBuilder script = new StringBuilder(2 00, 200);
string clientID = focusControl.Cl ientID;
script.Append(" <script language=\"java script\">docume nt.all.");
script.Append(c lientID);
script.Append (".focus();</script>");
RegisterStartup Script("SetFocu s", script.ToString ());
}
}
}
Then you just need to inherit your page from ProductCatalogu eWebPage (call
this anything you want of course) and call the SetClientFocus method passing
in your control - e.g.
SetClientFocus( textBox1);
Steve Willcock, MCSD
http://www.willcockconsulting.com/
"Steve C. Orr [MVP, MCSD]" <St***@Orr.ne t> wrote in message
news:uo******** *****@TK2MSFTNG P10.phx.gbl...
The easiest, most reliable way is client side javascript:
MyControl.focus ();
Here's more info:
http://wp.netscape.com/eng/mozilla/3..._f-g.htm#59872
You might also consider using this free control:
http://www.metabuilders.com/Tools/FirstFocus.aspx
--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com
"veera" <ve***@veera.co m> wrote in message
news:ut******** ******@TK2MSFTN GP10.phx.gbl... Is it possible to give control focus using Asp.net code??