Page_Load两次 [英] Page_Load twice

查看:56
本文介绍了Page_Load两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点生锈没有触及.NET 6个月和

我不记得为什么Page_Load在这段代码中发生了两次:


private void Page_Load(object sender,System.EventArgs e)

{

//现有会话?

if(Session [" ; NewOrder"] == null)

{

//保存本地空订单对象

this._newOrder = Orders.Initialize();


//在外观中创建新内容

Session [" NewOrder"] = this._newOrder;

}


if(!Page.IsPostBack)//绑定订单项如果没有发布

this.BindOrderItems();

}


private void BindOrderItems()

{

//如果会话处于活动状态,将订单项绑定到datagrid

if(this.NewOrder!= null&& this.NewOrder.OrderItems!=

null)

{

OrderItemsGrid.DataSource = this.NewOrder.OrderItems;

OrderItemsGrid.DataBind();

}

}


我知道这有很好的理由,但我不知道如何

阻止/解决它。


但是,无论如何,在单步执行此代码之后,绑定了

DataGrid(BindOrderItems函数)Page_Load

重新开始。


有什么想法吗?


谢谢!

解决方案

当在HTML和

代码隐藏中定义页面加载时,会发生这种情况。有时IDE会做一件事,而我做另一件事来绑定

那个事件。


" V.甄克思" <一个******* @ discussions.microsoft.com>在消息中写道

news:12 **************************** @ phx.gbl ... < blockquote class =post_quotes>我有点生锈,没有触及.NET 6个月而且
我不记得为什么Page_Load在这段代码中发生了两次:

