473,795 Members | 3,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1626
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.co m> wrote in message
news:ut******** ******@TK2MSFTN GP10.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 WillcockConsult ing.ProductCata logue.UI.Web.Ut ils
{
public class ProductCatalogu eWebPage : Page
{
protected void SetClientFocus( Control focusControl)
{
StringBuilder script = new StringBuilder(2 00, 200);

string clientID = focusControl.Cl ientID;
script.Append(" <script language=\"java script\">docume nt.all.");
script.Append(c lientID);
script.Append (".focus();</script>");
RegisterStartup Script("SetFocu s", script.ToString ());
}
}
}

Then you just need to inherit your page from ProductCatalogu eWebPage (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.ne t> wrote in message
news:uo******** *****@TK2MSFTNG P10.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.co m> wrote in message
news:ut******** ******@TK2MSFTN GP10.phx.gbl...
Is it possible to give control focus using Asp.net code??


Nov 18 '05 #3
"Steve Willcock" <st***@willcock consulting.com> wrote in message
news:cf******** ***********@new s.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
1217
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 to a VB 6.0 form works fine - with one important exception: the control disappears (except for any label/text on the control) if the user clicks the .NET-made control (giving it focus) and then clicks a button or other control which is not part of...
3
1831
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
2157
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
1428
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 System.Text.StringBuilder(""); sb.Append("<script language=\"JavaScript\">");
1
5138
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 the two steps, TextBox1.Text ="foo"; and TextBox2.Text = "bar";
2
1249
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 from within the Active event handler of the WizardStep control. Full details below. 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...
4
4307
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 have is that sometimes I seem to loose the original "holder" of focus and when the user hits tab while using "temporary" focus(while the mouse is over a control) it will change focus to the next control but not update it. So I have several issues....
5
11657
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 click to select one of the radiobuttons to select. The default behavior of Focus() seems to also select the radiobutton, but I can't seem to find what is causing this to happen. I would like very much to seperate the Focus and the selection....
11
7655
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 characters into the display myself - but that's not the main issue at this time. I've tried a scrolling multiline text box but once the original viewable area fills up and it starts scrolling the flashing of the entire area drives me nuts. The...
0
9672
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
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10436
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10213
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
9040
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...
0
6780
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
5436
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
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.