Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Can we set focus in UserName of a LoginView

Reply
Thread Tools

Can we set focus in UserName of a LoginView

 
 
ad
Guest
Posts: n/a
 
      09-21-2005
I use a LoginView to authenticate user.
Can we set the focus in the UserName or Password of the LoginView?


 
Reply With Quote
 
 
 
 
needin4mation@gmail.com
Guest
Posts: n/a
 
      09-21-2005
here is one I found and modified it for csharp:

private void SetFocusControl(String ControlName)
{
//http://www.developer.com/net/asp/article.php/2237431
//character 34 = "

String script = "<script language=\"javascript\""+
">" +
" var control = document.getElementById(\"" +
ControlName + "\");" +
" if( control != null ){control.focus();}" +
"</script>";

Page.RegisterStartupScript("Focus", script);
}

 
Reply With Quote
 
 
 
 
Juan T. Llibre
Guest
Posts: n/a
 
      09-21-2005
See :

http://ryanfarley.com/blog/archive/2004/12/21/1325.aspx



Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"ad" <(E-Mail Removed)> wrote in message
news:u3cR%(E-Mail Removed)...
>I use a LoginView to authenticate user.
> Can we set the focus in the UserName or Password of the LoginView?



 
Reply With Quote
 
ad
Guest
Posts: n/a
 
      09-21-2005
Thanks,
If the UserName control is general textbox, It can do by SetFocus or
Javascript.
But now the UserName is in LoginView.
How can I do?


"Juan T. Llibre" <(E-Mail Removed)> ¼¶¼g©ó¶l¥ó·s»D:(E-Mail Removed) bl...
> See :
>
> http://ryanfarley.com/blog/archive/2004/12/21/1325.aspx
>
>
>
> Juan T. Llibre, ASP.NET MVP
> ASP.NET FAQ : http://asp.net.do/faq/
> Foros de ASP.NET en Español : http://asp.net.do/foros/
> ======================================
> "ad" <(E-Mail Removed)> wrote in message
> news:u3cR%(E-Mail Removed)...
>>I use a LoginView to authenticate user.
>> Can we set the focus in the UserName or Password of the LoginView?

>
>



 
Reply With Quote
 
jnewquis jnewquis is offline
Junior Member
Join Date: Jun 2006
Posts: 1
 
      06-27-2006
I also had this page inside a master.page but this is what worked for me in the PreRender event ...



Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

'Find the Login control inside the LoginView
Dim curLogin As System.Web.UI.WebControls.Login = CType(LoginView1.FindControl("Login1"), System.Web.UI.WebControls.Login)

'Then find the Username textbox control
Dim txtUsername As TextBox = CType(curLogin.FindControl("UserName"), TextBox)

'Now set the focus on it
txtUsername.Focus()
End Sub
 
Reply With Quote
 
jostar jostar is offline
Junior Member
Join Date: Mar 2007
Posts: 1
 
      03-21-2007
Thanks for the ideas in VB.

Here is a C# solution that workes for me.

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if(!User.Identity.IsAuthenticated)
{
Login lg = (Login)LoginView1.FindControl("Login1");
TextBox tb = (TextBox)lg.FindControl("UserName");
SetFocus(tb);
}
}
}

BTW notice that tb does not have double quotes around it in the SetFocus (tb). I was pulling my hair out following another thread that had quotes around the control string inside the SetFocus method. If I can find that post again, I'll put in a correction there too!

John
 
Reply With Quote
 
talcott talcott is offline
Junior Member
Join Date: Dec 2007
Posts: 1
 
      12-26-2007
Quote:
Originally Posted by jnewquis
I also had this page inside a master.page but this is what worked for me in the PreRender event ...



Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

'Find the Login control inside the LoginView
Dim curLogin As System.Web.UI.WebControls.Login = CType(LoginView1.FindControl("Login1"), System.Web.UI.WebControls.Login)

'Then find the Username textbox control
Dim txtUsername As TextBox = CType(curLogin.FindControl("UserName"), TextBox)

'Now set the focus on it
txtUsername.Focus()
End Sub

Hi! This really works. Thanks
 
Reply With Quote
 
Suresh16 Suresh16 is offline
Junior Member
Join Date: Mar 2009
Posts: 1
 
      03-17-2009
it is working in IE but not working in Firefox.
I do something like this:
TextBox usernametxt = (TextBox)this.logOn.FindControl("UserName");
SetFocus(usernametxt);

on the aspx page I have code like this....
<asp:Login ID="logOn" runat="server".......>
<LayoutTemplate>
......
<asp:TextBox ID="UserName" runat="server" Width="250" TabIndex="1"></asp:TextBox>
......
</LayoutTemplate>
</asp:Login>

Can someone help me with this?
Quote:
Originally Posted by jostar
Thanks for the ideas in VB.

Here is a C# solution that workes for me.

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if(!User.Identity.IsAuthenticated)
{
Login lg = (Login)LoginView1.FindControl("Login1");
TextBox tb = (TextBox)lg.FindControl("UserName");
SetFocus(tb);
}
}
}

BTW notice that tb does not have double quotes around it in the SetFocus (tb). I was pulling my hair out following another thread that had quotes around the control string inside the SetFocus method. If I can find that post again, I'll put in a correction there too!

John
 
Reply With Quote
 
blad3runn69 blad3runn69 is offline
Junior Member
Join Date: Jun 2010
Posts: 1
 
      06-10-2010
thank you very much jnewquis, very much appreciated.
linked to msdn community content - LoginView.Focus Method

thanks again jnewquis
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
this.window.focus() vs. window.focus() vs. this.focus() Roger Javascript 3 03-08-2007 08:53 PM
loginview control displays network username instead of (web) username Shailesh Patel ASP .Net Web Controls 0 11-08-2006 08:19 PM
Can't access webpage's controls from the code-behind file after putting it in a <asp:LoginView/> Jack ASP .Net Web Controls 1 07-03-2006 01:54 PM
Why does putting focus on textbox also set focus to submit jw56578@gmail.com Javascript 2 06-06-2005 08:20 PM
Change the username found in "C:\Documents and Settings\Username" The Reluctant Robot Named Jude Computer Support 1 05-05-2004 07:11 AM



Advertisments