473,507 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set Focus after Postback (vb.net newbie)

Mel
I have several text boxes and drop-down lists in an AJAX Update
Panel. All user inputs have the Postback property set to True. After
I type something in the first input entry and press the "Tab" key how
can I set the focus to the next box after the postback? Please help!

Using Visual Studio 2005 Pro, Asp.net 2.0, vb.net, WinXP
Jun 27 '08 #1
8 6888
Use ScriptManager.SetFocus (myControl).

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mel" <ML********@gmail.comwrote in message
news:45**********************************@m36g2000 hse.googlegroups.com...
>I have several text boxes and drop-down lists in an AJAX Update
Panel. All user inputs have the Postback property set to True. After
I type something in the first input entry and press the "Tab" key how
can I set the focus to the next box after the postback? Please help!

Using Visual Studio 2005 Pro, Asp.net 2.0, vb.net, WinXP

Jun 27 '08 #2
Mel
On Apr 16, 8:12 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
Use ScriptManager.SetFocus (myControl).

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"Mel" <MLights...@gmail.comwrote in message

news:45**********************************@m36g2000 hse.googlegroups.com...
I have several text boxes and drop-down lists in an AJAX Update
Panel. All user inputs have the Postback property set to True. After
I type something in the first input entry and press the "Tab" key how
can I set the focus to the next box after the postback? Please help!
Using Visual Studio 2005 Pro, Asp.net 2.0, vb.net, WinXP
THANK YOU! I wish I would have posted my question yesterday...I spent
hours sifting the web for an answer. I had Page.SetFocus(MyControl)
instead of ScriptManager.SetFocus (myControl).

Code Snippet:
Protected Sub txtCustomer_TextChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles txtCustomer.TextChanged
'customer text box (1st text box on screen)
If rfvCustomer.IsValid = True Then
Session("ProjName") = txtCustomer.Text
Else
Session("ProjName") = Nothing
End If
Session("QRNextControl") = "2"
SetNextQRControl()
End Sub
Protected Sub SetNextQRControl()
Select Case Session("QRNextControl")
Case "2"
ScriptManager1.SetFocus(txtProjAddr1) 'address 1 text
box
Case "3"
ScriptManager1.SetFocus(txtProjAddr2) 'address 2 text
box
Case "4"
ScriptManager1.SetFocus(txtProjCity) 'city text box
Case "5"
ScriptManager1.SetFocus(ddlStAbrv) 'state text box
Case "6"
ScriptManager1.SetFocus(txtZip) 'zip text box
Case "7"
ScriptManager1.SetFocus(txtCusContact) 'customer
Contact text box
Case "8"
ScriptManager1.SetFocus(txtCusPhone) 'customer Phone
text box
Case "9"
ScriptManager1.SetFocus(txtProjName) 'project Name
text box
Case "10"
ScriptManager1.SetFocus(rblPriceAdj) 'price
Adjustment text box
End Select
Session("QRNextControl") = ""
End Sub
Jun 27 '08 #3
>I wish I would have posted my question yesterday...I spent hours sifting
>the web for an answer.
This is the only way of getting experience known to me.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mel" <ML********@gmail.comwrote in message
news:8c**********************************@y21g2000 hsf.googlegroups.com...
On Apr 16, 8:12 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
>Use ScriptManager.SetFocus (myControl).

--
Eliyahu Goldin,
Software Developer
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"Mel" <MLights...@gmail.comwrote in message

news:45**********************************@m36g200 0hse.googlegroups.com...
>I have several text boxes and drop-down lists in an AJAX Update
Panel. All user inputs have the Postback property set to True. After
I type something in the first input entry and press the "Tab" key how
can I set the focus to the next box after the postback? Please help!
Using Visual Studio 2005 Pro, Asp.net 2.0, vb.net, WinXP

THANK YOU! I wish I would have posted my question yesterday...I spent
hours sifting the web for an answer. I had Page.SetFocus(MyControl)
instead of ScriptManager.SetFocus (myControl).

