473,396 Members | 1,997 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,396 software developers and data experts.

Is it possible to give control focus using Asp.net code??

Is it possible to give control focus using Asp.net code??
Nov 18 '05 #1
3 1606
The easiest, most reliable way is client side javascript:

MyControl.focus();

Here's more info:
http://wp.netscape.com/eng/mozilla/3..._f-g.htm#59872

You might also consider using this free control:
http://www.metabuilders.com/Tools/FirstFocus.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"veera" <ve***@veera.com> wrote in message
news:ut**************@TK2MSFTNGP10.phx.gbl...
Is it possible to give control focus using Asp.net code??

Nov 18 '05 #2
Another useful way to do this is to create a custom page base class that
will emit the necessary javascript into the client code and inherit your
pages from this class.

I have used the following code in one of my projects to achieve this goal:

using System;
using System.Text;
using System.Web.UI;

namespace WillcockConsulting.ProductCatalogue.UI.Web.Utils
{
public class ProductCatalogueWebPage : Page
{
protected void SetClientFocus(Control focusControl)
{
StringBuilder script = new StringBuilder(200, 200);

string clientID = focusControl.ClientID;
script.Append("<script language=\"javascript\">document.all.");
script.Append(clientID);
script.Append (".focus();</script>");
RegisterStartupScript("SetFocus", script.ToString());
}
}
}

Then you just need to inherit your page from ProductCatalogueWebPage (call
this anything you want of course) and call the SetClientFocus method passing
in your control - e.g.

SetClientFocus(textBox1);

Steve Willcock, MCSD
http://www.willcockconsulting.com/

"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:uo*************@TK2MSFTNGP10.phx.gbl...
The easiest, most reliable way is client side javascript:

MyControl.focus();

Here's more info:
http://wp.netscape.com/eng/mozilla/3..._f-g.htm#59872
You might also consider using this free control:
http://www.metabuilders.com/Tools/FirstFocus.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"veera" <ve***@veera.com> wrote in message
news:ut**************@TK2MSFTNGP10.phx.gbl...
Is it possible to give control focus using Asp.net code??


Nov 18 '05 #3
"Steve Willcock" <st***@willcockconsulting.com> wrote in message
news:cf*******************@news.demon.co.uk...
Another useful way to do this is to create a custom page base class that
will emit the necessary javascript into the client code and inherit your
pages from this class.


Yes - I use this technique often.
Nov 18 '05 #4

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

Similar topics

1
by: Hvitebj?rn | last post by:
I have created a graphical control using C#.NET and made it COM-compatible using the method described here: http://www.codeproject.com/cs/miscctrl/exposingdotnetcontrols.asp Adding the control...
3
by: Paul | last post by:
Just wondering if there is a way to give a control focus when the page loads, for example so the user could start typing in a text box before clicking on it? Thanks, -- Paul G Software engineer.
2
by: bill | last post by:
I have the following user control in my project simply for setting focus to a control: Public Class SetFocus Inherits System.Web.UI.UserControl
2
by: Christian Ista | last post by:
Hello, I found that (see below) to give the focus to a control(textbox) on an asp.net page. There is no easiest way to do that ? Thanks, System.Text.StringBuilder sb = new...
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...
2
by: clickon | last post by:
I have posted this question 3 times now and no-one has even answered it, so is it possibly a bug or am i missing something. In short it does not seem to be possible to set the focus on control...
4
by: Jon Slaughter | last post by:
I've created some custom controls and forms that allow the feature to temporarily transfer focus to a control that has been entered by the mouse. Everything seems to work fine but the problem I...
5
by: Matt B | last post by:
I know this is a bit of nonstandard behavior, but I would like the Enter key to move focus through a group of radiobuttons without selecting them. The user would then have to use Space or actually...
11
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I know I sound like a one-note Johnny on this but I'm still looking for a solution. I need to display characters coming in from a serial port or a socket. I also need to be able to type...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
0
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...
0
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...

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.