私人void Page_Load(object sender,System.EventArgs e)
{
//现有会话?
if(Session [" NewOrder"] == null)
{
//保存本地空订单对象
this._newOrder = Orders.Initialize();

//在外观中创建新的
会话[" NewOrder"] = this。 _newOrder;
}
如果(!Page.IsPostBack)//绑定订单项如果没有发布
this.BindOrderItems();
}
<私有空BindOrderItems()
{
//如果会话处于活动状态,将订单项绑定到datagrid
if(this.NewOrder!= null&& this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

我知道这有很好的理由,但我不知道如何防止/解决它。

但是,无论如何,在踩踏的时候通过这段代码,在绑定了DataGrid之后(BindOrderItems函数)Page_Load
重新开始。

任何想法?

谢谢!


在你的aspx的html中,检查你是否有AutoEventWireup = False

。如果你使用代码隐藏,你需要将此属性设置为

false

-

Kumar Reddi
< a rel =nofollowhref =http://kumarreddi.blogspot.comtarget =_ blank> http://kumarreddi.blogspot.com


"诉甄克思" <一个******* @ discussions.microsoft.com>在消息中写道

news:12 **************************** @ phx.gbl ... < blockquote class =post_quotes>我有点生锈,没有触及.NET 6个月而且
我不记得为什么Page_Load在这段代码中发生了两次:

私人void Page_Load(object sender,System.EventArgs e)
{
//现有会话?
if(Session [" NewOrder"] == null)
{
//保存本地空订单对象
this._newOrder = Orders.Initialize();

//在外观中创建新的
会话[" NewOrder"] = this。 _newOrder;
}
如果(!Page.IsPostBack)//绑定订单项如果没有发布
this.BindOrderItems();
}
<私有空BindOrderItems()
{
//如果会话处于活动状态,将订单项绑定到datagrid
if(this.NewOrder!= null&& this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

我知道这有很好的理由,但我不知道如何防止/解决它。

但是,无论如何,在踩踏的时候通过这段代码,在绑定了DataGrid之后(BindOrderItems函数)Page_Load
重新开始。

任何想法?

谢谢!


这绝对不是,这是一个Web用户控件,

对不起我应该提到它。


我知道主页上的Page_Load事件处理程序是

loading但这不是我所看到的。 Page_Load

用户控制我正在两次踩火。它是
未定义两次因为我在

调试器中单步执行它并且我正在看它执行两次。

此外,在主页面中由Page.LoadControl(asp:占位符)加载

的控件。


但是,这不应该发生。

-----原始消息-----
我生锈了没有触及.NET 6个月和
我不记得为什么Page_Load在这个
代码中发生了两次:
private void Page_Load(object sender,System.EventArgs e)
{
//现有会话?
if(Session [" NewOrder"] == null)
{
//保存本地空订单对象
_newOrder = Orders.Initialize();

//在外观中创建新的
会话[" NewOrder"] = this._newOrder;
}
if(!Page.IsPostBack)//绑定订单项如果没有发布
this.BindOr derItems();
}
私有空BindOrderItems()
{
//如果会话处于活动状态,将订单项绑定到datagrid
if(this .NewOrder!= null&& this.NewOrder.OrderItems!=
null)
{/> OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

我知道这是一个很好的理由,但我不知道如何防止/解决它。

但是,无论如何,在单步执行此代码后,绑定了
DataGrid(BindOrderItems函数)Page_Load
重新开始。

任何想法?

谢谢!



I''m a little rusty having not touched .NET for 6 months and
I can''t remember why Page_Load is happening twice in this code:

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
this.BindOrderItems();
}

private void BindOrderItems()
{
//if session is active, bind order items to datagrid
if (this.NewOrder != null && this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

I know there''s a good reason for it but I''m not sure how to
prevent/work around it.

But, anyhow, while stepping through this code, after the
DataGrid is bound (BindOrderItems function) Page_Load
starts over again.

Any ideas?

Thanks!

解决方案

This happens to me when the page load is defined in both the HTML and in the
code-behind. Sometimes the IDE will do one thing while I do another to bind
that event.

"V. Jenks" <an*******@discussions.microsoft.com> wrote in message
news:12****************************@phx.gbl...

I''m a little rusty having not touched .NET for 6 months and
I can''t remember why Page_Load is happening twice in this code:

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
this.BindOrderItems();
}

private void BindOrderItems()
{
//if session is active, bind order items to datagrid
if (this.NewOrder != null && this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

I know there''s a good reason for it but I''m not sure how to
prevent/work around it.

But, anyhow, while stepping through this code, after the
DataGrid is bound (BindOrderItems function) Page_Load
starts over again.

Any ideas?

Thanks!



In the html of your aspx, check to see if you have "AutoEventWireup=False"
or not. If you are using code-behind, you need to have this attribute set to
false
--
Kumar Reddi
http://kumarreddi.blogspot.com

"V. Jenks" <an*******@discussions.microsoft.com> wrote in message
news:12****************************@phx.gbl...

I''m a little rusty having not touched .NET for 6 months and
I can''t remember why Page_Load is happening twice in this code:

private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
this.BindOrderItems();
}

private void BindOrderItems()
{
//if session is active, bind order items to datagrid
if (this.NewOrder != null && this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

I know there''s a good reason for it but I''m not sure how to
prevent/work around it.

But, anyhow, while stepping through this code, after the
DataGrid is bound (BindOrderItems function) Page_Load
starts over again.

Any ideas?

Thanks!



It''s definitely not, this is inside of a web user control,
sorry I should have mentioned that.

I know the Page_Load event handler from the master page is
loading but that''s not what I''m seeing. The Page_Load in
the user control that I''m stepping through fires twice. It
is not defined twice as I''m stepping through it in the
debugger and I''m watching it do it twice.

Also, the control that this is happening in is being loaded
by a Page.LoadControl (asp:placeholder) in the master page.

Still, this shouldn''t happen.

-----Original Message-----
I''m a little rusty having not touched .NET for 6 months and
I can''t remember why Page_Load is happening twice in this code:
private void Page_Load(object sender, System.EventArgs e)
{
//existing session?
if (Session["NewOrder"] == null)
{
//save local empty order object
this._newOrder = Orders.Initialize();

//create new in facade
Session["NewOrder"] = this._newOrder;
}

if (!Page.IsPostBack) //bind order items if not posted
this.BindOrderItems();
}

private void BindOrderItems()
{
//if session is active, bind order items to datagrid
if (this.NewOrder != null && this.NewOrder.OrderItems !=
null)
{
OrderItemsGrid.DataSource = this.NewOrder.OrderItems;
OrderItemsGrid.DataBind();
}
}

I know there''s a good reason for it but I''m not sure how to
prevent/work around it.

But, anyhow, while stepping through this code, after the
DataGrid is bound (BindOrderItems function) Page_Load
starts over again.

Any ideas?

Thanks!
.



这篇关于Page_Load两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