Code Snippet:
Protected Sub txtCustomer_TextChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles txtCustomer.TextChanged
'customer text box (1st text box on screen)
If rfvCustomer.IsValid = True Then
Session("ProjName") = txtCustomer.Text
Else
Session("ProjName") = Nothing
End If
Session("QRNextControl") = "2"
SetNextQRControl()
End Sub
Protected Sub SetNextQRControl()
Select Case Session("QRNextControl")
Case "2"
ScriptManager1.SetFocus(txtProjAddr1) 'address 1 text
box
Case "3"
ScriptManager1.SetFocus(txtProjAddr2) 'address 2 text
box
Case "4"
ScriptManager1.SetFocus(txtProjCity) 'city text box
Case "5"
ScriptManager1.SetFocus(ddlStAbrv) 'state text box
Case "6"
ScriptManager1.SetFocus(txtZip) 'zip text box
Case "7"
ScriptManager1.SetFocus(txtCusContact) 'customer
Contact text box
Case "8"
ScriptManager1.SetFocus(txtCusPhone) 'customer Phone
text box
Case "9"
ScriptManager1.SetFocus(txtProjName) 'project Name
text box
Case "10"
ScriptManager1.SetFocus(rblPriceAdj) 'price
Adjustment text box
End Select
Session("QRNextControl") = ""
End Sub

Jun 27 '08 #4
Mel
On Apr 16, 8:45 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
I wish I would have posted my question yesterday...I spent hours sifting
the web for an answer.

This is the only way of getting experience known to me.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"Mel" <MLights...@gmail.comwrote in message

news:8c**********************************@y21g2000 hsf.googlegroups.com...
On Apr 16, 8:12 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
Use ScriptManager.SetFocus (myControl).
--
Eliyahu Goldin,
Software Developer
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"Mel" <MLights...@gmail.comwrote in message
>news:45**********************************@m36g200 0hse.googlegroups.com...
I have several text boxes and drop-down lists in an AJAX Update
Panel. All user inputs have the Postback property set to True. After
I type something in the first input entry and press the "Tab" key how
can I set the focus to the next box after the postback? Please help!
Using Visual Studio 2005 Pro, Asp.net 2.0, vb.net, WinXP
THANK YOU! I wish I would have posted my question yesterday...I spent
hours sifting the web for an answer. I had Page.SetFocus(MyControl)
instead of ScriptManager.SetFocus (myControl).
Code Snippet:
Protected Sub txtCustomer_TextChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles txtCustomer.TextChanged
'customer text box (1st text box on screen)
If rfvCustomer.IsValid = True Then
Session("ProjName") = txtCustomer.Text
Else
Session("ProjName") = Nothing
End If
Session("QRNextControl") = "2"
SetNextQRControl()
End Sub
Protected Sub SetNextQRControl()
Select Case Session("QRNextControl")
Case "2"
ScriptManager1.SetFocus(txtProjAddr1) 'address 1 text
box
Case "3"
ScriptManager1.SetFocus(txtProjAddr2) 'address 2 text
box
Case "4"
ScriptManager1.SetFocus(txtProjCity) 'city text box
Case "5"
ScriptManager1.SetFocus(ddlStAbrv) 'state text box
Case "6"
ScriptManager1.SetFocus(txtZip) 'zip text box
Case "7"
ScriptManager1.SetFocus(txtCusContact) 'customer
Contact text box
Case "8"
ScriptManager1.SetFocus(txtCusPhone) 'customer Phone
text box
Case "9"
ScriptManager1.SetFocus(txtProjName) 'project Name
text box
Case "10"
ScriptManager1.SetFocus(rblPriceAdj) 'price
Adjustment text box
End Select
Session("QRNextControl") = ""
End Sub
It works great. One small glitch though.
Lets say there are 3 text boxes. If you type some data in the 1st
text box and then instead of pressing the tab key you click your mouse
in the 3rd text box, after the postback the cursor is sitting in the
2nd text box. Not the 3rd one.
Jun 27 '08 #5
You can handle client side onfocus event to set a hidden text control to the
id of the element that got focus. On server side, you can set focus based on
the passed id as opposed to the session variable.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mel" <ML********@gmail.comwrote in message
news:84**********************************@m1g2000p re.googlegroups.com...
On Apr 16, 8:45 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
>I wish I would have posted my question yesterday...I spent hours sifting
the web for an answer.

