有一个PageBase类,继承自System.Web.UI.Page。其他页面都继承自PageBase类。
当继承自PageBase的aspx页面切换到设计视图的时候,出现下面的信息:
PageBase的主要代码如下:
public class PageBase: System.Web.UI.Page
{
//当前登陆用户的实例
protected RanQi.Component.Account curUser=new RanQi.Component.Account();
public PageBase()
{}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.Load += new System.EventHandler(this.RanQiPage_Load );
this.Error += new System.EventHandler(this.RanQiPage_Error );
}
private void RanQiPage_Load(object sender, System.EventArgs e)
{
//如果没有登陆
if(curUser.UserID.Length<=0 || curUser.UserName.Length <=0)
{
Response.Redirect ("Login.aspx");
}
}
//错误处理
protected void RanQiPage_Error(object sender, System.EventArgs e)
{
Exception currentError = Server.GetLastError();
ShowError(currentError);
Server.ClearError();
}
//显示错误信息
protected void ShowError(Exception currentError)
{
HttpContext context=HttpContext.Current ;
context.Response.Write( "<link rel='stylesheet' href='/RanQi/Css/Main.css'>" +
"<h2>Error</h2><hr/>" +
"An unexpected error has occurred on this page." +
"The system administrators have been notified.<br/>" +
"<br/><b>错误来自:</b>" +
"<pre>" + context.Request.Url.ToString() + "</pre>" +
"<br/><b>错误信息:</b>" +
"<pre>" + currentError.Message.ToString() + "</pre>" +
"<br/><b>错误跟踪:</b>" +
"<pre>" + currentError.ToString() + "</pre>");
}
}
继承自PageBase类的Webform1.aspx.cs:
namespace RanQi
{
public class WebForm1 : PageBase
{
private void Page_Load(object sender, System.EventArgs e)
{
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
}
}
不知道为什么,一开始还可以正常切换,写着写着就这样了,但是程序本身并没有任何问题,编译运行都正常。![]()
碰到这个问题已经好久了,一直都没有解决,
如果谁知道问题出在哪里,还请告诉小弟。谢先~~~
==============================================
您可以看到在我的PageBase类的RanQiPage_Load事件里简单的判断用户是否登陆。但是刚才这个却在运行的时候不起作用。后来跟踪了一下,原来当载入WebForm1.aspx时,程序先执行的是WebForm1中的Page_Load,然后再执行PageBase里面的RanQiPage_Load。只需要将WebForm1里面的:
InitializeComponent();
base.OnInit(e);
顺序颠倒一下就可以了,呵呵~~

浙公网安备 33010602011771号