0

我有一个继承母版页的内容页。我以前在很多页面上都这样做过很多次,但由于某种原因,这次它不起作用。内容页有一个 ID 为“LoginButton”的按钮,母版页中没有相同的按钮。LoginButton 有一个按钮 OnClick 事件“LoginButton_Click”,它与我的 C# 代码匹配,Visual Studio 告诉我连接是正确的。

但是,当页面运行时,LoginButton 调用母版页中完全不同的事件!它调用第一个可用的按钮方法:MasterHomeButton_Click。这种情况以前从未发生过,我已经尝试完全重建母版页和内容页,但完全没有区别。

我的 ASP 内容页面:

<%@ 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>

我的 C# 内容页面:

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";
            }       
        }
    }
}

我的 ASP 母版页:

    <%@ 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>

我的 C# 母版页:

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");
        }
    }
}
4

0 回答 0