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.HttpApplication
{
// insert static SetFocus method here, just below the class Global
declaration:
public static void SetFocus(System.Web.UI.Page webPage)
{
string[] pbCtrl = webPage.Page.Request.Form.GetValues("__EVENTTARGET ");
if (pbCtrl != null && pbCtrl.Length > 0)
{
string ctrlId;
ctrlId = pbCtrl[0];
System.Web.UI.Control ctrlFound = webPage.Page.FindControl(ctrlId);
if ((ctrlFound != null) &&
(
ctrlFound is System.Web.UI.WebControls.DropDownList ||
ctrlFound is System.Web.UI.WebControls.TextBox ||
ctrlFound is System.Web.UI.WebControls.RadioButton ||
ctrlFound is System.Web.UI.WebControls.RadioButtonList))
{
string ctrlClientId;
ctrlClientId = ctrlFound.ClientID;
string strScript;
strScript = "<SCRIPT language=\"javascript\"> document.getElementById('" +
ctrlClientId + "').focus(); document.getElementById('"
+ ctrlClientId + "').scrollIntoView(true) </SCRIPT>";
webPage.Page.RegisterStartupScript("controlFocus", strScript );
}
}
}
// In your Page_Load handler for (any page:
private void Page_Load(object sender, System.EventArgs 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