In the previous chapter, we wrote one of the simplest custom controls. This time, let us leave the theory behind and develop a practical custom control: a menu that allows you to set permissions.
In this project, we will not use any unlearned theoretical knowledge. Users only need to have basic DHTML knowledge. As you know, server controls are nothing more than HTML and Javascript encapsulation. As for other techniques, we will gradually introduce and apply them in the future to produce commercial controls.
The idea of making this control is simple: first, use DHTML to write a menu, then extract the attributes, and then encapsulate the script and HTML display code, at last, rewrite the Render method as a parameter. You see, it's that simple.
If you do not want to read the code through the browser (it is really annoying), you can download the source code of this project from the following address, including the source code of this custom control and various test files: different data sources and permission settings.
Http://user1.7host.com/cashtsao//CashMenu0110.zip
First, declare an enumeration type MainMenuAlign in the namespace CashControls:
Public enum MainMenuAlign
{
/// <Summary>
/// Left
/// </Summary>
Left = 0,
/// <Summary>
/// Intermediate
/// </Summary>
Center = 1,
/// <Summary>
/// Right
/// </Summary>
Right = 2
}
Then declare the class CashMenu inherited from WebControls and declare the following variables and attributes:
Variable:
Private System. Web. HttpContext contextObject;
Private System. Xml. XmlDocument oXmlDoc = new XmlDocument ();