I have a content page that inherits a master page. I've done this many times before for many pages but for some reason this time it's not working. The content page has a button with ID 'LoginButton', there is no identical button in the master page. The LoginButton has a button OnClick event 'LoginButton_Click' which matches with my C# code and Visual Studio tells me that connection is correct.
However, when the page is run the LoginButton calls an entirely different event in the master page! It calls the first button method available: MasterHomeButton_Click. This has never happened before and I've tried completely rebuilding the master page and content page and it has made absolutely no difference.
My ASP content page:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/external-master.master" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="----.MasterPages.LoginPage" %>
<%@ MasterType VirtualPath="~/MasterPages/external-master.master" %>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentHolder" runat="server">
<asp:UpdatePanel ID="ContentUpdatePanel" runat="server">
<ContentTemplate>
<b>LOGIN</b>
<br />
Username: <asp:TextBox ID="UsernameInput" runat="server"></asp:TextBox>
Password: <asp:TextBox ID="PasswordInput" runat="server" TextMode="Password"></asp:TextBox>
<asp:Label ID="ErrorText" runat="server" Text=""></asp:Label>
<asp:Button ID="LoginButton" runat="server" Text="Go" OnClick="LoginButton_Click" OnClientClick="showLoading();"/>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
My C# content page:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ----.BasePageClasses;
using ----.Util;
using ----.Web;
using ----.People;
using ----.Util;
namespace ----.MasterPages
{
public partial class LoginPage : StaticBasePage
{
protected void Page_Load(object sender, EventArgs e)
{
SessionData.Clear();
}
protected void LoginButton_Click(object sender, EventArgs e)
{
try
{
TUser user = TUser.Login(UsernameInput.Text, PasswordInput.Text); //Retrieve username and password (don't remember to encrypt using Users.EncryptPassword(...) - it's handled by Users.Authenticate) and pass the username and password as parameters, which will return an object of type User.
SessionData sessionData = new SessionData(user);
sessionData.Save();
//Call Pages.GoTo(...) to change the page to the home page.
Website.GoToPage("default.aspx");
}
catch (SqlException ex)
{
Debug.Log(ex.ToString());
}
catch (InvalidUsernameException)
{
ErrorText.Text = "You cretinous fiend! Why can't you even enter your username correctly? Do it again properly - or else!";
}
catch (InvalidPasswordException)
{
ErrorText.Text = "btw m8 ur pswrd iz wrng";
}
}
}
}
My ASP master page:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="external-master.master.cs" Inherits="----.MasterPages.external_master" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel="stylesheet" type="text/css" href="../style.css"/>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<%-- Plain HTML --%>
<div id="loadingDiv" class="loadingContainer">
Loading...
</div>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager" runat="server"></asp:ScriptManager>
<asp:Button ID="MasterHomeButton" runat="server" Text="Home" OnClick="MasterHomeButton_Click" OnClientClick="showLoading();"/>
<asp:Button ID="MasterLoginButton" runat="server" Text="Login" OnClick="MasterLoginButton_Click" OnClientClick="showLoading();"/>
<asp:Button ID="MasterRegisterButton" runat="server" Text="Register" OnClick="MasterRegisterButton_Click" OnClientClick="showLoading();"/>
<br />
<br />
<asp:ContentPlaceHolder ID="ContentHolder" runat="server">
<asp:Label ID="ContentHolderLabel" runat="server" Text="Please insert content here."></asp:Label>
</asp:ContentPlaceHolder>
<asp:Label ID="ConsoleLabel" runat="server" Text=""></asp:Label>
</div>
</form>
<%-- Scripts --%>
<script>
function showLoading() {
document.getElementById('loadingDiv').style.visibility = 'visible';
}
function hideLoading() {
document.getElementById('loadingDiv').style.visibility = 'hidden';
}
</script>
</body>
</html>
My C# master page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ----.Util;
using ----.Util;
namespace ----.MasterPages
{
public partial class external_master : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(Page, GetType(), "Script", "hideLoading();", true);
new ASPConsoleDirector(ConsoleLabel);
}
protected void MasterHomeButton_Click(object sender, EventArgs e)
{
Website.GoToPage("default.aspx");
}
protected void MasterLoginButton_Click(object sender, EventArgs e)
{
Website.GoToPage("login.aspx");
}
protected void MasterRegisterButton_Click(object sender, EventArgs e)
{
Website.GoToPage("register.aspx");
}
}
}