Posted: 6/17/2011
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
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
Thank you!
Posted: 4/1/2012
Maybe you can try this instead of using Ajax Control Toolkit
RegisterUser.ActiveStep.FindControl("CreateUserStepContainer").FindControl("UserName").Focus();