Basic concepts of Asp.net webcontrols

Source: Internet
Author: User

Definition

WebcontrolsYou can drag and dropAsp.netOn the page, you can set attributes during design to encapsulate some good information.WebcontrolsCan be greatly improvedCodeEfficiency and code quality.

Several Concepts

WebControl Library Project

CreateWebcontrolsInVSCan be createdWebControl library project. By default, all class files under the project are inherited fromSystem. Web. UI. webcontrols. webcontrol

Render

Create webcontrol rewrite this method. , this method is used to output HTML to the output stream, yes webcontrol is displayed on the page. Equivalent to winform Control onprint ()

understand custom Web Form Control the key lies in the render method, this method is conceptually the same as the Windows form onpaint method, the difference is that the former sends HTML , the latter calls GDI . When Asp. net when the server framework assembles a Web form page in response to user requests, it creates controls listed on the page, sets the properties and persistent data of these controls, and then calls each of them render methods. The framework actually tells the control: "You are active and in the expected state. You need to tell me your appearance, because I have no other way to understand it ." Web the author of the Form Control places some code, to send HTML , tell the browser how to view the current status and attributes of the control, and any other information in the environment related to the control to display the control's appearance.

Asp. net when the Framework calls the render method of the control, A system. web. UI. htmltextwriter type object. This is similar to the onpaint method in the Windows form control. received system. windows. forms. painteventargs graphics member. Both represent the connection to the Framework. The framework positions the output to the corresponding position. htmltextwriter methods, attributes, and constants enable your control to HTML send to the output page that will be sent to the client browser. In the sample code, I first called the method addstyleattribute , this method internally creates a style HTML attribute, set the value to the value of the forecolor property inherited by the Control and add it to the internal buffer zone. You can add a style added value of attributes; you can add other attributes by calling the addattribute method

Page. getpostbackeventreference

 To implement this method, you must inherit the interfaceIpostbackeventhandlerFor ProcessingPostBackYou can process view status and control events here.

MethodPage. getpostbackeventreferenceCauseHtmlScript, and returnHtmlString

The server-side control is calledIpostbackeventhandlerAnd rewriteRaisepostbackeventMethod to receive the input notification

Event Processing

WebEvent processing in the form control includes two necessary parts and an optional third part. FirstRenderThe method must generate a clientHtml, TheseHtmlThe control is sent back when an event of interest occurs on the client. Second, your control must be implementedIpostbackeventhandlerInterfaceASP. NETNotifies your control that it has received the response and sends additional information about it. Next is an optional part. Your control can (probably) be used. NetEvent, so that other controls can receive notifications of these events

Viewstate(View status)

 This does not need to be explained.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.