Is MasterPage -> Page -> UserControl the loading order of an ASP .NET request?
Is there a situation where an UserControl loads before the Page loads ?
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.”
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
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.
But my concern is that UserControls may not always load last.
The event progression in ASP.NET is as follows:
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.)