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

Which control had focus before postback?

Hi,

Is it possible to retrieve the control that had the focus when the page was
posted back?

Because the focus is lost when a postback occurs I want to manually set the
focus to the control that previously had the focus (smartnavigation doesn't
do the trick).

Thanks, Marco
Nov 17 '05 #1
2 5172
use javascript
once the page hits the browser, .net is no longer at play

eg, object.onfocus(), set some hidden field to the control's name
once the page is back to the browser, use javascript again to set focus

it's a lot of work but that's the only way i've found that works. just
be careful about objects no longer being on the form or being disabled.

Marco Liedekerken wrote:
Hi,

Is it possible to retrieve the control that had the focus when the page was
posted back?

Because the focus is lost when a postback occurs I want to manually set the
focus to the control that previously had the focus (smartnavigation doesn't
do the trick).

Thanks, Marco


Nov 17 '05 #2
Here's a C# function you can call to have a page set focus when the page is
displayed:

protected void SetFocus(WebControl wc)

{

StringBuilder sScript = new StringBuilder("");

sScript.Append("<script language='javascript'>");

sScript.Append(" document.getElementById('" + wc.UniqueID + "').focus()");

sScript.Append("</script>");

Page.RegisterStartupScript("Focus", sScript.ToString());

}

All you need to do is call this function before posting the page. Should do
what you need.

"Kairi Zikpin" <zikkai.nospam.@netscape.net> wrote in message
news:3F**************@netscape.net...
use javascript
once the page hits the browser, .net is no longer at play

eg, object.onfocus(), set some hidden field to the control's name
once the page is back to the browser, use javascript again to set focus

it's a lot of work but that's the only way i've found that works. just
be careful about objects no longer being on the form or being disabled.

Marco Liedekerken wrote:
Hi,

Is it possible to retrieve the control that had the focus when the page was posted back?

Because the focus is lost when a postback occurs I want to manually set the focus to the control that previously had the focus (smartnavigation doesn't do the trick).

Thanks, Marco

Nov 17 '05 #3

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

Similar topics

2
by: Elliot M. Rodriguez | last post by:
Is it possible to change a control's focus at runtime? I'm sure you can.... I have a form with 2 textbox controls that cause postbacks. They are located in the middle of my form. When a...
4
by: RTM | last post by:
Can anyone help me with the following issue? I've seen some similar questions here, but none relating to a textbox control.... I have a form with several controls, one of them being a textbox...
1
by: Ian Oldbury | last post by:
i do a postback on a field within a dot.net datagrid (in editmode) and need to set the focus to a specific field within the grid. Has anyone done this, any suggestions?
3
by: Dexter | last post by:
Hello All, I have a web control that when receive the focus, a postback is called, using getPostBackEventReference. But, when the PostBack is called, i want that the focus goes to the web control....
7
by: djc | last post by:
I noticed that after entering text into a textbox on an asp.net webform and then hitting the enter key that a postback appears to be performed. 1) what event can I write to in order to perform an...
4
by: Chris | last post by:
Hi, I am trying to create a popup calender so a user can click on a button on the main form, a calender will then popup, the user will select a date and then click ok on the popup. The date will...
1
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for...
1
by: amjad | last post by:
Hi i need to write javascript to shift control focus ..... like if i enter in textbox 1 then it set focus to textbox2 or 3 any thing ... the other thing is how i know i can do like...
6
by: John Smith | last post by:
How can I find out which control performed PostBack? I have put this code inside my Page_Load event: Response.Write(Page.Request.Params.Get("__EVENTTARGET")) but it doesn't write to response...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
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...
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...
0
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,...

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.