This is the only way of getting experience known to me.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"Mel" <MLights...@gmail.comwrote in message

news:8c**********************************@y21g200 0hsf.googlegroups.com...
On Apr 16, 8:12 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
Use ScriptManager.SetFocus (myControl).
>--
Eliyahu Goldin,
Software Developer
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
>"Mel" <MLights...@gmail.comwrote in message
>>news:45**********************************@m36g20 00hse.googlegroups.com...
>I have several text boxes and drop-down lists in an AJAX Update
Panel. All user inputs have the Postback property set to True.
After
I type something in the first input entry and press the "Tab" key
how
can I set the focus to the next box after the postback? Please
help!
Using Visual Studio 2005 Pro, Asp.net 2.0, vb.net, WinXP
THANK YOU! I wish I would have posted my question yesterday...I spent
hours sifting the web for an answer. I had Page.SetFocus(MyControl)
instead of ScriptManager.SetFocus (myControl).
Code Snippet:
Protected Sub txtCustomer_TextChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles txtCustomer.TextChanged
'customer text box (1st text box on screen)
If rfvCustomer.IsValid = True Then
Session("ProjName") = txtCustomer.Text
Else
Session("ProjName") = Nothing
End If
Session("QRNextControl") = "2"
SetNextQRControl()
End Sub
Protected Sub SetNextQRControl()
Select Case Session("QRNextControl")
Case "2"
ScriptManager1.SetFocus(txtProjAddr1) 'address 1 text
box
Case "3"
ScriptManager1.SetFocus(txtProjAddr2) 'address 2 text
box
Case "4"
ScriptManager1.SetFocus(txtProjCity) 'city text box
Case "5"
ScriptManager1.SetFocus(ddlStAbrv) 'state text box
Case "6"
ScriptManager1.SetFocus(txtZip) 'zip text box
Case "7"
ScriptManager1.SetFocus(txtCusContact) 'customer
Contact text box
Case "8"
ScriptManager1.SetFocus(txtCusPhone) 'customer Phone
text box
Case "9"
ScriptManager1.SetFocus(txtProjName) 'project Name
text box
Case "10"
ScriptManager1.SetFocus(rblPriceAdj) 'price
Adjustment text box
End Select
Session("QRNextControl") = ""
End Sub

It works great. One small glitch though.
Lets say there are 3 text boxes. If you type some data in the 1st
text box and then instead of pressing the tab key you click your mouse
in the 3rd text box, after the postback the cursor is sitting in the
2nd text box. Not the 3rd one.

Jun 27 '08 #6
Mel
On Apr 17, 3:35 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
You can handle client side onfocus event to set a hidden text control to the
id of the element that got focus. On server side, you can set focus based on
the passed id as opposed to the session variable.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"Mel" <MLights...@gmail.comwrote in message

