473,398 Members | 2,165 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,398 software developers and data experts.

Problem setting focus on a control.

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";

Then in the first step the TextBox (TextBox1) contains the word foo and in
the second step the TextBox (TextBox2) contains the word bar. As you would
expect.

However if i replace the code with

TextBox1.Focus();

and

TextBox2.Focus();

Then i get the following error and i can't understand why. This is the
first time i have used Wizard controls and i'm just trying to work out how
they behave. What am i missing about Wizard controls that is causing this
behaviour. Also it does not matter whether the textboxes are within the
wizardstep or not, you cannot seem to set the focus to any control from
within the Active event handler of the WizardStep control. If you call the
focus method from the Page_load event handler then it works fine.

Anyone any idea what is causing this, i have called the focus method from
within other event handlers such as the OnDataBound event and the OnClick
event with no problem.

A form tag with runat=server must exist on the Page to use SetFocus() or
the Focus property.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.InvalidOperationException: A form tag with
runat=server must exist on the Page to use SetFocus() or the Focus property.

Source Error:

Line 19: protected void WizardStep1_Activate(object sender, EventArgs e)
Line 20: {
Line 21: TextBox1.Focus();
Line 22:
Line 23: }
Source File:
E:\DevelopmentWebsite\IntranetDev\Portal\Testing\M ultiViewTest.aspx.cs
Line: 21

Stack Trace:

[InvalidOperationException: A form tag with runat=server must exist on the
Page to use SetFocus() or the Focus property.]
System.Web.UI.Page.SetFocus(Control control) +2021658
System.Web.UI.Control.Focus() +20
Testing_MultiViewTest.WizardStep1_Activate(Object sender, EventArgs e) in
E:\DevelopmentWebsite\IntranetDev\Portal\Testing\M ultiViewTest.aspx.cs:21
System.Web.UI.WebControls.View.OnActivate(EventArg s e) +105
System.Web.UI.WebControls.MultiView.set_ActiveView Index(Int32 value) +395
System.Web.UI.WebControls.MultiView.OnInit(EventAr gs e) +46
System.Web.UI.Control.InitRecursive(Control namingContainer) +321
System.Web.UI.Control.AddedControl(Control control, Int32 index) +2065279
System.Web.UI.ControlCollection.Add(Control child) +146
System.Web.UI.WebControls.Wizard.CreateControlHier archy() +2992
System.Web.UI.WebControls.Wizard.CreateChildContro ls() +126
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.WebControls.Wizard.OnInit(EventArgs e) +100
System.Web.UI.Control.InitRecursive(Control namingContainer) +321
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +692
Apr 11 '06 #1
1 5111
I had a similar problem to you.

I resolved mine by using the page_prerender event as you get a postback
usually on each wizard step; and using code along these lines (vb sorry!)

Select Case Wizard1.ActiveStepIndex
case 0 '1st page in wizard
textbox1.focus
Case 1 '2nd page in wizard
textbox2.Focus()
End Select

sure the c# is similar

don't know if it helps, but sorted my problem out (had same error msg)
"clickon" wrote:
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";

Then in the first step the TextBox (TextBox1) contains the word foo and in
the second step the TextBox (TextBox2) contains the word bar. As you would
expect.

However if i replace the code with

TextBox1.Focus();

and

TextBox2.Focus();

Then i get the following error and i can't understand why. This is the
first time i have used Wizard controls and i'm just trying to work out how
they behave. What am i missing about Wizard controls that is causing this
behaviour. Also it does not matter whether the textboxes are within the
wizardstep or not, you cannot seem to set the focus to any control from
within the Active event handler of the WizardStep control. If you call the
focus method from the Page_load event handler then it works fine.

Anyone any idea what is causing this, i have called the focus method from
within other event handlers such as the OnDataBound event and the OnClick
event with no problem.

A form tag with runat=server must exist on the Page to use SetFocus() or
the Focus property.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.InvalidOperationException: A form tag with
runat=server must exist on the Page to use SetFocus() or the Focus property.

Source Error:

Line 19: protected void WizardStep1_Activate(object sender, EventArgs e)
Line 20: {
Line 21: TextBox1.Focus();
Line 22:
Line 23: }
Source File:
E:\DevelopmentWebsite\IntranetDev\Portal\Testing\M ultiViewTest.aspx.cs
Line: 21

Stack Trace:

[InvalidOperationException: A form tag with runat=server must exist on the
Page to use SetFocus() or the Focus property.]
System.Web.UI.Page.SetFocus(Control control) +2021658
System.Web.UI.Control.Focus() +20
Testing_MultiViewTest.WizardStep1_Activate(Object sender, EventArgs e) in
E:\DevelopmentWebsite\IntranetDev\Portal\Testing\M ultiViewTest.aspx.cs:21
System.Web.UI.WebControls.View.OnActivate(EventArg s e) +105
System.Web.UI.WebControls.MultiView.set_ActiveView Index(Int32 value) +395
System.Web.UI.WebControls.MultiView.OnInit(EventAr gs e) +46
System.Web.UI.Control.InitRecursive(Control namingContainer) +321
System.Web.UI.Control.AddedControl(Control control, Int32 index) +2065279
System.Web.UI.ControlCollection.Add(Control child) +146
System.Web.UI.WebControls.Wizard.CreateControlHier archy() +2992
System.Web.UI.WebControls.Wizard.CreateChildContro ls() +126
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.WebControls.Wizard.OnInit(EventArgs e) +100
System.Web.UI.Control.InitRecursive(Control namingContainer) +321
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Control.InitRecursive(Control namingContainer) +198
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +692

Apr 12 '06 #2

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

Similar topics

10
by: Matt Fielder | last post by:
I have developed a custom control to be used in my application. My application includes a form designer, so the control can be hosted while designmode for the control is either true or false,...
2
by: Matt Michael | last post by:
Hi, I'm having a problem working with a listview in an application I'm writing. Currently, whenever the selectedindex changed event fires, it loads up a htmledit control, and other labels on the...
0
by: dgk | last post by:
I've tried setting the tab order using the tab order tool (VS2005) but when the form finishes loading, the focus is on the tab control and not the first textbox on the form. The textbox is inside a...
2
by: Sridhar | last post by:
Hi, I have a question. I have created a user control which contains a textbox and a button. we will enter some search word in the textbox and hit the button. Then we will get a pop-up with the...
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...
21
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
7
by: Zytan | last post by:
I want to set a control in a form to have the default focus. This is not the accept button -- that's set to a button when is 'clicked' when you press ENTER. I want a textbox to have the focus...
3
by: kelvin.koogan | last post by:
I have a number of controls on a tab page. I want to validate them all when the user tries to leave the tab. I then want to highlight the first control which fails validation. How can I do this? I...
0
by: =?Utf-8?B?SWdvcg==?= | last post by:
Hi everyone! I have some strange behavior of ListView control in WPF. We are developing application in C#. I created ListView with some items and set SelectedIndex to some index in the...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.