DanielBorson
asked on
Default control focus in ASP.NET 2.0 Wizard on page using Master template
In ASP.NET 2.0, I have a Wizard control that is inside of an <asp:Content> tag. The <form> tag is in a Master template file. My question is how can I set a textbox to have default focus? When I try to do it from the code-behind by using "textbox.Focus()" I get an error that there is no Form, and therefore the focus cannot be set. On other pages that also use the Master template, I employ client-side JavaScript to set focus, but since this is a Wizard control, there would be several controls that would need default focus at different steps in the Wizard.
I've thought of a workaround by having a hidden textobx with the Wizard ActiveStepIndex and a switch/case in the client-side JavaScript that would set the focus to different controls, based on the ActiveStepIndex, but that seems like a bigger workaround than should be necessary. Is there another (and simpler) way to do this?
I've thought of a workaround by having a hidden textobx with the Wizard ActiveStepIndex and a switch/case in the client-side JavaScript that would set the focus to different controls, based on the ActiveStepIndex, but that seems like a bigger workaround than should be necessary. Is there another (and simpler) way to do this?
ASKER
Doesn't work. Here's the error I'm getting:
"A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property."
The "FindControl" is finding the textbox just fine. I can see it in the watch when I do "Wizard.FindControl("textb ox")". But in watch, "this.Form" is null. The form tag is in the Master, and it does have a runat="server" attribute.
I'm not sure what's going on. Can you enlighten me?
"A form tag with runat=server must exist on the Page to use SetFocus() or the Focus property."
The "FindControl" is finding the textbox just fine. I can see it in the watch when I do "Wizard.FindControl("textb
I'm not sure what's going on. Can you enlighten me?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
My Javascript may be incorrect....it may need to be:
"<script language='javascript'>docu ment.getEl ementById( '" & strID & "').focus();</script>"
"<script language='javascript'>docu
set focus