Page not updating after Login control authenticates

B

Bruce

I just started the design of an ASP.NET application which accesses one of
our custom web services to provide user authentication, among other
purposes.

I created a log-in page (code below), using the WebControls.Login control.
I put a simple label on the page, to display text showing whether the log-in
was successful. I populate the Label.Text from within the event handler for
the Login control's Authenticate event.

But when I run the page, the label text never shows up on the page. When I
singe step in the debugger, the Label.Text is definately set, but when the
web page is refreshed (after exiting the event handler) the Label text does
not show up on the web page.

I'm new to ASP.NET 2.0, and I assume I am confusing some aspect of the
page/postback lifecyle. Clarifications or recommendations would be greatly
appreciated.

Thanks, Bruce

---------------------------------------------


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using com.myservice;

public partial class _default : System.Web.UI.Page
{
com.myservice.ReflectionServer m_Server;
com.myservice.UserElements m_user;

protected void Page_Load(object sender, EventArgs e)
{
m_Server = new com.myservice.ReflectionServer();
}

protected void login_Authenticate(object sender, AuthenticateEventArgs e)
{
com.myservice.ReturnData result = new ReturnData();
string userName = login.UserName;
string passWord = login.Password;

result = m_Server.IsAuthenticated(userName, passWord);
if (result.Success)
{
e.Authenticated = true;

labelLogInResult.Text = "Successful Log In";
login.Enabled = false;

m_user = new UserElements();
m_user.userName = userName;
m_user.passWord = passWord;
Application["user"] = m_user;
}
else
{
login.FailureText = "Invalid Username/Password";
labelLogInResult.Text = "Invalid Username/Password";
e.Authenticated = false;
}

}
}



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="default.aspx.cs"
Inherits="_default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body style="font-size: 12pt">
<form id="form1" runat="server">
<div>
<br />
<br />
<asp:Image ID="Image1" runat="server" Height="161px"
ImageUrl="~/images-local/060508-reflection.jpg"
Width="320px" /><br />
<asp:Login ID="login" runat="server" BackColor="#F7F6F3"
BorderColor="#E6E2D8" BorderPadding="4"
BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana"
Font-Size="0.8em"
ForeColor="#333333" style="left: 319px; position: absolute; top:
232px"
OnAuthenticate="login_Authenticate" >
<TitleTextStyle BackColor="Navy" Font-Bold="True"
Font-Size="0.9em" ForeColor="White" />
<InstructionTextStyle Font-Italic="True" ForeColor="Black" />
<TextBoxStyle Font-Size="0.8em" />
<LoginButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC"
BorderStyle="Solid" BorderWidth="1px"
Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284775"
/>
</asp:Login>
<br />
<strong><span style="font-family: Tahoma; color: darkred;">User
Tasks</span></strong><br />
<br />
<span style="font-size: 11pt; font-family: Tahoma">
Create/Modify User Account<br />
Create/Remove/Modify Item<br />

</span>
<br />
<br />
<strong><span style="font-family: Tahoma; color: darkred;">
Administrator Tasks</span></strong><br />
<br />
<span style="font-size: 11pt; font-family: Tahoma">
View Raw Table Contents<br />
Remove a User<br />
Remove an Item</span><br />
<br />
<asp:Label ID="labelLogInResult" runat="server" style="left: 322px;
position: absolute; top: 384px" Height="160px"
Width="203px"></asp:Label></div>
</form>
</body>
</html>
 
C

clintonG

I can let you know about the new fast and easy way to get confirmation of
output string data by using Page.Title = "value"; which means no more need
for proxy controls or using Response.Write when running the Look and See
Visual Debugger :).

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/


Bruce said:
I just started the design of an ASP.NET application which accesses one of
our custom web services to provide user authentication, among other
purposes.

I created a log-in page (code below), using the WebControls.Login control.
I put a simple label on the page, to display text showing whether the
log-in was successful. I populate the Label.Text from within the event
handler for the Login control's Authenticate event.

But when I run the page, the label text never shows up on the page. When
I singe step in the debugger, the Label.Text is definately set, but when
the web page is refreshed (after exiting the event handler) the Label text
does not show up on the web page.

I'm new to ASP.NET 2.0, and I assume I am confusing some aspect of the
page/postback lifecyle. Clarifications or recommendations would be
greatly appreciated.

Thanks, Bruce

---------------------------------------------


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using com.myservice;

public partial class _default : System.Web.UI.Page
{
com.myservice.ReflectionServer m_Server;
com.myservice.UserElements m_user;

protected void Page_Load(object sender, EventArgs e)
{
m_Server = new com.myservice.ReflectionServer();
}

protected void login_Authenticate(object sender, AuthenticateEventArgs
e)
{
com.myservice.ReturnData result = new ReturnData();
string userName = login.UserName;
string passWord = login.Password;

result = m_Server.IsAuthenticated(userName, passWord);
if (result.Success)
{
e.Authenticated = true;

labelLogInResult.Text = "Successful Log In";
login.Enabled = false;

m_user = new UserElements();
m_user.userName = userName;
m_user.passWord = passWord;
Application["user"] = m_user;
}
else
{
login.FailureText = "Invalid Username/Password";
labelLogInResult.Text = "Invalid Username/Password";
e.Authenticated = false;
}

}
}



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="default.aspx.cs"
Inherits="_default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body style="font-size: 12pt">
<form id="form1" runat="server">
<div>
<br />
<br />
<asp:Image ID="Image1" runat="server" Height="161px"
ImageUrl="~/images-local/060508-reflection.jpg"
Width="320px" /><br />
<asp:Login ID="login" runat="server" BackColor="#F7F6F3"
BorderColor="#E6E2D8" BorderPadding="4"
BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana"
Font-Size="0.8em"
ForeColor="#333333" style="left: 319px; position: absolute;
top: 232px"
OnAuthenticate="login_Authenticate" >
<TitleTextStyle BackColor="Navy" Font-Bold="True"
Font-Size="0.9em" ForeColor="White" />
<InstructionTextStyle Font-Italic="True" ForeColor="Black" />
<TextBoxStyle Font-Size="0.8em" />
<LoginButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC"
BorderStyle="Solid" BorderWidth="1px"
Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284775"
/>
</asp:Login>
<br />
<strong><span style="font-family: Tahoma; color: darkred;">User
Tasks</span></strong><br />
<br />
<span style="font-size: 11pt; font-family: Tahoma">
Create/Modify User Account<br />
Create/Remove/Modify Item<br />

</span>
<br />
<br />
<strong><span style="font-family: Tahoma; color: darkred;">
Administrator Tasks</span></strong><br />
<br />
<span style="font-size: 11pt; font-family: Tahoma">
View Raw Table Contents<br />
Remove a User<br />
Remove an Item</span><br />
<br />
<asp:Label ID="labelLogInResult" runat="server" style="left: 322px;
position: absolute; top: 384px" Height="160px"
Width="203px"></asp:Label></div>
</form>
</body>
</html>
 
B

Bruce

I think I've found the explaination. The line "e.Authenticated = true;",
which tells the Login control that authentication was successful, triggers a
full page reload (and not a postback). As a result, the Label control is
reset to its initial state upon the reload (thus removing the "Successful
Log In" text I had assigned to it.

I'm set. Thanks for the answers.

-- Bruce
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top