Suggested Videos
Part 4 - Events in the life cycle of a web application
Part 5 - Difference between ViewState, SessionState and ApplicationState
Part 6 - ASP.NET Page Life Cycle Events
In the previous parts of this video series, we have discussed that events can occur at application, page and control levels. In Part 4, we discussed application level events, and in Part 6, we discussed about Page Level events.
In this session, we will discuss about control level events. ASP.NET server controls, such as TextBox, Button, and DropDownList has their own events. For example, Button has a click event. TextBox has TextChanged event, and DropDownList has SelectedIndexChanged event. We have a set of asp.net validation controls, that has validation events. The events that all these controls expose, can be broadly divided into 3 categories.
Postback events - These events submit the Web page, immediately to the server for processing. Click event of a button control is an example for PostBack event.
Cached events - These events are saved in the page’s view state to be processed when a postback event occurs. TextChanged event of TextBox control, and SelectedIndexChanged event of a DropDownList control are examples of cached events. Cached events can be converted into postback events, by setting the AutoPostBack property of the control to true.
Validation events - These events occur on the client, before the page is posted back to the server. All validation controls use these type of events.
In Part 6, of this video series, we have understood that control events are processed after the PageLoad event. The picture below depicts the same. Among the control events, Cached events happen before PostBack events.
To understand the order in which Page and Server control events execute, add a Web form with a TextBox, RequiredFieldValidator, and a Button control. You can find RequiredFieldValidator under Validation tab, in the ToolBox. Double click the TextBox control on the WebForm, and the event handler TextBox1_TextChanged() will be automatically generated. Along the same lines, double click the Button control, Button1_Click() event handler will be generated. Right Click the RequiredFieldValidator control on the webform and select Properties. From the Properties window, Set ControlToValidate property to TextBox1. At this stage copy and paste the following code in WebForm1.aspx.cs.
protected void Page_PreInit(object sender, EventArgs e)
{
Response.Write("Page_PreInit" + "<br/>");
}
protected void Page_Init(object sender, EventArgs e)
{
Response.Write("Page_Init" + "<br/>");
}
protected void Page_InitComplete(object sender, EventArgs e)
{
Response.Write("Page_InitComplete" + "<br/>");
}
protected void Page_PreLoad(object sender, EventArgs e)
{
Response.Write("Page_PreLoad" + "<br/>");
}
protected void Page_LoadComplete(object sender, EventArgs e)
{
Response.Write("Page_LoadComplete" + "<br/>");
}
protected void Page_PreRender(object sender, EventArgs e)
{
Response.Write("Page_PreRender" + "<br/>");
}
protected void Page_PreRenderComplete(object sender, EventArgs e)
{
Response.Write("Page_PreRenderComplete" + "<br/>");
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
Response.Write("Text Changed Event"+ "<br/>");
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("Button Click"+ "<br/>");
}
Now, run the project, and when the webform renders, the page level events occur in the following order. Notice that, TextChanged and ButtonClick events are not fired.
Page_PreInit
Page_Init
Page_InitComplete
Page_PreLoad
Page_LoadComplete
Page_PreRender
Page_PreRenderComplete
Don't type anything in the TextBox, and click the button control. The RequiredFieldValidator message is displayed. No other events get processed and the page is not posted back to the server.
Now, enter some text, into the TextBox and Click the button. Notice that, Text Changed Event and Button Click, execute after Page Load and Before Page Load Complete events. Among the control events, TextChanged event is fired before the click event. The execution order is shown below.
Page_PreInit
Page_Init
Page_InitComplete
Page_PreLoad
Text Changed Event
Button Click
Page_LoadComplete
Page_PreRender
Page_PreRenderComplete
Part 4 - Events in the life cycle of a web application
Part 5 - Difference between ViewState, SessionState and ApplicationState
Part 6 - ASP.NET Page Life Cycle Events
In the previous parts of this video series, we have discussed that events can occur at application, page and control levels. In Part 4, we discussed application level events, and in Part 6, we discussed about Page Level events.
In this session, we will discuss about control level events. ASP.NET server controls, such as TextBox, Button, and DropDownList has their own events. For example, Button has a click event. TextBox has TextChanged event, and DropDownList has SelectedIndexChanged event. We have a set of asp.net validation controls, that has validation events. The events that all these controls expose, can be broadly divided into 3 categories.
Postback events - These events submit the Web page, immediately to the server for processing. Click event of a button control is an example for PostBack event.
Cached events - These events are saved in the page’s view state to be processed when a postback event occurs. TextChanged event of TextBox control, and SelectedIndexChanged event of a DropDownList control are examples of cached events. Cached events can be converted into postback events, by setting the AutoPostBack property of the control to true.
Validation events - These events occur on the client, before the page is posted back to the server. All validation controls use these type of events.
In Part 6, of this video series, we have understood that control events are processed after the PageLoad event. The picture below depicts the same. Among the control events, Cached events happen before PostBack events.
To understand the order in which Page and Server control events execute, add a Web form with a TextBox, RequiredFieldValidator, and a Button control. You can find RequiredFieldValidator under Validation tab, in the ToolBox. Double click the TextBox control on the WebForm, and the event handler TextBox1_TextChanged() will be automatically generated. Along the same lines, double click the Button control, Button1_Click() event handler will be generated. Right Click the RequiredFieldValidator control on the webform and select Properties. From the Properties window, Set ControlToValidate property to TextBox1. At this stage copy and paste the following code in WebForm1.aspx.cs.
protected void Page_PreInit(object sender, EventArgs e)
{
Response.Write("Page_PreInit" + "<br/>");
}
protected void Page_Init(object sender, EventArgs e)
{
Response.Write("Page_Init" + "<br/>");
}
protected void Page_InitComplete(object sender, EventArgs e)
{
Response.Write("Page_InitComplete" + "<br/>");
}
protected void Page_PreLoad(object sender, EventArgs e)
{
Response.Write("Page_PreLoad" + "<br/>");
}
protected void Page_LoadComplete(object sender, EventArgs e)
{
Response.Write("Page_LoadComplete" + "<br/>");
}
protected void Page_PreRender(object sender, EventArgs e)
{
Response.Write("Page_PreRender" + "<br/>");
}
protected void Page_PreRenderComplete(object sender, EventArgs e)
{
Response.Write("Page_PreRenderComplete" + "<br/>");
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
Response.Write("Text Changed Event"+ "<br/>");
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("Button Click"+ "<br/>");
}
Now, run the project, and when the webform renders, the page level events occur in the following order. Notice that, TextChanged and ButtonClick events are not fired.
Page_PreInit
Page_Init
Page_InitComplete
Page_PreLoad
Page_LoadComplete
Page_PreRender
Page_PreRenderComplete
Don't type anything in the TextBox, and click the button control. The RequiredFieldValidator message is displayed. No other events get processed and the page is not posted back to the server.
Now, enter some text, into the TextBox and Click the button. Notice that, Text Changed Event and Button Click, execute after Page Load and Before Page Load Complete events. Among the control events, TextChanged event is fired before the click event. The execution order is shown below.
Page_PreInit
Page_Init
Page_InitComplete
Page_PreLoad
Text Changed Event
Button Click
Page_LoadComplete
Page_PreRender
Page_PreRenderComplete
If you are searching life partner. your searching end with kpmarriage.com. now kpmarriage.com offer free matrimonial website which offer free message, free chat, free view contact information. so register here : kpmarriage.com- Free matrimonial website
0 comments:
Post a Comment