Loading ...

I cannot figure out how to set focus on a textbox in a create user wizard control

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  web forms / data controls   » I cannot figure out how to set focus on a textbox in a create user wizard control

I cannot figure out how to set focus on a textbox in a create user wizard control

Posts under the topic: I cannot figure out how to set focus on a textbox in a create user wizard control

Posted: 6/17/2011

Lurker 360  points  Lurker
  • Joined on: 6/5/2011
  • Posts: 51

Please help.  I cannot figure hoe to set focus on a UserName TextBox in a createUserWizard control.  I tried using javascript:

 

<script
   type="text/javascript"
   language="javascript">
   document.getElementById.("UserName").focus();
</script>


Then I tried in the code behind on page load:

protected void Page_Load(object sender, EventArgs e)
{
   UserName.Focus();
}


Is it because the text box is within the template?  I am also having trouble setting focus on my user name login TextBox. It is in a modal popup.  I tried using the behavior ID and calling it with javascript to set the focus, that didn't work.  I can't get focused(lol)

 

thanks in advance!


Posted: 6/19/2011

Starter 727  points  Starter
  • Joined on: 6/6/2011
  • Posts: 74

Hi Mike,

You should add a handler to the ModalPopupExtender's add_shown event hook. It will be fired when the ModalPopupExtender is shown. Try this code:

<script type="text/javascript">
        function pageLoad(sender, e) {
            $find("ModalPopupExtender1").add_shown(function () {
                $get("TextBox1").focus();
            });
        }
</script>


Because you are using AjaxControlsToolkit you should add ToolkitScriptManager on your page, also.

First check if AjaxControlToolkit is register:

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>


Second, add this in the body of your page:

<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>

 

Best Regards,

Gjorgji Dimitrov


Posted: 6/21/2011

Lurker 360  points  Lurker
  • Joined on: 6/5/2011
  • Posts: 51
  Answered

Thank you!


Posted: 4/1/2012

Lurker 5  points  Lurker
  • Joined on: 4/1/2012
  • Posts: 1

Maybe you can try this instead of using Ajax Control Toolkit

RegisterUser.ActiveStep.FindControl("CreateUserStepContainer").FindControl("UserName").Focus();


Page 1 of 1 (4 items)