【发布时间】:2014-06-17 07:53:54
【问题描述】:
我想使用另一个类函数更改母版文件
例子:
public class XYZClass
{
public void CheckLogin(object ses,bool ipb,ref MasterPage page)
{
if (!(ses == null))
{
if (ses.ToString() == "Admin")
page.MasterPageFile = "~/Admin.master";
else
page.MasterPageFile = "~/MasterPage.master";
}
else
{
Response.Redirect("~/frmLogin.aspx");
}
}
}
public partial class frmDoctorHistory : System.Web.UI.Page
{
BLLcheckLogin checkLogin = null;
protected void Page_PreInit(object sender, EventArgs e)
{
checkLogin = new BLLcheckLogin();
checkLogin.CheckLogin(Session["usertype"], IsPostBack, ref MasterPageFile);
}
}
我从另一个 aspx 源文件调用这个函数,它给了我一个错误,比如 “不能将属性、索引器或动态成员访问作为 out 或 ref 参数传递”。
【问题讨论】:
-
MasterPage 是一个对象,所以不需要通过引用传递。从您的方法声明和方法调用中删除“ref”以解决该错误。