Mike, the behaviour that you are describing is a design change from Beta1 to Beta2. Let me explain the new behaviour: the LoginView control will only trigger its changing events when the template to display is different than the template that it retrieved from ViewState. Think of it as the control loading a starting template upon the first request, the anonymous template if the request was anonymous or the LoggedInTemplate if the request was authenticated. In this case, the viewchange events are NOT triggered, because there was no previously selected template to change from, the control is just picking its starting template. If in a subsequent post the control needs to change templates, then the viewchange event is triggered (because its changing from the starting template to a new template).
I attach a sample page to exemplify.
1) The first time you hit the page (a GET request) the control chooses the AnonymousTemplate (no viewchange event)
2) If you click on the "Login and Refresh" button, you will set the formsauth ticket and redirect back to the same page, which is in essence another GET. There is no viewstate, so the control is back to where it started, it needs to choose again its starting template, and in this case (since the formsauth ticket is present) it will select the LoggedInTemplate (no viewchange event). This is what happens when log in with the Login control
3) Logout of the site
4) Click on "Login" button, this will set the formsauth ticket but WILL NOT redirect
5) Now click on "Refresh". In this case the control remembers that its starting template was the AnonymousTemplate, and now needs to change rendering to LoggedInTemplate, so it must trigger its ViewChange event.
Notice that the Login control by default will Log in and redirect, which is why you don't get the change events. The nest result of this change is that if you need to modify the contents of the templates of LoginView, you no longer need to do it on the ViewChange event (unless your application expects authentication status change to occur on mid-request or no redirects after authentication status change). Instead you can do it on the regular Page_Load() event, because at that time the control is garanteed to have the correct template loaded up.
Hope this helps,
Federico Silva
Web Platform & Tools QA Team
<script runat="server">
protected void LoginView1_ViewChanged(object sender, EventArgs e)
{
Response.Write("<br>VIEWCHANGED");
}
protected void LoginView1_ViewChanging(object sender, EventArgs e)
{
Response.Write("<br>VIEWCHANGING");
}
protected void Button1_Click(object sender, EventArgs e)
{
FormsAuthentication.SetAuthCookie("farmas", false);
Response.Redirect(Request.Path);
}
protected void Button2_Click(object sender, EventArgs e)
{
FormsAuthentication.SetAuthCookie("farmas", false);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:LoginView ID="LoginView1" runat="server" OnViewChanged="LoginView1_ViewChanged" OnViewChanging="LoginView1_ViewChanging">
<LoggedInTemplate>
YOU ARE LOGGED IN
</LoggedInTemplate>
<AnonymousTemplate>
YOU ARE ANONYMOUS
</AnonymousTemplate>
</asp:LoginView>
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Login & Refresh" />
<asp:Button ID="Button2" runat="server" Text="Login" OnClick="Button2_Click" /> <asp:Button ID="Button3"
runat="server" Text="Refresh" /><br />
<br />
</div>
</form>
</body>
</html>