Jeff's Junk

The sillynonsense and .NET musings of Jeff Putz

News

My Sites

Buggin' on the LoginView control

I guess I'm just lucky, but I was surprised to find some bugs with the ASP.NET LoginView control and its use in VS 2005. I know it's only beta 1, but it surprised me.

First off, I can't access controls in the LoginView. So if you have:

<asp:LoginView Runat="Server" ID="TopNav">
  <AnonymousTemplate>
    <asp:TextBox ID="EmailTextBox" Runat="server" />
  </AnonymousTemplate>
</asp:LoginView>

Then when you try to access EmailTextBox, like EmailTextBox.Text = "blah" for example, it throws an exception:
CS0103: The name 'EmailTextBox' does not exist in the current context

The thing is, it's clearly in the control tree, and if you move it outside of the LoginView, it can be accessed just fine.

Related, at some point when switching between design view and source for a page, the <LoggedInTemplate> of my LoginView migrated outside of the LoginView tags, and entirely outside of the <form> tags. It happened at some point while I was editing the <AnonymousTemplate> in design view, adding controls and an HTML table.

I guess I finally earned all of my mailings!

Posted: Jul 19 2004, 01:46 PM by Jeff | with 8 comment(s)
Filed under:

Comments

Robert W. McLaws said:

You can't access it like that. You have to assess it programmatically through the TopNav object, which is the ID for your LoginView control. Migfht want to switch to design view and read the context-sensitive help.
# July 19, 2004 4:30 PM

Justin Lovell said:

It is not a bug. It is by design. Basically, they are using templates which is NOT part of the control tree UNTIL the control says it is. The control normally decides the point that the controls are part of the control tree is during the PreRender stage of the life cycle.

The better solution instead of waiting for the PreRender stage of the life cycle to come by is to migrate the controls into custom templates, port it into an user control or port it into a server control.

I am pretty much sort of time and will respond latter with more details... maybe even write a blog post about it :-).
# July 19, 2004 4:34 PM

Jeff said:

If that's "by design," then it's a crappy design. The whole idea here is to take a step out of showing some portion of the page based on whether or not the user is logged in. Prior to this I'm sure we all used Panel controls to "turn off" stuff we wanted to show by setting the Panel's Visible property to false. If this doesn't work like that, it's useless.
# July 19, 2004 7:32 PM

TrackBack said:

# July 22, 2004 6:45 PM

Robert W. McLaws said:

Um, guys....

LoginControl.UserName
LoginControl.Password

What else do you need? You can template the control at runtime. Use a skin.
# July 23, 2004 12:48 AM

Jeff said:

Um... it's not good enough?

Not only will I not use the login control, but there's a lot more to put in there, like endless examples of customized content for a logged in user.
# July 23, 2004 1:11 AM

Frank Huang said:

TextBox email = (TextBox)TopNav.FindControl("EmailTextBox") as TextBox;

if (email != null)

{

   email.Text = "blah";

}

# September 8, 2006 2:50 AM

Boris Yeltsin said:

Thanks Frank, but that solution is quite ridiculous. Not your fault, but the LoginView concept seems broken IMHO.

# September 15, 2006 9:47 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)