473,624 Members | 2,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question: maintaining focus between pages

I have a few textbox controls that have autopostback so that when they loose
focus they update a label control that shows the count of characters in
their respective text control. This works fine, except that after the
postback, the page is shown reset -- scrolled to the top and with no control
having focus. Can I maintain scroll/focus w/o writing client-side
scripting?

thanks
Nov 18 '05 #1
6 1379
Not to question you as I'm sure you have a good reason, but why are you trying to avoid client-side code in this situation? Doesn't this problem beg for it?

To answer your question, no, you can't maintain scroll/focus w/o writing client-side code. Sure you can write code to do it on the server, but it is still going to be clientside code. I'd try to avoid the postback as much as possible, unless this is an intranet app and nobody will ever notice.

--Michael

"Mike" <vi********@yah oo.com> wrote in message news:e$******** ********@TK2MSF TNGP10.phx.gbl. ..
I have a few textbox controls that have autopostback so that when they loose
focus they update a label control that shows the count of characters in
their respective text control. This works fine, except that after the
postback, the page is shown reset -- scrolled to the top and with no control
having focus. Can I maintain scroll/focus w/o writing client-side
scripting?

thanks

Nov 18 '05 #2
Figured as much. This particular app. is for external users, but is a
management app. (not many users), not the main customer-facing application.
Basically there was an edict of "client code only when necessary" -- and
also laziness on my part. But basically, you're right.
So, any pointers to the preferred way to do this? (Figured there'd be a
declaritive way to do this and have the framework handle it, even if it
generated client scripting - but maybe not.)

thanks

"Raterus" <mo*********@su retar.reverse> wrote in message
news:ue******** ******@TK2MSFTN GP09.phx.gbl...
Not to question you as I'm sure you have a good reason, but why are you
trying to avoid client-side code in this situation? Doesn't this problem
beg for it?

To answer your question, no, you can't maintain scroll/focus w/o writing
client-side code. Sure you can write code to do it on the server, but it is
still going to be clientside code. I'd try to avoid the postback as much as
possible, unless this is an intranet app and nobody will ever notice.

--Michael

"Mike" <vi********@yah oo.com> wrote in message
news:e$******** ********@TK2MSF TNGP10.phx.gbl. ..
I have a few textbox controls that have autopostback so that when they loose focus they update a label control that shows the count of characters in
their respective text control. This works fine, except that after the
postback, the page is shown reset -- scrolled to the top and with no control having focus. Can I maintain scroll/focus w/o writing client-side
scripting?

thanks

Nov 18 '05 #3
No, there isn't a way to do it with the framework.

Use Page.RegisterCl ientScriptBlock to place the javascript in the page,
technically you're still writing it on the server. :-) Use the ID's as
references, since they are the same on the client side as they are on
the server side.

As for a pointer for info, use msdn. http://msdn.microsoft.com/library
is a good place to start. Under the Web Development tree....

Web Development->HTML and Dynamic HTML->SDK Documentation->Reference
will have everything that you basically need. There's an overview of
all things that appear in the HTML DOM, all properties, methods, and
yada. There is also some example scripting, but javascript is very
similar to typical server-side programming.
Mike wrote:
Figured as much. This particular app. is for external users, but is a
management app. (not many users), not the main customer-facing application.
Basically there was an edict of "client code only when necessary" -- and
also laziness on my part. But basically, you're right.
So, any pointers to the preferred way to do this? (Figured there'd be a
declaritive way to do this and have the framework handle it, even if it
generated client scripting - but maybe not.)

thanks

"Raterus" <mo*********@su retar.reverse> wrote in message
news:ue******** ******@TK2MSFTN GP09.phx.gbl...
Not to question you as I'm sure you have a good reason, but why are you
trying to avoid client-side code in this situation? Doesn't this problem
beg for it?

To answer your question, no, you can't maintain scroll/focus w/o writing
client-side code. Sure you can write code to do it on the server, but it is
still going to be clientside code. I'd try to avoid the postback as much as
possible, unless this is an intranet app and nobody will ever notice.

--Michael

"Mike" <vi********@yah oo.com> wrote in message
news:e$******** ********@TK2MSF TNGP10.phx.gbl. ..
I have a few textbox controls that have autopostback so that when they


loose
focus they update a label control that shows the count of characters in
their respective text control. This works fine, except that after the
postback, the page is shown reset -- scrolled to the top and with no


control
having focus. Can I maintain scroll/focus w/o writing client-side
scripting?

thanks


Nov 18 '05 #4
This is heavily edited, but you might be able to use something like this in
your base page class, if you have one.

private WebControl focusControl = null;

public void SetFocus( WebControl focus ) {
focusControl = focus;
}

