Page 85 - DCAP312_WEB_TECHNOLOGIES_II
P. 85
Unit 4: Advanced Server Controls
The first versions of Microsoft Windows ran every program in a single address Notes
space. Every program was meant to co-operate by yielding the CPU to other
programs so that the graphical user interface (GUI) could multitask and be
maximally responsive.
Create a Web page to show the use of compare validator.
Validation Control in ASP.NET
As we all know the ASP.NET Page LifeCycle as:
Init
Load View State
Load Post Data
Load
Post Back Events
Save View State
Pre Render
Render
Unload
As you can see, here LoadPostData is a part of PageLife Cycle and comes after LoadViewState.
All of the Input control’s data dont get wiped off during postback even if viewstate is not
enabled for that control. So this is the LoadPostData method that is responsible to get the
data from Form collection and assign it to the control. Now asp.net 4.5, validates the input
only when you access the data from form collection. That is why if you look the stacktrace
then it is visible that the exception is thrown fromLoadPostData method only and page life
cycle is the last stage of ASP.NET Request Processing.
Now lets try to have an clarification using a demo. In ASP.NET 4.5, the validation triggers
only when the data is accessed and the data is accessed at LoadPostData for input controls.
So lets create a custom textbox. For this we will override LoadPostData method and will
do nothing in that. It means that the data would not be accessed for the customTextBox at
LoadPostData. So even if the ValidationMode is enabled for the CustomtextBox, it would
not be fired. Let us see this.
We create a CustomtestBox and overridden the LoadPostData method as:
public class CustomTextBox : System.Web.UI.WebControls.TextBox
{
protected override bool LoadPostData(string postDataKey, NameValueCollection
postCollection)
Contd...
LOVELY PROFESSIONAL UNIVERSITY 79