|
I am putting together an article about master and content pages, and I want to make sure the info I'm including is correct. Also, if this is useful in any way, I can expand on it a bit and make it an article unto itself. The information has been culled from MS documentation, meaning that accuracy and completeness is iffy at best. So any comments or suggestions would be appreciated.
----------
As ASP files go from a request to something sent to the browser, several events are raised. All pages will raise the events I've marked below as Content and Page; Master events will be raised only if the page has a Master Page. Events marked as Page show where the server does something important and are not trappable events.
Content PreInit
The first capturable event. The Request and Response objects are available. IsPostBack and UICulture objects have been initialized. ViewState is not available. This is the only event where you can set the master page dynamically, as it occurs before any master page event has been raised. This is also when you would set the page's theme and create dynamically created controls.
Master Init
Initialize the master page and set any properties that it will require. ViewState is not available. Server controls on the master page have been fully initialized and can be accessed as needed, but the controls' values have not yet been set.
Content Init
Initialize the content page and set any properties that it will require. ViewState is not available. Server controls on the content page have been fully initialized and can be accessed as needed, but the controls' values have not yet been set.
Content InitComplete
The page has been fully initialized.
Page ViewStateRestore
This is not a trappable event. The ViewState is initialized. If the page request is a postback, the postback data is processed. Server controls with ViewState or postback data have their values set.
Content PreLoad
The ViewState has been restored and postback data has been set.
Content Load
The content page is being loaded. This event is usually where you set properties, open connections, etc. Note that the content page is loaded before the master page.
Master Load
The master page is being loaded. This event is usually where you set properties, open connections, etc. Note that the master page is loaded after the content page.
Page Validation
This is not a trappable event. If your page has any Validation controls, the Validate method is called on them.
Page HandlePostBack
This not a trappable event. After the page's controls have been validated and before rendering begins, any postback events such as button clicks are handled.
Content LoadComplete
The page has been completely loaded.
Page PreRender
This is not a trappable event. The EnsureChildControls method is called on all server controls, on the content page and on the master page. The BindData method is called on controls that are data-bound.
Content PreRender
The page is about to be rendered. Perform final changes to server controls, and save any data you want to persist to the ViewState .
Master PreRender
The page is about to be rendered. Perform final changes to server controls, and save any data you want to persist to the ViewState .
Content PreRenderComplete
This is your last chance to change the page's content; subsequent changes to the page will be ignored.
Content SaveStateComplete
This is your last chance to persist data to the ViewState .
Page Render
This is not a trappable event. The Render method is called on all server controls on the page. In-line commands (those noted in the HTML with <% %> are executed top down.
Master Unload
The page has finished rendering. If you opened any files or data connections for rendering the page, now would be the time to close them and free resources. Use of the Response , Request and ViewState objects will throw an exception. Please note that this event has nothing to do with browser navigation.
Content Unload
The page has finished rendering. If you opened any files or data connections for rendering the page, now would be the time to close them and free resources. Use of the Response , Request and ViewState objects will throw an exception. Please note that this event has nothing to do with browser navigation.
Content Disposed
The cycle is complete, and the page has been fully rendered. Please note that this event has nothing to do with browser navigation.
Master Disposed
The cycle is complete, and the page has been fully rendered. Please note that this event has nothing to do with browser navigation.
When you have nested master pages, the inner master page is treated as the contents of the outer master page. So if you had Content.asp with a master page of Inner.master which, in turn, has a master page Outer.master, the events would be:
Content PreInit
Outer Init (master master)
Inner Init (Outer's content)
Content Init (Inner's content)
Content InitComplete
Page ViewStateRestore
Content PreLoad
Content Load
Inner Load (Content's master)
Outer Load (Inner's master)
Page Validation
Page HandlePostBack
Content LoadComplete
Page PreRender
Content PreRender
Inner PreRender (Content's master)
Outer PreRender (Inner's master)
Content PreRenderComplete
Content SaveStateComplete
Page Render
Outer Unload (master master)
Inner Unload (Outer's content)
Content Unload (Inner's content)
Content Disposed
Inner Disposed (Content's master)
Outer Disposed (Inner's master)
----------
|
|
|
|
|
Good Info.
But I would suggest write an article instead of posting this information in the message board.
One more thing:
It would be great if you would have explained the life cycle of the web controls also along with the Page life cycle and Master pages.
|
|
|
|
|
Hey.
I get this exeption on my Vista machine, this works fine on my XP machine.
On both machines I use Visual Studio 2008, and both uses .Net Framework 3.5.
<!-- HttpException The file '/MyControls/Web/GUI/Controls/PageHead.ascx' does not exist. at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.UI.BaseTemplateParser.GetReferencedType(VirtualPath virtualPath, Boolean allowNoCompile)
at System.Web.UI.BaseTemplateParser.GetUserControlType(VirtualPath virtualPath)
at System.Web.UI.MainTagNameToTypeMapper.ProcessUserControlRegistration(UserControlRegisterEntry ucRegisterEntry)
at System.Web.UI.BaseTemplateParser.ProcessDirective(String directiveName, IDictionary directive)
at System.Web.UI.TemplateControlParser.ProcessDirective(String directiveName, IDictionary directive)
at System.Web.UI.PageParser.ProcessDirective(String directiveName, IDictionary directive)
at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding) -->
I have a prodject where my SomePage.aspx site is.
On this page I have a refference to the usercontrol PageHead.ascx witch is located on
another prodject.
<%@ Register TagPrefix="uc1" TagName="pageHead" Src="MyControls/Web/GUI/Controls/PageHead.ascx" %>
I've have added the web prodject to IIS and added the virtual path for the usercontrol prodjekt,
and in the usercontrol prodjekt properies I've sat it to use the IIS Web server and to override the application root URL.
Nothing of this has helped.
Anyone know why?
Thanks
Thomas
|
|
|
|
|
use an absolute or relative path. I expect the issue is that your path is not right from the context of the page using it.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
i want to create a random number when i insert a record to table. and i want that random number is unik and it not be more than 10 digit. i should use a GUID or ....? can any bode give me a suggestion and good idea?
thanks.
|
|
|
|
|
ptvce wrote: i should use a GUID or ....?
Yes, you can use GUID.
cheers,
Abhijit
CodeProject MVP
|
|
|
|
|
I'm not sure a GUID satisfies this requirement - "and it not be more than 10 digit".
Scott
|
|
|
|
|
I've done this in the past by creating guids in a loop until xx characters of the GUID are unique in the DB.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Why not use a identity column? It can auto increment the value upon each insertion.
|
|
|
|
|
System.Random r = new System.Random();
string strrnd = (100000 + r.Next(799999)).ToString();
|
|
|
|
|
But it doesn't guarantee to be unique always.
|
|
|
|
|
Yes.. Navaneeth is right.. .If you cannot deal with GUID field (36 characters in size)
I think best way for uniqueness is to leave this to SQL server using Identity.
|
|
|
|
|
You can take several approaches:
Make a list of max number of random numbers that you need and shuffle them, then go and insert one after another. A good random shuffle algorithm you can create in no time.
You could use a good hash function. There are plenty to choose. You need two keys, one is secret and somewhat random, and another is ID itself. You combine them and get a random number using the hash function. (I can give you an example of very simple and fast one if you like.)
Another is to create a circular random function which calculates a random number from the previous random value. You keep only the last entry. You take care that the cycle size is exactly what you need.
You use normal random number and check if that one is used in the database, and keep searching for the one that is not.
You can use a simple random number and attach to it your ID so that the size of both is 10 digit. For example you know you will not need more than 9999 id's. Good. Take six digit random number and concatenate to it 4 digit ID. This is not a completely random number but it is as strong as six digit random number.
You can use a matrix
0123456789
0
1
2
3
4
5
6
7
8
9
and then use random generator mod 10 (0-9 digit at random) (or in general mod matrix size). Now ,if you would get these numbers 4, 5, 7, 0 you mark (4,5) (5,7) (7,0) and keep on until you get your first ten-digit number. For the next ten-digit number you keep on marking but you count how many entries were previously already marked. If you find for a 10 digit number that its all 9 entries were marked you reject that number. This way you get a smaller number of unique random numbers, but the matrix can always be larger (100x100...), of course.
Keep in mind what security level you need.
And do not use GUID, it is never a random number on one computer.
modified on Monday, March 9, 2009 2:02 PM
|
|
|
|
|
Perisic, Aleksandar wrote: And do not use GUID, it is never a random number on one computer.
what do you mean? Are you implying you can generate the same GUID in one computer? Huh!
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
Really, how did you get to this "Are you implying you can generate the same GUID in one computer?"
I said GUID is never a random number on one computer. Random. Use a GUID tool available out there and see for yourself.
GUID is not used to create a random number. It is used only to create a unique number.
For a GUID on one computer, several parameters are used (some of which are fixed some are dynamic) like netwok card ID, current time, etc.... so that when they are combined it is almost impossible to create the same GUID ever again during the time of the entire Universe (yes, that unique). Not random. Unique.
Now once this number is created, if you keep asking for another one on the same machine, you get numbers that are very close to each other, sometimes even in increasing order. Random? Not even close.
GUID could be taken maybe as somewhat random (or better say unpredictable) if you have computers in a network and then you take one time one GUID from each. Even then that is only one series with some form of randomness that you can get. But even a network card ID, time etc that are combined in a GUID have some format, so no, a GUID is really not random in any sense and should never be used as such unless a developer really need some form of "unknown, unpredictable number".
|
|
|
|
|
Perisic, Aleksandar wrote: Really, how did you get to this "Are you implying you can generate the same GUID in one computer?"
I said GUID is never a random number on one computer. Random. Use a GUID tool available out there and see for yourself.
I've to re-read your message again and I guess I missed "never" in your statement. May be, you know, Day Light Saving (Summer Time) changed yesterday and I am still under the weather. Sorry for the mix up.
I know GuiD are not random, they are pseudo random.
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
As you wish but:
A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever a unique identifier is required. Such an identifier has a very low probability of being duplicated.
A GUID has nothing in common with random numbers, it is as random as credit card number is random. You will probably not guess the number of my credit card but it is still not random, it is a structured number with very specific parts. The similar way GUID has structure and is not random.
A GUID can be based on a random generator, but we do not know wheather it is or not, and GUID library support on Microsoft
OS is not, so we should not use it for creating randomness.
However, if the size cost is acceptable, creating unique numbers using GUID's is a good solution, especially knowing that it is unique in the Universe so we can move around records and we will never find two objects with the same ID.
|
|
|
|
|
I want to change color of the windows title bar so that it blinks when it is not focused i.e. it is minimized in the task bar. I want to achieve it when a new message arrives. I m using a web form and thus window is a browser window.Thanks in advance!!!
|
|
|
|
|
Between operating system issues, browser issues and security issues -- not to mention user annoyance issues -- I don't think this is possible.
|
|
|
|
|
How to use updatePanel without ScriptManager in ASP.NET. Is it possible to use it without ScriptManager
|
|
|
|
|
hey....
scriptManager is a server control that includes all the necessary javascript that the page needs to run the update panel. Update panel needs script manager as it is defined as mandatory in compiler. otherwise we may include all the javascript files it needs manually without including scriptmanager.
I dont think it is possible to use UpdatePanel without ScriptManager. In case you really need, create the updatepanel yourself..
|
|
|
|
|
yes, you'll create user control.
|
|
|
|
|
Jack Li wrote: yes, you'll create user control.
What does it mean?
cheers,
Abhijit
CodeProject MVP
|
|
|
|
|
Any specific reason, you dont want to use scriptmanager ?
If you have more then 2 pages with scripmanager and it is giving you error when you try to use both the pages, then you can use ScriptManagerProxy in one of the page. Or you can add the ScriptManager in the "Master Page", and in all the content page you will able to use it.
Or you can use other 3rd party framework.
|
|
|
|
|
Hi!
I work with C #
I want update my columns in my GridView without going through edit :
for each row I click update button to update the line
how? Thank you.
|
|
|
|
|