如何使用asp.net c#中的母版页从一个网页调用方法(函数)到另一个网页

问题描述 投票:0回答:1

我创建了一个母版页

Login_Nav
并使用母版页
(AuthenticationMethods.aspx,password.aspx)
创建了两个
Login_Nav.master
网页,并且我在
CheckAuth()
页面中创建了方法
AuthenticationMethods.aspx
,我想将该方法调用到
password.aspx
页面中,我已经创建了实例
Model_AuthenticationMethods authenticationMethods = new Model_AuthenticationMethods();
并且它抛出了类似
are you missing a using directive or an assembly reference
的错误,我不知道如何在我想要的地方调用该方法
CheckAuth()
,下面是我的代码

Login_Nav 主页:-


<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Login_Nav.master.cs" Inherits="Login_Nav" %>
public partial class Login_Nav : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
}

带有母版页的 AuthenticationMethods aspx 页面:-


<%@ Page Title="" Language="C#" MasterPageFile="~/Login_Nav.master" AutoEventWireup="true" CodeFile="AuthenticationMethods.aspx.cs" Inherits="Model_AuthenticationMethods" %>
public partial class Model_AuthenticationMethods : System.Web.UI.Page
{

public void CheckAuth()
{
  //my logic will go here
}

}

带有母版页的密码 aspx 页面:-

我想调用

CheckAuth();
页面中的
password.aspx
方法


<%@ Page Title="" Language="C#" MasterPageFile="~/Login_Nav.master" AutoEventWireup="true" CodeFile="password.aspx.cs" Inherits="password" %>
public partial class Model_Data : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
  // Creating an instance of Model_AuthenticationMethods
Model_AuthenticationMethods authenticationMethods = new Model_AuthenticationMethods(); //getting error "are you missing a using directive or an assembly reference"

   authenticationMethods.CheckAuth()

    //CheckAuth();

    }

}


建议我如何调用该方法

{creating an instance or using inheritance concept}

我没有足够的知识来实现这个概念

asp.net master-pages
1个回答
0
投票

iPhone iPhonejjrhfhfhfhfhhfhfjnfnfjfnnfnfjcjchchchudbskg e NH s 在每个 Yb 汇丰银行 hmm fkdkx 在 Xbox GB 盒子 Yb 说关键阿拉莫 VA 将电视 Vlasic Yb s 银河如果困难过渡威斯康星州解释精神分析分析杰克逊维尔最喜欢的瓦茨拉夫 CA 长臂猿

© www.soinside.com 2019 - 2024. All rights reserved.