ASP .NET:何时加载UserControls? [英] ASP .NET: when UserControls loads?

查看:56
本文介绍了ASP .NET:何时加载UserControls?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MasterPage-> Page-> UserControl是ASP .NET请求的加载顺序吗?
是否存在在页面加载之前先加载UserControl的情况?

Is MasterPage -> Page -> UserControl the loading order of an ASP .NET request?
Is there a situation where an UserControl loads before the Page loads ?

我有我的用户的私人消息,他们在每个页面中都会看到诸如您有3条未读消息"之类的消息.
当用户查看未读消息时,我要将消息更改为您有2条未读消息."

I have private messages for my users and in every page they will see a message like this "You have 3 unread messages."
When users view an unread message I want to change the message to this "You have 2 unread messages."

使用Request.Redirect可以轻松完成此操作,但我想避免这种情况.
消息1->单击它将转到MarkAsRead.aspx?id = x,这会将我重定向到ViewMessage.aspx?id = x

This can be easily done with a Request.Redirect, but I want to avoid this.
message 1 -> click on it will goes to MarkAsRead.aspx?id=x wich redirects me to ViewMessage.aspx?id=x

我不想将其标记为已从ViewMessage.aspx?id = x读取,然后减少会话变量"unreadMessages",然后让UserControl显示新编号.

Instead of doing this I want to mark the message as read from ViewMessage.aspx?id=x then decrease my Session variable "unreadMessages", then let my UserControl display the new number.

但是我担心的是UserControls可能不会总是加载到最后.

But my concern is that UserControls may not always load last.

推荐答案

ASP.NET中的事件进度如下:

The event progression in ASP.NET is as follows:

Page.OnPreInit()
UserControl.OnInit()
MasterPage.OnInit()
Page.OnInit()
Page.OnInitComplete()
Page.OnLoad()
MasterPage.OnLoad()
UserControl.OnLoad()
Page.OnLoadComplete()
(page event handlers fired here)
Page.OnPreRender()
MasterPage.OnPreRender()
UserControl.OnPreRender()
Page.OnPreRenderComplete()
Page.OnSaveStateComplete()
UserControl.OnUnload()
MasterPage.OnUnload()
Page.OnUnload()

要完成您的尝试,请在Page.Init事件中处理消息计数更新,然后在UserControl.Load事件期间显示该计数.我已经提供了上述事件的完整进展,如果上述情况不够充分,可能会为您提供更多选择. (例如,如果由于某些原因Page.Init太早,您可以在Page.Load中更新计数,并在UserControl.PreRender中呈现该计数.)

To accomplish what your trying to do, handle your message count update in your Page.Init event, then display that count during the UserControl.Load event. I've provided the full progression of events above, which may provide you more options in case the above scenario isn't adequate. (For example, you could update the count in Page.Load, and render it in UserControl.PreRender, if for some reason Page.Init was too soon.)

这篇关于ASP .NET:何时加载UserControls?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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