news:84**********************************@m1g2000p re.googlegroups.com...
On Apr 16, 8:45 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
I wish I would have posted my question yesterday...I spent hours sifting
the web for an answer.
This is the only way of getting experience known to me.
--
Eliyahu Goldin,
Software Developer
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"Mel" <MLights...@gmail.comwrote in message
>news:8c**********************************@y21g200 0hsf.googlegroups.com...
On Apr 16, 8:12 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
Use ScriptManager.SetFocus (myControl).
--
Eliyahu Goldin,
Software Developer
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"Mel" <MLights...@gmail.comwrote in message
>news:45**********************************@m36g200 0hse.googlegroups.com...
I have several text boxes and drop-down lists in an AJAX Update
Panel. All user inputs have the Postback property set to True.
After
I type something in the first input entry and press the "Tab" key
how
can I set the focus to the next box after the postback? Please
help!
Using Visual Studio 2005 Pro, Asp.net 2.0, vb.net, WinXP
THANK YOU! I wish I would have posted my question yesterday...I spent
hours sifting the web for an answer. I had Page.SetFocus(MyControl)
instead of ScriptManager.SetFocus (myControl).
Code Snippet:
Protected Sub txtCustomer_TextChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles txtCustomer.TextChanged
'customer text box (1st text box on screen)
If rfvCustomer.IsValid = True Then
Session("ProjName") = txtCustomer.Text
Else
Session("ProjName") = Nothing
End If
Session("QRNextControl") = "2"
SetNextQRControl()
End Sub
Protected Sub SetNextQRControl()
Select Case Session("QRNextControl")
Case "2"
ScriptManager1.SetFocus(txtProjAddr1) 'address 1 text
box
Case "3"
ScriptManager1.SetFocus(txtProjAddr2) 'address 2 text
box
Case "4"
ScriptManager1.SetFocus(txtProjCity) 'city text box
Case "5"
ScriptManager1.SetFocus(ddlStAbrv) 'state text box
Case "6"
ScriptManager1.SetFocus(txtZip) 'zip text box
Case "7"
ScriptManager1.SetFocus(txtCusContact) 'customer
Contact text box
Case "8"
ScriptManager1.SetFocus(txtCusPhone) 'customer Phone
text box
Case "9"
ScriptManager1.SetFocus(txtProjName) 'project Name
text box
Case "10"
ScriptManager1.SetFocus(rblPriceAdj) 'price
Adjustment text box
End Select
Session("QRNextControl") = ""
End Sub
It works great. One small glitch though.
Lets say there are 3 text boxes. If you type some data in the 1st
text box and then instead of pressing the tab key you click your mouse
in the 3rd text box, after the postback the cursor is sitting in the
2nd text box. Not the 3rd one.
Sorry to be a pain. I am using a Textbox control. Will I need to use
a different control instead to get an OnFocus method?
Jun 27 '08 #7
No, you can attach a client-side event handler like
myTextBox.Attributes["onfocus"] = "gotFocus(this)";

and in .aspx file:
<input type = "hidden" runat="server" id="inhControlWithFocus" />

and in javascript
function gotFocus(control)
{
myForm.inhControlWithFocus.value = control.Id;
}

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Mel" <ML********@gmail.comwrote in message
news:3a**********************************@c65g2000 hsa.googlegroups.com...
On Apr 17, 3:35 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
>You can handle client side onfocus event to set a hidden text control to
the
id of the element that got focus. On server side, you can set focus based
on
the passed id as opposed to the session variable.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"Mel" <MLights...@gmail.comwrote in message

news:84**********************************@m1g2000 pre.googlegroups.com...
On Apr 16, 8:45 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
I wish I would have posted my question yesterday...I spent hours
sifting
the web for an answer.
>This is the only way of getting experience known to me.
>--
Eliyahu Goldin,
Software Developer
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
>"Mel" <MLights...@gmail.comwrote in message
>>news:8c**********************************@y21g20 00hsf.googlegroups.com...
On Apr 16, 8:12 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
Use ScriptManager.SetFocus (myControl).
>--
Eliyahu Goldin,
Software Developer
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
>"Mel" <MLights...@gmail.comwrote in message
>>news:45**********************************@m36g20 00hse.googlegroups.com...
>I have several text boxes and drop-down lists in an AJAX Update
Panel. All user inputs have the Postback property set to True.
After
I type something in the first input entry and press the "Tab" key
how
can I set the focus to the next box after the postback? Please
help!
Using Visual Studio 2005 Pro, Asp.net 2.0, vb.net, WinXP
THANK YOU! I wish I would have posted my question yesterday...I
spent
hours sifting the web for an answer. I had Page.SetFocus(MyControl)
instead of ScriptManager.SetFocus (myControl).
Code Snippet:
Protected Sub txtCustomer_TextChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles txtCustomer.TextChanged
'customer text box (1st text box on screen)
If rfvCustomer.IsValid = True Then
Session("ProjName") = txtCustomer.Text
Else
Session("ProjName") = Nothing
End If
Session("QRNextControl") = "2"
SetNextQRControl()
End Sub
Protected Sub SetNextQRControl()
Select Case Session("QRNextControl")
Case "2"
ScriptManager1.SetFocus(txtProjAddr1) 'address 1 text
box
Case "3"
ScriptManager1.SetFocus(txtProjAddr2) 'address 2 text
box
Case "4"
ScriptManager1.SetFocus(txtProjCity) 'city text box
Case "5"
ScriptManager1.SetFocus(ddlStAbrv) 'state text box
Case "6"
ScriptManager1.SetFocus(txtZip) 'zip text box
Case "7"
ScriptManager1.SetFocus(txtCusContact) 'customer
Contact text box
Case "8"
ScriptManager1.SetFocus(txtCusPhone) 'customer Phone
text box
Case "9"
ScriptManager1.SetFocus(txtProjName) 'project Name
text box
Case "10"
ScriptManager1.SetFocus(rblPriceAdj) 'price
Adjustment text box
End Select
Session("QRNextControl") = ""
End Sub
It works great. One small glitch though.
Lets say there are 3 text boxes. If you type some data in the 1st
text box and then instead of pressing the tab key you click your mouse
in the 3rd text box, after the postback the cursor is sitting in the
2nd text box. Not the 3rd one.

