473,324 Members | 2,501 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,324 software developers and data experts.

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 1368
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********@yahoo.com> wrote in message news:e$****************@TK2MSFTNGP10.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*********@suretar.reverse> wrote in message
news:ue**************@TK2MSFTNGP09.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********@yahoo.com> wrote in message
news:e$****************@TK2MSFTNGP10.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.RegisterClientScriptBlock 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*********@suretar.reverse> wrote in message
news:ue**************@TK2MSFTNGP09.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********@yahoo.com> wrote in message
news:e$****************@TK2MSFTNGP10.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_PreRender(object sender, EventArgs e) {
if ( focusControl != null ) {
Page.RegisterStartupScript( "FocusScript", string.Format(
"<script
language='javascript'>try{{document.getElementById ('{0}').focus();}}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********@yahoo.com> wrote in message
news:e$**************@TK2MSFTNGP10.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 RegisterClientScript and set client
focus on html objects. I just do a window.attachevent and call a function
which places the focus on the control. Simple but very useful.

Sekhar.

"Mike" <vi********@yahoo.com> wrote in message
news:e$****************@TK2MSFTNGP10.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
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...
8
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...
3
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...
1
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. ...
2
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...
27
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...
4
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...
8
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....
2
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.