Professional Documents
Culture Documents
Windows Programming
User Controls
Department of Computer Science and Engineering
University of South Carolina
Columbia, SC 29208
User Controls
We have seen that the .NET FCL contains 28 Web Controls, 21
HTML Controls, and 6 Validation Controls, all of which can be used
in Web Forms.
UseHello.aspx File
<%@ Register TagPrefix="user
user"
TagName="Hello
Hello" src="Hello.ascx
Hello.ascx" %>
<html> Hello.ascx File
<body>
<form runat="server"> <h1>Hello, world</h>
<user:Hello RunAt="server" />
</form>
</body>
</html>
This control uses two classes: LoginEventArgs and LoginBase, both written
into a .cs file (figure 7-9).
In this sample the code explicitly derives the script portion of the control from
UserControl.
Note that ASP.NET does that in the previous samples, when the script code of
the control is compiled, ASP.NET derives an object from the base class
UserControl.
The control has a Title and a navigation bar that appears on the
left side.
When users select from the choices in the left bar, the content
is displayed on the main portion of the control, to the right
side.
Note that all that is needed to use this control is an XML file
that contains the titles and the paths to the selection, as shown
in file Links.xml, figure 7-13.
Everything else is script code that is used to create <a ref… >
tag elements:
<a href="News.aspx"
onmouseover="defcolor=this.style.color;
this.style.color='Black'"
onmouseout="this.style.color=defcolor" Properties of the tag
style="text-decoration: none;
font-family: verdana; font-size: 10pt;
font-weight: bold; color: White“
>
News
</a>
The name of the class is selected by ASP.NET when the new class is
compiled. Alternatively, it can be specified as:
<%@Control ClassName = “XmlNavBarControl” %>
// Name must match in the <%@Register directive>