Sorry to be a pain. I am using a Textbox control. Will I need to use
a different control instead to get an OnFocus method?

Jun 27 '08 #8
Mel
On Apr 17, 8:57 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
No, you can attach a client-side event handler like
myTextBox.Attributes["onfocus"] = "gotFocus(this)";

and in .aspx file:
<input type = "hidden" runat="server" id="inhControlWithFocus" />

and in javascript
function gotFocus(control)
{
myForm.inhControlWithFocus.value = control.Id;

}

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

"Mel" <MLights...@gmail.comwrote in message

news:3a**********************************@c65g2000 hsa.googlegroups.com...
On Apr 17, 3:35 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
You can handle client side onfocus event to set a hidden text control to
the
id of the element that got focus. On server side, you can set focus based
on
the passed id as opposed to the session variable.
--
Eliyahu Goldin,
Software Developer
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"Mel" <MLights...@gmail.comwrote in message
>news:84**********************************@m1g2000 pre.googlegroups.com...
On Apr 16, 8:45 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
I wish I would have posted my question yesterday...I spent hours
sifting
the web for an answer.
This is the only way of getting experience known to me.
--
Eliyahu Goldin,
Software Developer
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"Mel" <MLights...@gmail.comwrote in message
>news:8c**********************************@y21g200 0hsf.googlegroups.com...
On Apr 16, 8:12 am, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
Use ScriptManager.SetFocus (myControl).
--
Eliyahu Goldin,
Software Developer
Microsoft MVP
[ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
"Mel" <MLights...@gmail.comwrote in message
>news:45**********************************@m36g200 0hse.googlegroups.com...
I have several text boxes and drop-down lists in an AJAX Update
Panel. All user inputs have the Postback property set to True.
After
I type something in the first input entry and press the "Tab" key
how
can I set the focus to the next box after the postback? Please
help!
Using Visual Studio 2005 Pro, Asp.net 2.0, vb.net, WinXP
THANK YOU! I wish I would have posted my question yesterday...I
spent
hours sifting the web for an answer. I had Page.SetFocus(MyControl)
instead of ScriptManager.SetFocus (myControl).
Code Snippet:
Protected Sub txtCustomer_TextChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles txtCustomer.TextChanged
'customer text box (1st text box on screen)
If rfvCustomer.IsValid = True Then
Session("ProjName") = txtCustomer.Text
Else
Session("ProjName") = Nothing
End If
Session("QRNextControl") = "2"
SetNextQRControl()
End Sub
Protected Sub SetNextQRControl()
Select Case Session("QRNextControl")
Case "2"
ScriptManager1.SetFocus(txtProjAddr1) 'address 1 text
box
Case "3"
ScriptManager1.SetFocus(txtProjAddr2) 'address 2 text
box
Case "4"
ScriptManager1.SetFocus(txtProjCity) 'city text box
Case "5"
ScriptManager1.SetFocus(ddlStAbrv) 'state text box
Case "6"
ScriptManager1.SetFocus(txtZip) 'zip text box
Case "7"
ScriptManager1.SetFocus(txtCusContact) 'customer
Contact text box
Case "8"
ScriptManager1.SetFocus(txtCusPhone) 'customer Phone
text box
Case "9"
ScriptManager1.SetFocus(txtProjName) 'project Name
text box
Case "10"
ScriptManager1.SetFocus(rblPriceAdj) 'price
Adjustment text box
End Select
Session("QRNextControl") = ""
End Sub
It works great. One small glitch though.
Lets say there are 3 text boxes. If you type some data in the 1st
text box and then instead of pressing the tab key you click your mouse
in the 3rd text box, after the postback the cursor is sitting in the
2nd text box. Not the 3rd one.
Sorry to be a pain. I am using a Textbox control. Will I need to use
a different control instead to get an OnFocus method?
The hidden text box always says "undefined". I am doing something
wrong.

<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Set Focus - AJAX Script Manager and Update Panel</title>
</head>
<script type="text/javascript">
function gotFocus(control)
{

document.getElementById("inhControlWithFocus").val ue=control.Id;
}
</script>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
&nbsp;
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"
AutoPostBack="True" OnTextChanged="TextBox1_TextChanged"
TabIndex="1"></asp:TextBox><br />
<br />
<asp:TextBox ID="TextBox2" runat="server"
AutoPostBack="True" OnTextChanged="TextBox2_TextChanged"
TabIndex="2"></asp:TextBox><br />
<br />
<asp:TextBox ID="TextBox3" runat="server"
AutoPostBack="True" OnTextChanged="TextBox3_TextChanged"
TabIndex="3"></asp:TextBox><br />
<br />
<input runat="server" id="inhControlWithFocus" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
TextBox1.Attributes("onfocus") = "gotFocus(this)"
TextBox2.Attributes("onfocus") = "gotFocus(this)"
TextBox3.Attributes("onfocus") = "gotFocus(this)"
End Sub
Protected Sub SetNextQRControl()
ScriptManager1.SetFocus(inhControlWithFocus.ID)
End Sub
Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e
As System.EventArgs)
'Session("QRNextControl") = 2
SetNextQRControl()
End Sub

