You can turn on SmartNavigation , although under certain circumstances that
can prove problematic. Here's how I take care of it in ASP.NET 1.1 (in
ASP.NET 2.0, you have special overloads that don't require separate code for
this issue):
// in Global.asax.cs:
public class Global : System.Web.Http Application
{
// insert static SetFocus method here, just below the class Global
declaration:
public static void SetFocus(System .Web.UI.Page webPage)
{
string[] pbCtrl = webPage.Page.Re quest.Form.GetV alues("__EVENTT ARGET");
if (pbCtrl != null && pbCtrl.Length > 0)
{
string ctrlId;
ctrlId = pbCtrl[0];
System.Web.UI.C ontrol ctrlFound = webPage.Page.Fi ndControl(ctrlI d);
if ((ctrlFound != null) &&
(
ctrlFound is System.Web.UI.W ebControls.Drop DownList ||
ctrlFound is System.Web.UI.W ebControls.Text Box ||
ctrlFound is System.Web.UI.W ebControls.Radi oButton ||
ctrlFound is System.Web.UI.W ebControls.Radi oButtonList))
{
string ctrlClientId;
ctrlClientId = ctrlFound.Clien tID;
string strScript;
strScript = "<SCRIPT language=\"java script\"> document.getEle mentById('" +
ctrlClientId + "').focus() ; document.getEle mentById('"
+ ctrlClientId + "').scrollIntoV iew(true) </SCRIPT>";
webPage.Page.Re gisterStartupSc ript("controlFo cus",strScript );
}
}
}
// In your Page_Load handler for (any page:
private void Page_Load(objec t sender, System.EventArg s e)
{
// insert this conditional call to the SetFocus Method:
if(IsPostBack) Global.SetFocus (this);
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"gjtired" wrote:
Hi,
When I click a button or dropdown box at the bottom of the web form the
focus shifts to the top of the form. What can I do to make it stay
where it is at?
Thanks
Gayle