Problem setting focus on a control.

G

Guest

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\MultiViewTest.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\MultiViewTest.aspx.cs:21
System.Web.UI.WebControls.View.OnActivate(EventArgs e) +105
System.Web.UI.WebControls.MultiView.set_ActiveViewIndex(Int32 value) +395
System.Web.UI.WebControls.MultiView.OnInit(EventArgs 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.CreateControlHierarchy() +2992
System.Web.UI.WebControls.Wizard.CreateChildControls() +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
 
G

Guest

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 said:
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\MultiViewTest.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\MultiViewTest.aspx.cs:21
System.Web.UI.WebControls.View.OnActivate(EventArgs e) +105
System.Web.UI.WebControls.MultiView.set_ActiveViewIndex(Int32 value) +395
System.Web.UI.WebControls.MultiView.OnInit(EventArgs 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.CreateControlHierarchy() +2992
System.Web.UI.WebControls.Wizard.CreateChildControls() +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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top