New page events:
In 2.0, the life cycle of a page is mainly (represented in red fonts 2.0 newly added phase page events): Client request page—》Pre-initialization (OnPreInit)—》Initization (OnInit)—》Complete initialization (OnInitComplete)—》Load ViewState (LoadViewState)—》processing of loopback data (IPostBackDataHandler)—》Page_OnPreLoad—》Page_OnLoad—》PostDataChange dEvent)—》Processing postback events (RaisePostBackEvent)—》Page_OnLoadComplete—》Prepresentation (OnPreRender)—》Complete pre-representation (OnPreRenderComplete)—》SaveControlState (SaveControlState)—》SaveViewState (SaveViewState)—》Page_UnLoad.
OnPreInit: Triggered before the OnInit event of the initialization page. In this stage, operations such as defining the site theme (Theme) or loading the data information required for site personalization can be performed.
OnInitComplete: Triggered after the OnInit event is completed on the initialization page.
OnPreLoad: fired before the OnLoad event on the page is loaded.
OnLoadComplete: fired after the OnLoad event is completed.
OnPreRenderComplete: Fired after the pre-rendering of the OnPreRender event is completed. This is the last level to complete the page rendering, after which the page will no longer be able to make any changes in the rendering.
SaveControlState: Save the control status ControlState. ControlState is a new attribute added to ASP.NET 2.0 control, similar to ViewState, but the difference is that ControlState is used to save more important control status information to ensure that the control status can be read and written when ViewState is disabled.
Increase control over the page header:
The class has added a new Header attribute to operate on data in the HTML page header area. By tracking the header attribute, it can be found that the header attribute holds an object that implements the IPageHeader interface (the object has four attributes: LinkedStyleSheets, Metadata, StyleSheet and Title), which is actually the operation of data in the HTML page header area through this object. For example:
<script runat="server">
void Page_Load(object sender, e)
{
("author", "*s");
}
</script>
The operation result is:
<html>
<head> <title>Untitled Page</title>
<meta name="author" content="*s" />
</head>
Define the default button in the form:
In ASP.NET 1.0, I was helpless to set the default buttons in the form. Fortunately, ASP.NET 2.0 has added this function, and now it is very convenient to set the default button in the form.
<%@ page language="C#" %>
<script runat="server">
void Button1_Click(object sender, e)
{
this.LB_Message.Text = "You clicked button1";
}
</script>
<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form runat="server" defaultbutton="Button1">
<asp:textbox runat="server"></asp:textbox>
<asp:button runat="server" text="Button" onclick="Button1_Click" />
<asp:label runat="server"></asp:label>
</form>
</body>
</html>
Set focus:
Now assume that you set the focus for the TextBox1 control, it can be implemented in 2.0 like this:
this.(); or (this.Textbox1); sets focus for the TextBox1 control.
If you plan to set a default focus control for the form, let the cursor stay on TextBox1 by default:
<form runat="server" defaultfocus="TextBox1">
Cross-page data sending:
If you need multiple pages to send data to the same form program for processing, or the data is transferred between multiple pages, you can use the new feature of 2.0. For example, I plan to send the text data in TextBox1 in the page to the page for processing:
Page:
<%@ Page Language="C#" %>
<script runat="server">
void Button2_Click(object sender, EventArgs e)
{
= "Hi," + + ". This is ";
}
</script>
<html xmlns="http:///1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form runat="server">
<asp:TextBox ID="TextBox1" Runat="server"></asp:TextBox>
<asp:Button ID="Button1" Runat="server" Text="PostToAnotherPage" PostBackUrl="~/" />
<asp:Button ID="Button2" Runat="server" Text="PostToSelf" OnClick="Button2_Click" />
<br />
<asp:Label ID="Label1" Runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
Page:
<%@ Page Language="C#" %>
<script runat="server">
void Page_Load(object sender, e)
{
TextBox textBox1 = (TextBox)("TextBox1");
this. = "Hi," + + ". This is !";
}
</script>
<html xmlns="http:///1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form runat="server">
<asp:label runat="server"></asp:label>
</form>
</body>
</html>