一个非常简单又很变态的问题!

zilong32 2007-10-09 03:37:01
在IE地址栏中直接敲入一个如:
http://localhost:2556/webUI/addnotice.aspx时,
addnotice.aspx.cs文件中的Page_Load事件没有运行,大家帮我看看这是怎么回事?

我的本意是必须已经登陆过了才能进入addnotice.aspx.

addnotice.aspx中代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="addnotice.aspx.cs" Inherits="addnotice" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">
<title>添加通知</title>
<link href="css/zcr_css.css" type="text/css" rel="stylesheet"/>
<script language="javascript" type="text/javascript">
function check()
{

if(document.getElementById("txttitle").value=="")
{
alert("标题不能为空!");
document.getElementById("txttitle").focus();
return false;
}
if(document.getElementById("txtcontent").value=="")
{
alert("内容不能为空!");
document.getElementById("txtcontent").focus();
return false;
}
return true;
}
</script>
</head>
<body bgcolor="#F4F9FF">
<form id="form1" runat="server" method="get">
<div>
<table width="100%" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td bgcolor="#DBEBF9" class="zcr_login5" style="padding-left: 10px;" colspan="2"><strong>当前位置:添加新通知</strong></td>
</tr>
<tr>
<td class="zcr_login3" align="right" width="10%">
标题:
</td>
<td class="zcr_login3" align="left">
<asp:TextBox ID="txttitle" runat="server" Text="" Width="500px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="zcr_login3" align="right" width="10%">
内容:
</td>
<td class="zcr_login3" align="left">
<asp:TextBox ID="txtcontent" runat="server" TextMode="multiLine" Width="500px" Height="400px" Text=""></asp:TextBox>
</td>
</tr>
<tr>
<td class="zcr_login4" align="right" width="10%" style="height: 22px">
附件:
</td>
<td class="zcr_login3" align="left" style="height: 22px">
<asp:FileUpload ID="fileup1" runat="server" />
<span class="zcr_login4" ><strong>注:上传附件只能是doc,xls文件格式</strong></span>
</td>
</tr>
<tr>
<td class="zcr_login3" align="right" width="10%">
 </td>
<td class="zcr_login3" align="left">
<asp:FileUpload ID="fileup2" runat="server" />
</td>
</tr>
<tr>
<td class="zcr_login3" align="right" width="10%">
 </td>
<td class="zcr_login3" align="left">
<asp:FileUpload ID="fileup3" runat="server" />
</td>
</tr>
<tr>
<td class="zcr_login3" align="right" width="10%" style="height: 22px">
 </td>
<td class="zcr_login3" align="left" style="height: 22px">
<asp:FileUpload ID="fileup4" runat="server" />
</td>
</tr>
<tr>
<td class="zcr_login3" align="right" width="10%">
 </td>
<td class="zcr_login3" align="left">
<asp:FileUpload ID="fileup5" runat="server" />
</td>
</tr>
<tr>
<td class="zcr_login3" align="right" width="10%">

</td>
<td class="zcr_login3" align="left">
<asp:Button ID="btnsubmit" runat="server" Text="提 交" OnClick="btnsubmit_Click" OnClientClick="return check();" />  
<asp:Button ID="btnclear" runat="server" Text="请 空" OnClick="btnclear_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
addnotice.aspx.cs中部分代码:
public partial class addnotice : System.Web.UI.Page
{
private PMaddnotice Model = new PMaddnotice();
/// <summary>
/// 窗体初始化
/// </summary>
/// <param name="e"></param>
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Model.init();
}


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Comsession.loginInfo == null)
{
//JScript.ShowMessage(Page, "您还没有登录,请先登录!");
JScript.Redirect("login.aspx");
return;
}
}
}
}
...全文
251 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
greenery 2007-10-09
  • 打赏
  • 举报
回复
正常情况下不会的。
你试一下新建一个工程看看。
如果新工程没有问题,就逐个对比你的文件与新工程的文件的区别。
  • 打赏
  • 举报
回复
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.Load += new System.EventHandler(PageBase_Load);
}

zilong32 2007-10-09
  • 打赏
  • 举报
回复
这样还是没用的.
是不是应该在那里设一下什么东西??如:webconfig
是不是和method有什么关系?
form method默认为post
showlie 2007-10-09
  • 打赏
  • 举报
回复
把private PMaddnotice Model = new PMaddnotice(); 设置为静态private static PMaddnotice Model = new PMaddnotice();
或者
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
private PMaddnotice Model = new PMaddnotice();
Model.init();
}
zilong32 2007-10-09
  • 打赏
  • 举报
回复
将addnotice.aspx设为起始页时,断点调试,pageload执行;
但是直接敲入地址http://localhost:2556/webUI/addnotice.aspx时,断点调试,pageload不执行!

整个系统其它页面都是这样。
而我以前的系统没有出现过这样的现象。

我对照了此系统和以前的系统,发现设置一样。
symbol441 2007-10-09
  • 打赏
  • 举报
回复
断点调试确认一下是否pageload确实没有真正执行,还是你的程序其他原因
zilong32 2007-10-09
  • 打赏
  • 举报
回复
我用的是2005。2.0版本
我也感觉是事件没有注册,是不是和form中的method有什么关系?或是其它设置??
zilong32 2007-10-09
  • 打赏
  • 举报
回复
怎么没人顶啊?
白云在上 2007-10-09
  • 打赏
  • 举报
回复
你用的.net 版本是什么?如果是 1.1版的话,好像在OnInit里面要有 page.load += 之类的语句。

110,552

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