The declarative Syntax of user controls is very similar to the syntax used to create ASP. NET web pages. The main difference is: the use of User Controls @ Control command replaced @ Page command, and the user control does not include html, body, and form elements around the content.
So how can we use this?
In general, we drag the solution manager directly to the corresponding location on the page. So, after we drag it, what is the difference between the page and other controls? The problem persists until we make an instance (selling points first). In addition, like other controls, it can be dynamically added during page loading.
We generally consider placing multiple user controls in a separate folder. So here we should remind you that, it is easy to place a user control in APP_Code. If a user control is in the App_Code folder, an analysis error will occur when running the page containing the control.
There is another situation, that is, we want to directly change the existing asp.net page to a user control. Is that feasible?
The answer is yes. You can. People who want to learn more about me must know what I want to say. Hey hey, indeed, I am very lazy, So I pasted it on MSDN, you can take a look.
Convert a single-file ASP. NET webpage to a user control
Rename the control so that its file extension is. ascx.
Remove html, body, and form elements from the page.
Change the @ Page command to the @ Control command.
Remove all attributes except Language, AutoEventWireup (if any), CodeFile, and Inherits in the @ Control command.
The @ Control command contains the className attribute. This allows the user control to be strongly typed when added to the page.
Code hiding ASP. NET web pages into user controls
Rename the. aspx file so that the file extension is. ascx.
Based on the programming language used by the Code hiding file, rename the code hiding file so that the file extension is. ascx. vb or. ascx. cs.
Open the code hiding file and change the class inherited from this file from Page to UserControl.
In the. aspx file, perform the following operations:
Remove html, body, and form elements from the page.
Change the @ Page command to the @ Control command.
Remove all attributes except Language, AutoEventWireup (if any), CodeFile, and Inherits in the @ Control command.
In the @ Control command, change the CodeFile attribute to point to the renamed code hidden file.
The @ Control command contains the className attribute. This allows the user control to be strongly typed when added to the page.
Video download address 1 address 2 address 3