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

focus question


We have some fields with AutoPostBack set to true and when user tabs to the
next field the screen re-calculates correctly however we also lose which
control/text box had focus when the user tabbed.
Is there any way of storing and resting which control should have focus?
We are using asp.net with vb.net for code.

Thanks
---
Outgoing mail is certified Virus Free, so am I.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.688 / Virus Database: 449 - Release Date: 18/05/2004
Nov 18 '05 #1
4 1295
Here is a user control I wrote in C# to accomplish this. Place it in your toolbox and drag and drop it on any form. Set the properties in your code behind

using System
using System.Web.UI
using System.ComponentModel

namespace Common.CTL.FocusManage

/// <summary
/// clsFocusManager - Allows programmer to set focus to a control and to select the data in th
/// control if desired
/// This web custom control is placed in the Tool Box
/// </summary
[DefaultProperty("Text"),
ToolboxData("<{0}:clsFocusManager runat=server></{0}:clsFocusManager>")

public class clsFocusManager : System.Web.UI.WebControls.WebContro

private string mBoundControlID
private bool mSelectControl

//Property to indicate which control will receive focus
[Bindable(true),
Category("Appearance"),
DefaultValue("")]

public string BoundControlI

ge

return mBoundControlID

se

mBoundControlID = value

//Property to indicate if the data in the control is selected or not
[Bindable(true),
Category("Appearance"),
DefaultValue(false)]

public bool SelectContro

ge

return mSelectControl

se

mSelectControl = value

/// <summary>
/// Render this control to the output parameter specified
/// </summary
/// <param name="output"> The HTML writer to write out to </param
protected override void Render(HtmlTextWriter output

string strScript

if (mBoundControlID != null

if (Page.FindControl(mBoundControlID) != null

if(!Page.IsStartupScriptRegistered("FocusManager")

strScript = "<Script Language=javascript>"
strScript += "document.getElementById('" + mBoundControlID + "').focus();"

if (mSelectControl == true

strScript += "document.getElementById('" + mBoundControlID + "').select();"

strScript += "</script>"
Page.RegisterStartupScript("FocusManager", strScript)



Nov 18 '05 #2
Thanks

"RCAM" <an*******@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
Here is a user control I wrote in C# to accomplish this. Place it in your toolbox and drag and drop it on any form. Set the properties in your code
behind.
using System;
using System.Web.UI;
using System.ComponentModel;

namespace Common.CTL.FocusManager
{
/// <summary>
/// clsFocusManager - Allows programmer to set focus to a control and to select the data in the /// control if desired.
/// This web custom control is placed in the Tool Box.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:clsFocusManager runat=server></{0}:clsFocusManager>")]

public class clsFocusManager : System.Web.UI.WebControls.WebControl
{
private string mBoundControlID;
private bool mSelectControl;

//Property to indicate which control will receive focus.
[Bindable(true),
Category("Appearance"),
DefaultValue("")]

public string BoundControlID
{
get
{
return mBoundControlID;
}
set
{
mBoundControlID = value;
}
}

//Property to indicate if the data in the control is selected or not.
[Bindable(true),
Category("Appearance"),
DefaultValue(false)]

public bool SelectControl
{
get
{
return mSelectControl;
}
set
{
mSelectControl = value;
}
}

/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
string strScript;

if (mBoundControlID != null)
{
if (Page.FindControl(mBoundControlID) != null)
{
if(!Page.IsStartupScriptRegistered("FocusManager") )
{
strScript = "<Script Language=javascript>";
strScript += "document.getElementById('" + mBoundControlID + "').focus();";
if (mSelectControl == true)
{
strScript += "document.getElementById('" + mBoundControlID + "').select();"; }
strScript += "</script>";
Page.RegisterStartupScript("FocusManager", strScript);
}
}
}
}
}
}

---
Outgoing mail is certified Virus Free, so am I.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.688 / Virus Database: 449 - Release Date: 18/05/2004
Nov 18 '05 #3
Here is another idea:

In your base page that all your pages inherit from you can use:
================================================== ===
Public InitialFocus As Control

Protected Overridable Sub Page_PreRender(ByVal sender As Object, ByVal e As
EventArgs)
Dim sb As New StringBuilder
sb.Append("<script language='javascript'>")
If Not InitialFocus Is Nothing Then
sb.Append("document.getElementById('" & InitialFocus.ClientID &
"').focus();")
End If
sb.Append("</script>")
End Sub
================================================== ===
Then in Page_Load of your .aspx page you simply set the Property like this:
InitialFocus = txtVuid
================================================== ===
--
Joe Fallon

"starbuck" <st******@mbssoft.co.uk> wrote in message
news:eW*************@TK2MSFTNGP10.phx.gbl...

We have some fields with AutoPostBack set to true and when user tabs to the next field the screen re-calculates correctly however we also lose which
control/text box had focus when the user tabbed.
Is there any way of storing and resting which control should have focus?
We are using asp.net with vb.net for code.

Thanks
---
Outgoing mail is certified Virus Free, so am I.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.688 / Virus Database: 449 - Release Date: 18/05/2004

Nov 18 '05 #4
Thanks Joe

"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:ew**************@TK2MSFTNGP10.phx.gbl...
Here is another idea:

In your base page that all your pages inherit from you can use:
================================================== ===
Public InitialFocus As Control

Protected Overridable Sub Page_PreRender(ByVal sender As Object, ByVal e As EventArgs)
Dim sb As New StringBuilder
sb.Append("<script language='javascript'>")
If Not InitialFocus Is Nothing Then
sb.Append("document.getElementById('" & InitialFocus.ClientID &
"').focus();")
End If
sb.Append("</script>")
End Sub
================================================== ===
Then in Page_Load of your .aspx page you simply set the Property like this: InitialFocus = txtVuid
================================================== ===
--
Joe Fallon

"starbuck" <st******@mbssoft.co.uk> wrote in message
news:eW*************@TK2MSFTNGP10.phx.gbl...

We have some fields with AutoPostBack set to true and when user tabs to

the
next field the screen re-calculates correctly however we also lose which
control/text box had focus when the user tabbed.
Is there any way of storing and resting which control should have focus?
We are using asp.net with vb.net for code.

Thanks
---
Outgoing mail is certified Virus Free, so am I.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.688 / Virus Database: 449 - Release Date: 18/05/2004


---
Outgoing mail is certified Virus Free, so am I.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.688 / Virus Database: 449 - Release Date: 18/05/2004
Nov 18 '05 #5

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

Similar topics

7
by: Chris | last post by:
I'm using eight links listed horizontally as a menu on my site. I'm using font-variant:small-caps and they are padded so that they mimic buttons. My gripe is with the way IE handles the focus...
3
by: Frederik Vanderhaegen | last post by:
Hi, I've written a sort of wizard in which the user has to answer some questions. This wizard contains a radiobuttonlist en two buttons (back and next). With the first question there's no...
2
by: Jonathan N. Little | last post by:
As part of a JavaScript precheck form validation I noticed a problem with trying to return focus to the field with an error. I have setup a demo page. ...
3
by: Simon | last post by:
Dear reader, On the event "Lost focus" I make the ComboBox invisible but the massage pops up "You can't hide a control that has the focus." But this code is written in the "Lost focus"...
1
by: john ciriello | last post by:
I created a form and put a button and a label on it. I set the tabstops to false. When I first run it I can click the button and there is no focus rectangle. Which is what I want. However, if I...
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: 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: 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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.