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

About web form textbox focus question !!

Dear All,

I used csharp web form to develop my company web application, and my
question is how shuld I do if I want to focus on my textbox(ex. like Java
Script form.txtID.focus()).

Thanks !!

Sincerely yous,
Paul
Nov 16 '05 #1
1 1655
You'll have to use javascript code for setting focus. This can be done in the
codebehind file as follows:
(1) Write a method, say, SetFocus(Control x), which will register a
javascript code block.
(2) Call the SetFocus method with a control parameter from another method,
or event handler, say, Page_Load or Button1_click
(3) For detailed articles, follow this link
http://www.aspnetworld.com/articles/2004030301.aspx

The sample code is as follows:
private void SetFocus(Control x)
{
string clientId = x.ClientID;
StringBuilder strScript = new StringBuilder("<script
language='javascript'>\n");
strScript.Append("document.getElementById('" + clientId +
"').focus();\n");
strScript.Append("</script>\n");
Page.RegisterStartupScript("Focus",strScript.ToStr ing());
}

private void Button1_Click(object sender, System.EventArgs e)
{
SetFocus(TextBox2);
}

Hope this helps.

"Paul Tsai" wrote:
Dear All,

I used csharp web form to develop my company web application, and my
question is how shuld I do if I want to focus on my textbox(ex. like Java
Script form.txtID.focus()).

Thanks !!

Sincerely yous,
Paul

Nov 16 '05 #2

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

Similar topics

4
by: Albinas | last post by:
Hi all, I am trying to customize the text box to suit the practice of my app. And I am working about the focus behavior of text field. I have met the the following problem. When I set the...
5
by: Darren DeCoste | last post by:
I have an access project with a Form that has a Command button to print the current record. I would like to Print the record 3 times, changing a text field on each print. The standard code of...
17
by: Neil Ginsberg | last post by:
OK, this is a stupid thing, but I can't seem to get this to work. I have a form with a subform (in continuous form view). A combo box on the main form has code in the AfterUpdate event which adds a...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
5
by: feng | last post by:
Hi, I have a aspx page that contains a textbox. When the page loads, it's always the browser's address bar or other browser controls has the focus. What I want however, is to let the textbox...
1
by: TBK | last post by:
I'm trying to finish up an assignment I had for a class and basically I'm stuck. The program is supposed to take information you've entered, put it into an array, display it in a listbox and then...
2
by: Jesper | last post by:
Hi, I have an C# windows application running that has the property WindowsState of the main form set to 'Minimized' and the property ShowInTaskBar set to false. I've asingned a notifyIcon to the...
6
by: =?Utf-8?B?U2NvdHQgTGFt?= | last post by:
Hi, I have a VB.NET form with a bunch of controls in it . The focus is in one of the controls , (i.e. a textbox), is there any way to click on the form itself and make the textbox lose focus and...
3
by: hugo | last post by:
Hi, I have a function that I call from form fields using the OnKeyUp function to replace special caracters. Once this function has been called, it does not set the focus on the form field where...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
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?
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...

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.