We have previously made a vest of the simplest TextBox. In this article, we will talk about the labels of custom controls. You may see that the Code dragged in the previous article is
<C0: TextEdit ID = "TextEdit1" runat = "server"> </PC3: TextEdit>. This is definitely not the expected result. The label "PC3" is not well named, it also makes people feel "too watery". Now let's improve the code.
System.ComponentModel;,)]
In fact, we only need to add one line of code. Let's take a look at the code at the UI Layer.
<% @ Page Language = AutoEventWireup = CodeBehind = Inherits = %> <! -- This line of code is automatically generated --> <% @ Register Assembly = Namespace = TagPrefix = %> <! DOCTYPE html PUBLIC>
We found that the label is still, and we will see the above <% @ Register Assembly = Namespace = TagPrefix = %>
TagPrefix = "PC3", we only need to change TagPrefix = "PC3" to TagPrefix = "XYB". Now let's drag another control to see it.
<% @ Page Language = AutoEventWireup = CodeBehind = Inherits = %> <! -- This line of code is automatically generated --> <% @ Register Assembly = Namespace = TagPrefix = %> <! DOCTYPE html PUBLIC>
Now, what has the label changed? <XYB: TextEdit ID = runat => </XYB: TextEdit>. Now we have changed, but let's take a closer look at our best practices. In the future, we will expand this class library, which encapsulates many classes. Do we add a sentence on every page?
[Assembly: TagPrefix ("XYB. controls "," XYB], <% @ Register Assembly = "XYB. controls "Namespace =" XYB. controls "TagPrefix =" XYB "%>? This is obviously unscientific. We should not mention the difficulties in maintenance, but will be despised in the future, and there will still be a lot of repetitive work.
- Modify configuration file
Modify the web. config file and add the following code under the <system. web> node:
<Pages controlRenderingCompatibilityVersion = "4.0" clientIDMode = "AutoID">
<Controls>
<Add namespace = "XYB. Controls" assembly = "XYB. Controls" tagPrefix = "XYB"/>
</Controls>
</Pages>
The entire configuration file code is as follows:
<?xml version= encoding=?><!-- --><configuration> <system.web> <compilation debug= targetFramework= /> <pages controlRenderingCompatibilityVersion= clientIDMode=> <controls> <add = assembly= tagPrefix=/> </controls> </pages> </system.web></configuration>
Now we can comment out the code dragged in before TextEditUI. aspx, or delete it. Delete the [assembly: TagPrefix ("XYB. Controls", "XYB")] code in the TextEdit class. Regenerate.
The TextEdit. cs code is as follows:
System.ComponentModel;
The HTML code is as follows:
<% @ Page Language = AutoEventWireup = CodeBehind = Inherits = %> <! -- This line of code is automatically generated --> <% -- <% @ Register Assembly = Namespace = TagPrefix = %> -- %> <! DOCTYPE html PUBLIC>
Let's drag a control in, and the label is changed.
<% @ Page Language = AutoEventWireup = CodeBehind = Inherits = %> <! -- This line of code is automatically generated --> <% -- <% @ Register Assembly = Namespace = TagPrefix = %> -- %> <! DOCTYPE html PUBLIC>
So far, it is a success.
Render renders controls and discusses the relationships between Render, RenderControl, and RenderChilden.