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 WillcockConsulting.ProductCatalogue.UI.Web.Utils
{
public class ProductCatalogueWebPage : Page
{
protected void SetClientFocus(Control focusControl)
{
StringBuilder script = new StringBuilder(200, 200);
string clientID = focusControl.ClientID;
script.Append("<script language=\"javascript\">document.all.");
script.Append(clientID);
script.Append (".focus();</script>");
RegisterStartupScript("SetFocus", script.ToString());
}
}
}
Then you just need to inherit your page from ProductCatalogueWebPage (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.net> wrote in message
news:uo*************@TK2MSFTNGP10.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.com> wrote in message
news:ut**************@TK2MSFTNGP10.phx.gbl... Is it possible to give control focus using Asp.net code??