Hi again,
Since I don't like to give up easily, I decided to start a whole new
project. It seemed like none of the event handlers generated in the project
mentioned below worked. After starting a new project and creating the pages
and codebehinds all over again, with the exact same code, it worked.
Strange...
Inge
-----Original Message-----
From: Schepers, Inge
Sent: Monday, March 19, 2001 10:04 AM
To: ASP_Professional
Subject: [aspx_professional] CookieAuthentication using CodeBehind
possible?
Hi everyone,
Yesterday I tried the CookieAuthentication sample from the Wrox ASP+ book,
and it worked fine. I then tried the same sample with asp controls
instead of "plain" html controls, and it still worked. My code looked
like this:
<% @Language="C#" Debug=True %>
<script language="C#" runat="server">
void btnLogin_Click(Object sender, EventArgs e)
{
if(CookieAuthentication.Authenticate(txtUsername.Text,
txtPassword.Text))
{
CookieAuthentication.RedirectFromLoginPage(txtUsername.Text, true);
}
else
{
lblStatus.Text = "Invalid Login";
}
}
</script>
<html>
<head>
<title>World Of WildLife Photos - Login</title>
</head>
<body>
<form method="post" runat="server">
<table
<tr>
<td>
Username:
</td>
<td>
<asp:TextBox id="txtUsername" name="txtUsername" runat="server" />
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<asp:TextBox id="txtPassword" name="txtPassword"
TextBoxMode="Password" runat="server" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button id="btnLogin" name="btnLogin" Text="Login"
OnClick="btnLogin_Click" runat="server" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label id="lblStatus" name="lblStatus" runat="server" />
</td>
</tr>
</table>
</form>
</body>
</html>
Then, I wanted to see if I could do the same thing in a CodeBehind. I
doubleclicked my button and Visual Studio.NET generated the click even
handler for me. I added the code in the btnLogin_Click method above to
the event handler for the button in the CodeBehind but, when I tried to
debug it, it seemed like the debugger never even entered the event
handler. I did notice that the event handler created by Visual Studio.NET
was for the Button.Click event, maybe this should be OnClick? That might
explain why it seemed like the debugger never even entered the event
handler method.
Could this be a bugin Visual Studio/ASP.NET, or am I trying to do
something in a CodeBehind that can only be done directly in the ASP page?
I assumed that, since the <script> in the page runs server side, I should
be able to do it in a CodeBehind as well, but it didn't work. I am not
sure if it is the event handler that is not working, or if I just can't
access the CookieAuthentication information from the CodeBehind.
Inge