setfocus for UserRegistration

Topics: Developer Forum, User Forum
Dec 30, 2010 at 6:53 AM

thanks for your time
MWPSK 1.3.1

... as usual I probably miss something simple:
???    How can I set Focus on the Textbox 'UserName' in selfRegistration (CreateUser).  ???
I tried with below code (also used in Login.aspx.cs) but did not succeed

Thanks for your hints
ed

 //Control ctl = FindControl("UserName");
            //if (ctl != null)
            //{
            //    (ctl).Focus();
            //}

Jan 31, 2011 at 3:03 PM

Hi edkaufmann,

Try this in the Page_Load event;

*Note, change Login1 to the ID of your Login control.

 

if (!IsPostBack)
{
	Control ctl = Login1.FindControl("UserName");
	if (ctl != null)
	{
		(ctl).Focus();
	}
}

Bjorn

 

Feb 3, 2011 at 7:12 AM

Hi Bjorn, thanks for your time

well, I certainly tried to find a substitute for 'Login1'! ... no success!

This is in the UserRegistration.aspx:

<asp:CreateUserWizardStep runat="server" ID="createUserStep">

when using; "Control ctl = createUserStep.FindControl("UserName");" it obviously doesn't work!

which ID should I use?  

ed

Feb 3, 2011 at 7:29 AM
Edited Feb 3, 2011 at 7:50 AM

protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostBack)
      (createUserStep.ContentTemplateContainer.FindControl("UserName") as TextBox).Focus();
}

Feb 4, 2011 at 1:48 PM
Thanks Bjorn, But
whatever I try 'UserName' doesn't get Focus!
e.g. createUserStep.Focus(); createUserStep.UserName.Focus(); etc.....
below the Code I'm talking about in 'Registration.aspx'
what do I miss?!
ed
<WizardSteps>
<asp:CreateUserWizardStep runat="server" ID="createUserStep">
<ContentTemplate>











<asp:Localize runat="server" Text="<%$Resources:stringsRes, pge_UserRegistration_WizardTitle %>" />

<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ValidationGroup="createUserWizard" Display="Dynamic" ErrorMessage="<%$ Resources:stringsRes, ctl_CreateUserWizard_UserNameRequired%>"/>
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName" Text="<%$ Resources:stringsRes, ctl_CreateUserWizard_UserName%>" /> <asp:TextBox ID="UserName" runat="server" tabIndex="1" />
Feb 4, 2011 at 2:04 PM

Hi Ed,

Under your Page_Load event add:

if (!IsPostBack)
{
	Control ctl = createUserStep.ContentTemplateContainer.FindControl("UserName");
	if (ctl != null)
	{
		(ctl).Focus();
	}
}

This works for me, it should for you too.

Bjorn

Feb 4, 2011 at 2:24 PM

sorry, something went wrong with my last reply,

using:      (createUserStep.ContentTemplateContainer.FindControl("UserName") as TextBox).Focus();

sort of works  ... however only  the 2nd time I do:  login --> create user

Whether I put it inside or outside " if (!IsPostBack) "; see below code 'Registration.aspx.cs'

well will do somemore tests!
thanks ed

protected void Page_Load(object sender, EventArgs e)
 {
        if (!IsPostBack)
  {
   (createUserStep.ContentTemplateContainer.FindControl("EmailRegexValidator") as RegularExpressionValidator).ValidationExpression = Validation.EmailRegex;
   
                   createUserStep.ContentTemplateContainer.FindControl("UserName") as TextBox).Focus();
   }

                  //(createUserStep.ContentTemplateContainer.FindControl("UserName") as TextBox).Focus();

}

Feb 4, 2011 at 5:46 PM
Hi Bjorn, thanks again
it works sort of , BUT as mentioned:
when I do Login the first time and then 'create user' I do NOT get the Focus on 'UserName'
However:
when doing Login a 2nd time and 'create user' Focus IS on 'userName!
that's of course not quite what I'm looking for but will further investigate
thanks anyway ed
Feb 25, 2011 at 8:36 PM

in Page_Init

       SetFocus(Login1.FindControl("UserName"));

 

Works for me.

Feb 28, 2011 at 5:30 AM

Hi Lokh,

thanks a lot; yes this works also for me now!

ed