asp.net
First, ASP. NET page processing order
Asp. NET page is driven by events, the first is the Init event, in the code, the system automatically added a oninit overloaded function, so that when the page init to execute this oninit function. In this function, the InitializeComponent function is executed, in which there are many proxy functions for control events, and the Web Formdesigner generated Code of a page is expanded so that we can see these.
After the completion of the page init, is the Load event, the corresponding code is Page_Load.
Then is the code that causes the page to return the event, of course, if the page is the first time to run, there is no such a step.
That is, the page executes the Page_Load function every time it refreshes, which is why some code is written in
if (! Page.IsPostBack)
{ ... }
of the reason. For example, there is a text box, if you set the initial value in the Page_Load, where to put it? If it is placed outside the IF, the assignment statement is executed every time the refresh is made, even if the value of the text box is modified in the page, it disappears after the return, but if it is placed in the IF, it is OK, and the text box is still the previous value after the return.
Many friends of the DataGrid can't get the edited value, and that's probably the reason.
Second, the application of JavaScript in the page
Although ASP.net has adopted a new operating mechanism, it eventually generates HTML and JavaScript code that can be identified by a general browser.
In the page, you can still write a piece of JS code through Response.Write, such as to pop up a new browser window, you can use Response.Write (@ "<script language=javascript> window.open (' url ');</script> ");
In Web controls, the Attributes property collection is also closely associated with JS. A newly added attributes element corresponds to a property or event of the HTML code that was last generated by the Web control.
For example, there is a textbox that asks us to select all the text when it gets focus, so we can deal with it: textbox1.attributes["onfocus"]= "Javascript:this.select ();"; Through the view of the source code of the page in IE, we can see such a paragraph: <input Type=text...>, as to what means do not need me to explain it.
There is also an application, if there is a button, its Click event there are a lot of operations on the database, we require users to press the button after the confirmation once (this is a bit like the MsgBox in ASP), Now we can handle this: button1.attributes["OnClick"]= "Javascript:return confirm (' Are your
sure; '); The final effect is as we imagine.
Note: The above code runs through the codebehind. As for the combination of the Code and the page, it may be different in writing.
Third, about code reuse
Asp. NET has basically shifted to the OO level, where the code is basically performed through classes. As we write the C/s system, we use one or more classes to save the common functions and then call them in other functions.
Another way is to write to a base class, and other classes inherit the base class. As for that method, look at the personal hobby and the scope of the function.
One of the projects I did in the previous event was to do this with two base classes, one for the base class of the middle tier, and one for the base class of the Page class (inherited System.Web.UI.Page). Then put some of the database processing into the previous base class, the page control of some common operations into the latter base class.
Four, Web controls
There are several controls that we should have a deep understanding of: The DataGrid, the DataList. These two controls in the display of data for us to provide a great convenience, their various uses, we need to continue to explore in practice, and constantly summed up.
In addition, custom controls are a more important area.
On the type selection of a custom control, if you just display some of the intrinsic controls, not the attributes, the events, it would be simpler to write UserControl, a custom control that is equivalent to code executed by include in ASP. If you want to modify the properties of controls inside the design, run, and get some of the control's events, it is best to write a DLL file, that is, to write a class, such a control can be like a typical Web control, drag the mouse size, set properties, get events, and so on.