0

I have a simple loginview on a webpage. If a user is logged out they are prompted with a login control. If they do, I have a label in the LoggedInTemplate with no text value. I have programmatically set a text value through the ViewChanged Event. However, when I log in, nothing appears. It seems to me, that the ViewChanged Event is not firing. My code is in the file attached.

Thank you

Robert

Attachments
Partial Class Default3   
    Inherits System.Web.UI.Page   
  
    Protected Sub LoginButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)   
  
        Dim UserNameTextBox As New TextBox   
        UserNameTextBox = DirectCast(LoginView1.FindControl("TextBox13"), TextBox)   
        Dim PasswordTextBox As New TextBox   
        PasswordTextBox = DirectCast(LoginView1.FindControl("TextBox14"), TextBox)   
        Dim RememberMeCheckBox As New CheckBox   
        RememberMeCheckBox = DirectCast(LoginView1.FindControl("CheckBox1"), CheckBox)   
  
  
        'Validate the user against the Membership framework user store   
        If Membership.ValidateUser(UserNameTextBox.Text, PasswordTextBox.Text) Then  
  
            'Log the user into the site   
            FormsAuthentication.RedirectFromLoginPage(UserNameTextBox.Text, RememberMeCheckBox.Checked)   
            Response.Redirect("Default3.aspx")   
  
        End If  
  
    End Sub  
  
    Protected Sub LoginView1_ViewChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles LoginView1.ViewChanged   
  
        Dim TestLabel As New Label   
        TestLabel = CType(LoginView1.FindControl("Label27"), Label)   
        TestLabel.Text = "You are logged in"  
  
    End Sub  
  
End Class  


And from the .aspx file:  

<%@ Page Language="VB" MasterPageFile="~/Bitsandbobs.master" AutoEventWireup="false" CodeFile="Default3.aspx.vb" Inherits="Default3" title="Untitled Page" %>   
  
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">   
<asp:LoginView ID="LoginView1" OnViewChanged="LoginView1_ViewChanged" runat="server">   
                <LoggedInTemplate>   
                    <asp:Label ID="Label27" runat="server"></asp:Label>   
                </LoggedInTemplate>   
                <AnonymousTemplate>   
                    <table border="0" cellpadding="0" cellspacing="0" style="width: 400px">   
                        <tr>   
                            <td style="text-align: center">   
                                <span class="headingtext">For online bookings, please login</span><br />   
                                <br />   
                                <asp:Label ID="Label26" runat="server" Text="Username"></asp:Label>   
                                    
                                <asp:TextBox ID="TextBox13" runat="server"></asp:TextBox>   
                                <br />   
                                <br />   
                                Password:    
                                <asp:TextBox ID="TextBox14" runat="server"></asp:TextBox>   
                                <br />   
                                <br />   
                                <asp:CheckBox ID="CheckBox1" runat="server" Text="Remember Me" />   
                                <br />   
                                <br />   
                                <asp:Button ID="LoginButton" runat="server" onclick="LoginButton_Click"    
                                    PostBackUrl="~/Default3.aspx" Text="Login" />   
                                <br />   
                            </td>   
                        </tr>   
                    </table>   
                </AnonymousTemplate>   
                </asp:LoginView>   
</asp:Content>
2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Ramesh S
0

MSDN Documentation says...

The ViewChanged event is only raised if the login status for a user changes during a postback to the page. The ViewChanged event will not be raised if a user logs in using the Login control, or if the user logs out using the LoginStatus control. The ViewChanged event will also not occur if a user is logged in or out followed by a redirect.

As mentioned by you, the ViewChanged event will not occur when you logs-in and therefore nothing will be displayed in the Label in the LoggedInTemplate.

0

Cool,

So what can we do to make sure that it does fire?

Regards

Rob

0

Refer this link. http://forums.asp.net/p/899295/978972.aspx#978972

It clearly tells about when the change events will occur in the LoginView control with sample scenario. Though the thread discuss about LoginView control in the beta 2 version, there is no much difference between beta 2 and current version(RTM) of LoginView ViewChange events.

You can then change your code accordingly based on your requirement .

Edited by Ramesh S: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.