Protected Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e
As System.EventArgs)
'Session("QRNextControl") = 3
SetNextQRControl()
End Sub

Protected Sub TextBox3_TextChanged(ByVal sender As Object, ByVal e
As System.EventArgs)
'Session("QRNextControl") = 1
SetNextQRControl()
End Sub
End Class
Jun 27 '08 #9

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

Similar topics

2
5179
by: Marco Liedekerken | last post by:
Hi, Is it possible to retrieve the control that had the focus when the page was posted back? Because the focus is lost when a postback occurs I want to manually set the focus to the control...
2
2415
by: Elliot M. Rodriguez | last post by:
Is it possible to change a control's focus at runtime? I'm sure you can.... I have a form with 2 textbox controls that cause postbacks. They are located in the middle of my form. When a...
3
1637
by: Dexter | last post by:
Hello All, I have a web control that when receive the focus, a postback is called, using getPostBackEventReference. But, when the PostBack is called, i want that the focus goes to the web control....
4
2113
by: kpg | last post by:
After an autopostback event the control that gets focus next is not the one defined in the taborder, but the first control. This makes sense becuase the page is reloaded, but of course this is...
1
1175
by: psual | last post by:
Hi I have a page (1st page) with a button. this button opens a new page (2nd page) in full-screen mode. The problem is that the 2nd page is always loaded before the postback of the 1st page,...
5
2023
by: Finn Stampe Mikkelsen | last post by:
Hi How can i set a focus to a textbox in my codebehind page?? I have this WebForm, that takes information from a user and 2 buttons on the form. One that takes action on the entered...
2
3859
by: Rey | last post by:
Howdy all. Using visual web developer (VB) on xp pro box. My problem with with a web form that on accessing the calendar control causes a postback that moves the cursor back to the txtFirstName...
2
3428
by: tomwilliams | last post by:
Hi I have created a website which has a number of buttons on it which allow users to add items to there basket, they then click on an AJAX watermarked textbox to set focus before using a keyboard...
1
5325
by: Jeff | last post by:
hi asp.net 3.5 (project upgraded from asp.net 2.0). are using vwd2008 express now This is my first ajax attempt. The code below shows a TextBox and a ListBox. The idea I was trying to...
0
7223
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
7314
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
7372
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...
1
7030
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
5623
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,...
0
3191
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1540
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 ...
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.