关于在.NET每个页面调用同一段代码

qbc0771 2009-04-06 04:20:53
   
protected void Page_Load(object sender, EventArgs e)
{


if (!Page.IsPostBack)
{
if (Session["yh"] == null || Session["yh"] == "")
{
Response.Write("<script>window.open('GuanLilongin.aspx?cc=123','_top');</" + "script>");
}
}
}

在每个页面的前面多加上这个判断语句,请问如有封装起来,在每个页面调用.也方便修改.
...全文
95 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
fengjian_428 2009-04-06
  • 打赏
  • 举报
回复
global的Application_BeginRequest事件里面
fengjian_428 2009-04-06
  • 打赏
  • 举报
回复
写在gloabe里面
fengjian_428 2009-04-06
  • 打赏
  • 举报
回复
写在gloabe里面
liu4545533 2009-04-06
  • 打赏
  • 举报
回复
上面正解
jie3614 2009-04-06
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 namhyuk 的回复:]
SORRY, 刚才回的代码一踏糊涂。

再贴一个,在MasterPage的Page_Load里:


C# code
protected void Page_Load(object sender, EventArgs e)
{
if(Session["hy"] == null || Session["hy"].ToString() == string.Empty)
{
string script = string.Format("window.open('{0}','{1}','{2}');", "Default2.aspx", "winname","height=100, width=400, toolbar= no, menubar=no, scrollbars=…
[/Quote]

同意
namhyuk 2009-04-06
  • 打赏
  • 举报
回复
SORRY, 刚才回的代码一踏糊涂。

再贴一个,在MasterPage的Page_Load里:


protected void Page_Load(object sender, EventArgs e)
{
if(Session["hy"] == null || Session["hy"].ToString() == string.Empty)
{
string script = string.Format("window.open('{0}','{1}','{2}');", "Default2.aspx", "winname","height=100, width=400, toolbar= no, menubar=no, scrollbars=no, resizable=no, location=no, status=no,top=100,left=300");
Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptKey", script, true);
}
}
namhyuk 2009-04-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zzyzgydotnet 的回复:]
写一个基类,其他的继承之。
[/Quote]
同意。

protected void Page_Load(object sender, EventArgs e)
{

if (!Page.IsPostBack)
{
if(string.IsNullOrEmpty(Session["yh"].ToString())
//if (Session["yh"] == null || Session["yh"] == "")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptKey", "window.open('GuanLilongin.aspx?cc=123','_top')", true);
//Response.Write("<script>window.open('GuanLilongin.aspx?cc=123','_top');</" + "script>");
}
}
}
zzyzgydotnet 2009-04-06
  • 打赏
  • 举报
回复
写一个基类,其他的继承之。
fangyuan303687320 2009-04-06
  • 打赏
  • 举报
回复
写一个公共类放在app_code中,
在类中写一个静态的判断方法,


然后每个页面,只调用方法就好了。

mabailin 2009-04-06
  • 打赏
  • 举报
回复
关注....

111,126

社区成员

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

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

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