Prev | Current Page 99 | Next

Rob Cameron and Dale Michalk

"Pro ASP.NET 3.5 Server Controls and AJAX Components"


After publishing is completed, go to the target location specified in the Publish dialog, and
look in the bin directory for an assembly named something like App_Web_simpleusercontrol.
ascx.5b4d926a.dll. This is the SimpleUserControl.ascx compiled to an assembly and is ready
to be used as a server control.
52 CHAPTER 2 ?–  ENCAPSULATING FUNCT IONALITY IN A SP.NET
Next, add the assembly to a test web application by right-clicking the application, selecting
Add Reference, and browsing to the user control assembly. The next step is to make the server
control available on a web form by registering it:
<%@ Register TagPrefix="apressuc" Namespace="ControlsBook2"
Assembly="App_Web_simpleusercontrol.ascx.5b4d926a.dll" %>
The final step is to add a tag to the .aspx page:

While it is possible to deploy a user control in a similar manner to a custom server control
as shown in the preceding example, deployment of a user control as an .ascx file is a bit more
straightforward and probably more applicable where user controls are of most interest, which
is for sharing code internal to an organization.
The design-time rendering of user controls and the ability to deploy a user control as an
assembly are welcome ASP.


Pages:
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111