User control

zhaozj2021-02-16  59

Need more personalized controls, then you will have two options, and the user control user control custom control Custom Control write a custom control is essentially a new Server control. difficulty

In fact, the ordinary web form program can be modified to become a user control, and when a web form program is used as a Server control, this webform program is called the "User Control" user control extension as "ASCX" user The control is required to use the Register directive in other programs to use it. <% @ Register tagprefix = "Error! The hyperlink reference is invalid." Tagname = "error! Super link reference is invalid." SRC = "Pathname"%> TagPRefix determines the unique naming control (Namespace) of the user control, multiple user controls The same tagprefix tagname is the name of this user control. This name can be taken, which is used to distinguish between multiple user controls in the same page. The reference form of the user control is: When defining properties in the user control, it is important to note that the modifier of the attribute value must be a public because the interpretation of the user control is based on the class (Class) as prototype, so only the publication of the publication of the user has access to the properties in the user control. .

When defining the time processing of the user control, you must be aware that the public modifier cannot be used because the event can only occur inside the user control. If you use public modifications, you can use external access, which is obviously not ruled, so you can only use private. Make modification (because the default modifier is private, so the program can be omitted) The other common mistake is to use the HTMLFORM control in the user control. This is also not allowed because HTMLFORM controls often appear in the page of the reference control. If the HTMLFORM control is also included in the user control, the nested use of the HTMLFORM control will appear, which is logically unreasonable, and it is inevitable.

Creating User Controls in the program code In Web Form, user controls can be created not only by: can also create Control Cl = LoadControl like other Server controls ("Pagelet7.ascx"); (Pagelet7cs) C1) .category = "business"; page.controls.add (c1);

DIM CL As UserControl = LoadControl ("Pagelet7.ascx") CType (C1, (Pagelet7_ascx)). Category = "Business" Page.Controls.Add (C1)

Varcl: UserControl = loadingControl ("Pagelet7.ascx"); (Pagelet7_ascx (C1)). Category = "Business"; page.controls.add (c1);

转载请注明原文地址:https://www.9cbs.com/read-18549.html

New Post(0)