473,568 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2496
I think you have to check for Page.IsPostBack in the Page_Load function. So
something like:

private void Page_Load(objec t sender, System.EventsAr gs e)
{
if (Page.IsPostBac k == 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.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

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(objec t sender, System.EventArg s e)
{
if (Page.IsPostBac k == false)
{
// copies Task and TaskType index from TaskToPerform.a spx
txtTaskType.Tex t=Request.Query String["TaskType"];
txtTask.Text=Re quest.QueryStri ng["Task"];

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

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

ListItem questtype= new ListItem();

questtype.Text= dataRow["QuestionType_O ption"].ToString().Tri m();
questtype.Value =dataRow["QuestionType_I D"].ToString().Tri m();
drpTypeQuest.It ems.Add(questty pe);
} //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(dsM ain1.BTForm);
DataTable BTFormDT = dsMain1.Tables["BTForm"];

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

ListItem newBTForm= new ListItem();

newBTForm.Text= BTFormRow["BTForm_Nam e"].ToString().Tri m();
newBTForm.Value =BTFormRow["BTForm_ID"].ToString().Tri m();
drpSelectForm.I tems.Add(newBTF orm);
} //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
8930
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 have their own set of fields they can change. Therefore I use setfocus property in the lostfocus event for some of the users to get from one...
8
6971
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 As String Dim strWhere As String strDocName = "rptSomeReport" strWhere = "=" & me!RunID DoCmd.OpenReport strDocName, acPreview, , strWhere...
3
2509
by: Wang | last post by:
Here is the code for a webcontrol, quite simple: ------------------------------------------------------------------------------------------------------------- <%@ Control Language="c#" AutoEventWireup="false" Codebehind="WebUserControl1.ascx.cs" Inherits="WebApplication23.WebUserControl1"...
3
3359
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 btNew.Click Server.Transfer("New.aspx?") ' this moves to a
14
4951
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 for things like delete, save, edit, cancel buttons - in the footer, or on the form detail section? 2. If in the footer, how do you add them to the...
4
4786
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 opens up with the record that corresponds to the one on the cont. form. I put that same code for the OnClick of an image control (i.e. the user...
14
14585
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 presses the "Save" button while the textbox has the focus, the LostFocus code doesn't run at the right time, so that the "Save" function is dealing with...
0
1703
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 the simulated "click" is running in a separate thread from the main form's GUI. The "click" action is triggered by the user closing an external switch...
24
8399
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 validation, of course flushing with the bunch of messages because rest of the fields are empty. I remember I had some pages where wrote the code to go...
8
4736
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 back to the form, where their selections show up. They can change whatever they want to change and resubmit the new query. Mostly, everything works...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5498
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2101
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.