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

Can I set initial focus from server-side into textbox?

Hi,

I am showing/hiding a variety of panels that have different text boxes via
code-behind functions. Depending on the condition, I would like to have the
focus be set on a specific text box. However, all examples I've seen do
this from the client side.

Does anyone have a way to easily to specify the textbox to focus on from a
code-behind function? My guess is it will have to be some combination of
server-side and client-side coding.

Any help would be appreciated.

Thanks!

-- Kent Iler
----------------------------------------------------------------------
ke**@iler.NOSPAM.com
Please CC: all replies via e-mail
Remove .NOSPAM from e-mail address
Nov 19 '05 #1
4 4784
HI Kent P. Iler ,

The followint function will helps you to set the focus to the
specified control through the Code behind.

Only the thig you have to pass the Control name as string Parameter

ex : SetAlertFocusControl("txtName")

Not you can place the focus to all the Control With this generic function.

Public Sub SetAlertFocusControl(ByVal ControlName As String)
Dim strScript As String ' for storing the script generated
Try
strScript = "<script language=" + Chr(34) + "javascript" + Chr(34) + ">"
strScript &= " var control = document.getElementById(" + Chr(34)
strScript &= ControlName + Chr(34) + ");"
strScript &= " control.focus();"
strScript &= "</script>"
' register the generated script
Page.RegisterStartupScript("Focus", strScript)
Catch excp As Exception
Finally
End Try
End Sub

Hope this helps ! all the best

--
Message posted via http://www.dotnetmonster.com
Nov 19 '05 #2
Hi Kent,

Yeah you can bring to the focus to some controls based on some condition. I
believe you know how to bring the focus to a control using java script. What
you need to do here is make that script to trigger from the code behind file.

There are two ways to running the script from the code behind file.

1. Printing the script using response.write.

eg. Response.Write("<script>text1.focus()</script>")

2. Using Page.RegisterStartupScript

Page.RegisterStartupScript("foc", "text1.focus()")

Page.RegisterStartupScript will execute the script.

With regards,

Sadha Sivam S,
Microsoft Community Star,
Sr. Software Engineer,
Aspire Systems,
www.dotnetspider.com
"Kent P. Iler" wrote:
Hi,

I am showing/hiding a variety of panels that have different text boxes via
code-behind functions. Depending on the condition, I would like to have the
focus be set on a specific text box. However, all examples I've seen do
this from the client side.

Does anyone have a way to easily to specify the textbox to focus on from a
code-behind function? My guess is it will have to be some combination of
server-side and client-side coding.

Any help would be appreciated.

Thanks!

-- Kent Iler
----------------------------------------------------------------------
ke**@iler.NOSPAM.com
Please CC: all replies via e-mail
Remove .NOSPAM from e-mail address

Nov 19 '05 #3
Something basic like this should work:

Response.Write "<script language = javascript>"& MyTextBox.ClientID &
".focus()</script>"

Here is an even slicker approach:
http://SteveOrr.net/faq/2in1.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Kent P. Iler" <ke**@iler.NOSPAM.com> wrote in message
news:Nr********************@comcast.com...
Hi,

I am showing/hiding a variety of panels that have different text boxes via
code-behind functions. Depending on the condition, I would like to have
the focus be set on a specific text box. However, all examples I've seen
do this from the client side.

Does anyone have a way to easily to specify the textbox to focus on from a
code-behind function? My guess is it will have to be some combination of
server-side and client-side coding.

Any help would be appreciated.

Thanks!

-- Kent Iler
----------------------------------------------------------------------
ke**@iler.NOSPAM.com
Please CC: all replies via e-mail
Remove .NOSPAM from e-mail address

Nov 19 '05 #4
Hi Kent,

You can make use form Data Format string property of the grid columns to
format the date.

For more input Refer http://www.dotnetspider.com/technology/kbpages/384.aspx.

With regards,

Sadha Sivam S,
Microsoft Community Star,
Sr. Engineer,
Aspire Systems,
www.dotnetspider.com

"Kent P. Iler" wrote:
Hi,

I am showing/hiding a variety of panels that have different text boxes via
code-behind functions. Depending on the condition, I would like to have the
focus be set on a specific text box. However, all examples I've seen do
this from the client side.

Does anyone have a way to easily to specify the textbox to focus on from a
code-behind function? My guess is it will have to be some combination of
server-side and client-side coding.

Any help would be appreciated.

Thanks!

-- Kent Iler
----------------------------------------------------------------------
ke**@iler.NOSPAM.com
Please CC: all replies via e-mail
Remove .NOSPAM from e-mail address

Nov 19 '05 #5

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

Similar topics

0
by: titouille | last post by:
Hi everybody ! first, sorry for my poor english, I'm french mothertongue ;) technologies : -------------- Python 2.3 Twisted Matrix 1.2.0 wxPython 2.5.1
2
by: dsnyder | last post by:
This HTML has a bit of Javascript at the end that puts the initial focus on the userID field. It works great on Windows2000 running IE6, but the initial focus never goes to the userID field on...
31
by: Benno Bös | last post by:
If I use the following construct in the frame "main" for a link to an extern site: <A HREF="http://www.any.xy" TARGET="extern"> the Browser is creating the window "extern", loading the page...
1
by: Jim Bayers | last post by:
This has been driving me crazy. server.transfer doesn't set the focus to the page I transfer to so when the user does a refresh, the results aren't what's expected. I have a datagrid on one...
8
by: copyco | last post by:
I want to be able to test if my app's form has focus, (ie: not in background, behind other windows). How can I do this? I tried the Me.Focused, but that doesn't work. I think it's because a...
10
by: Raja S. | last post by:
How does one set the initial focus to a control such as a picture box? Suppose I have a form with a single picture box on it. When the application starts to run I would like to set the focus to...
10
by: James Pyrich | last post by:
Greetings: I am using .NET to pop up a graphical window for a legacy application (remember the IBM System/23?). In order to achieve good performance, I created a GUI Broker Server and a Client...
1
by: Benton | last post by:
Hi there, I was using VS 2005 Beta 2 and was able to set the focus to any control on a web form by calling its Focus() method, for instance: btnContinue.Focus(); Today I upgraded to VS 2005...
1
by: rameshch45 | last post by:
How to set the initial focus on the cursor in my form's first field? I dont want to use javascript for that as I have many forms - is there any attribute to set?
4
by: =?ISO-8859-15?Q?Albe_V=B0?= | last post by:
In my Application, I need to make a certain graphical refresh, interrogating SqlServer, only if Application has focus (i.e. the title bar is blue). Interrogating .Focused property of various...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.