473,387 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

on button click form moves to the top

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

Nov 23 '05 #1
3 2481
I think you have to check for Page.IsPostBack in the Page_Load function. So
something like:

private void Page_Load(object sender, System.EventsArgs e)
{
if (Page.IsPostBack == false)
{
// Code goes here.
}
}

That'll keep the page from reloading everytime you change a selection in the
dropdown box.

"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

Nov 23 '05 #2
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

Nov 23 '05 #3
I had a if (!IsPostBack)
{
//code
}

I tried it your way and it still does the same thing. Below is what I
have.

private void Page_Load(object sender, System.EventArgs e)
{
if (Page.IsPostBack == false)
{
// copies Task and TaskType index from TaskToPerform.aspx
txtTaskType.Text=Request.QueryString["TaskType"];
txtTask.Text=Request.QueryString["Task"];

//Fill drpQuestionType
sqlConnection1.Open();
daQuestionType.Fill(dsMain1.QuestionType);
DataTable dtQuestionType = dsMain1.Tables["QuestionType"];
//Make type of question invisible if editing a question
//lblTypeQuestion.Visible = false;
drpTypeQuest.Visible = false;

//fills the drpTypeQuest
foreach (DataRow dataRow in dtQuestionType.Rows)
{

ListItem questtype= new ListItem();

questtype.Text=dataRow["QuestionType_Option"].ToString().Trim();
questtype.Value=dataRow["QuestionType_ID"].ToString().Trim();
drpTypeQuest.Items.Add(questtype);
} //end foreach loop

string sqlEdit="SELECT * " +
"FROM BTForm " +
"WHERE BTForm_Status = 'Active' " +
"Order By BTForm_Name";

SqlDataAdapter daEdit=new SqlDataAdapter(sqlEdit, sqlConnection1);
dsMain1.BTForm.Clear();
daEdit.Fill(dsMain1.BTForm);
DataTable BTFormDT = dsMain1.Tables["BTForm"];

//fills the drpSelectForm
foreach (DataRow BTFormRow in BTFormDT.Rows)
{

ListItem newBTForm= new ListItem();

newBTForm.Text=BTFormRow["BTForm_Name"].ToString().Trim();
newBTForm.Value=BTFormRow["BTForm_ID"].ToString().Trim();
drpSelectForm.Items.Add(newBTForm);
} //end foreach loop
sqlConnection1.Close();
}//end ispostback if
}//Page_Load

Nov 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: MJW | last post by:
Is there a way for me to know if or which command button was just clicked that triggers the LostFocus event for the current control on a Form? I have a form that has many types of users who each...
8
by: William Bradley | last post by:
Following is the code I am using, behind a command button, on a form to print out only the report of that particular form. ******************** Code Start ************************ Dim strDocName...
3
by: Wang | last post by:
Here is the code for a webcontrol, quite simple: ------------------------------------------------------------------------------------------------------------- <%@ Control Language="c#"...
3
by: | last post by:
Hi I am using vb.net code behind. In my code I have a button click event on my main web form. Private Sub btNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
14
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons...
4
by: John Smith | last post by:
I have a continuous form. there is a command button with the following code for the OnClick event: DoCmd.OpenForm "frmPlants", , , "PlantsID =" & Me!PlantsID I click the button and frmPlants...
14
by: teddysnips | last post by:
WINDOWS FORMS I've a form that has a textbox that allows the user to enter a string. On the LostFocus event, the textbox formats the string into a preferred format. However, if the user...
0
by: AllenW | last post by:
I have a VB.Net 2005 application that moves the mouse cursor via software and generates mouse clicks anywhere on the monitor using SendInput. The code that moves the mouse and decides when to issue...
24
by: MichaelK | last post by:
Who knows how to prevent submitting a form on the press Enter button before all fields on the form are filled up. People just enter the first field hit Enter and it submits the form and doing...
8
by: Harvey Schmidlapp | last post by:
I have a fairly complex form (generated by means of an ASP 3 page). The form is used to define a query against a database. After running a query, the user hits their browser's back button and goes...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.