private void BasePage_PreRen der(object sender, EventArgs e) {
if ( focusControl != null ) {
Page.RegisterSt artupScript( "FocusScrip t", string.Format(
"<script
language='javas cript'>try{{doc ument.getElemen tById('{0}').fo cus();}}catch(x ){{}}</script>",
focusControl .ClientID );
}
}

"Mike" wrote:
I have a few textbox controls that have autopostback so that when they loose
focus they update a label control that shows the count of characters in
their respective text control. This works fine, except that after the
postback, the page is shown reset -- scrolled to the top and with no control
having focus. Can I maintain scroll/focus w/o writing client-side
scripting?

thanks

Nov 18 '05 #5
Hi Mike,

Set smartNavigation to true.
Below is from MSDN:
In most circumstances, do not set this property in code. Set the
SmartNavigation attribute to true in the @ Page directive in the .aspx file.
When the page is requested, the dynamically generated class sets this
property.

When a page is requested by an Internet Explorer 5.5 browser, or later,
smart navigation enhances the user's experience of the page by performing
the following:

a.. eliminating the flash caused by navigation.
b.. persisting the scroll position when moving from page to page.
c.. persisting element focus between navigations.
d.. retaining only the last page state in the browser's history.
Smart navigation is best used with ASP.NET pages that require frequent
postbacks but with visual content that does not change dramatically on
return. Consider this carefully when deciding whether to set this property
to true.
--
Juno
MCSD.NET, MCDBA, MCSE
----------------------------------------------------------
Support Team of EasyDotNet, INC. http://www.EasyDotNet.com
DataForm.NET - The most powerful data entry web server control for ASP.NET

"Mike" <vi********@yah oo.com> wrote in message
news:e$******** ******@TK2MSFTN GP10.phx.gbl...
I have a few textbox controls that have autopostback so that when they loose focus they update a label control that shows the count of characters in
their respective text control. This works fine, except that after the
postback, the page is shown reset -- scrolled to the top and with no control having focus. Can I maintain scroll/focus w/o writing client-side
scripting?

thanks

Nov 18 '05 #6
I use a server side utility function to RegisterClientS cript and set client
focus on html objects. I just do a window.attachev ent and call a function
which places the focus on the control. Simple but very useful.

Sekhar.

"Mike" <vi********@yah oo.com> wrote in message
news:e$******** ********@TK2MSF TNGP10.phx.gbl. ..
I have a few textbox controls that have autopostback so that when they loose focus they update a label control that shows the count of characters in
their respective text control. This works fine, except that after the
postback, the page is shown reset -- scrolled to the top and with no control having focus. Can I maintain scroll/focus w/o writing client-side
scripting?

thanks

Nov 18 '05 #7

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

Similar topics

20
12294
by: Arne | last post by:
During testing <div style="overflow:auto;"> in CSS I noticed the mousewheel would work in Mozilla only after I made a <a href="#">some text</a> link and clicked on that, within the div. It appears as if Mozilla needs to have the focus set on that div in order for the mousewheel to work. That's all that link does. The mousewheel works perfectly in IE without the link. It scrolls the div even if there is a scrollbar on the page. Is...
8
3549
by: Yeah | last post by:
I wish to use a drop box where each Option will not take the user to a web page - but a certain location on the same page the drop box exists. For example, Option 1 would take the user to "Chapter 1", Option 2 would be "Chapter 2", and so on. All destinations are on the same page. I already have <A NAME="#ChapterX"> tags placed in the appropriate places in the document. (A no-GO button drop box is preferred.) How do I achieve this?
3
4215
by: Philip Townsend | last post by:
I have an aspx page that contains 2 user controls, each containing a seperate textbox and button. I would like to specify that one of the buttons recieve focus when the page loads. Also, I would like that same button to fire its event when the user presses enter. Can anybody help with this? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
1
1911
by: Novice | last post by:
Hey all, I have finally managed to create a Custom WebControl and am using a technique from another programmer to maintain state between pages - I would just like to validate this idea. Basically I have created a Custom Web Control that is capable of generating multiple webpages. It actually only creates one webpage, but hides Panels (that contain the web controls - TextBox's, Labels, etc) to give the impression that the user is...
2
1965
by: jason | last post by:
Hello and Good Day. REALLY LOST. Running ASP.NET 1.1 Becuase I think I'm using my own controls smartnavigation does not appear to work for me. Stardard issue: I've got a datagrid thats displaying pages and pages of rows. When I edit some row below pages 1 the post refreshes back to page one, requiring me to page down to do the input.
27
1870
by: Raymond | last post by:
They say it's easier, but has anyone tried maintaining an ASP.NET site without the source code of the dlls? This was not a problem with classic ASP, all the code was almost always just in text files, easily viewable and most importantly readily AVAILABLE on the site, to anyone access to the site's folder. But just imagine, bunch of companies out there, managed by non-technical people, who have had a bunch of outside
4
4331
by: Sam | last post by:
I have an asp.net 2.0 app that uses a sitemap, Master Page, and has several content pages. While this feature has simplified the process of creating a data-driven site menu, it does seem to have some big restrictions. Namely, maintaining state on the Master Page across all content pages. I simply want to keep track of a key value across all content pages. The only solution I can come up with is using a session variable, which I hate.
8
4061
by: makunag | last post by:
Didn't get answer with google and in my regular forum. Came across this site and posting here. Your help will be highly appreciated ! Our application have frames - MainNav, TaskNave and Content. When print button is clicked, it prints only the Content (obviously top.Content.focus() is in the code before window.print()). We were using windows 2000 & IE6 for years. Recently, our installation updated users machines with XP SP2. Now when print...
2
918
by: bobh | last post by:
Hi All In AccessXP I have a tab control with 5 tabs and I went to requery a combobox if and only if the user is moving from one perticular tab. I have this in place right now (On Change event of the tab control) but it does not do exactly what I want as it requeries cboParty each the user clicks on a non-'Page28' tab. If Me.TabCtl10.Pages.Item(TabCtl10.Value).Name <"Page28" Then Me.cboPARTY.Requery
0
8242
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8629
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8488
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7170
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.