Server Control Samples
The following table lists simple samples that show how to perform server control authoring tasks.
|Authoring a simple server control||Developing a Simple ASP.NET Server Control|
|Exposing properties from a control||Custom Property Sample|
|Rendering a server control||Rendering a Server Control Samples|
|Processing postback data||Postback Data Processing Sample|
|Exposing an event||Defining an Event|
|Capturing a postback event||Postback Event Sample|
|Bubbling an event||Event Bubbling Control Sample|
|Generating client-side script for postback||Postback Using Client-Side Script Sample|
|Using a hidden variable for capturing client-side changes||Persisting Client-Side Changes in a non-Form Control|
|Developing a composite control||Composite Server Control Sample|
|Using rendering instead of control composition||Composition vs. Rendering|
|Developing a templated control||Templated Control Sample|
|Governing control parsing with ParseChildrenAttribute||ParseChildrenAttribute Sample|
|Creating a custom control builder||Custom Control Builder Sample|
The following table lists more complex samples (similar to those that ship with the SDK).
|Templated data-bound control||Templated Data-Bound Control Sample|
|Validator control||Validator Control Samples|
For a sample of a designer for the templated data-bound control, see Web Forms Templated Data-Bound Control Designer.
Building the Samples
The instructions for building the validator samples are described in Validator Control Samples. Instructions for building other samples in the preceding tables are in the following list.
To build the samples
- Create an Internet Information Services (IIS) virtual rooted directory (named
Samplesin this discussion).
- Create a subdirectory named
binunder the virtual rooted directory (for example,
bindirectory contains assemblies (compiled .dll files) that are local to your ASP.NET application. You can create subdirectories under your virtual rooted directory (for example
Samples\DataBoundControls, and so on). However, you must create only one
bindirectory and it must be directly under the virtual rooted directory (
- Copy the ASP.NET pages (such as .aspx, .ascx, .asax, and .asmx) and source files (such as .cs or .vb) to the virtual rooted directory. If you do not want a user to browse to source code in a deployment scenario, you can copy the source files (.cs or .vb) to a separate directory not under the virtual root. The ASP.NET pages, however, must be placed in the virtual rooted directory (
Samples) or one of its subdirectories (
- From the virtual rooted directory (or the directory that contains the .cs or .vb source files), execute the following command. If the command is executed from a directory that is not the virtual rooted directory, you will have to supply the path to the
csc /t:library /out:./bin/CustomControls.dll /r:System.dll /r:System.web.dll /r:System.Drawing.dll *.cs [Visual Basic] vbc /t:library /out:./bin/CustomControls.dll /r:System.dll /r:System.web.dll /r:System.drawing.dll /r:System.Data.dll *.vbNote The assembly that is generated by the above command must be namedCustomControls.dllbecause the assembly nameCustomControlsis used in the Register page directive on the sample .aspx pages.
- Request a sample .aspx page in your browser by entering one the following commands in the address bar.
http://YourMachineName/Samples/Filename.aspxNote You can build the sample incrementally by copying only the files you are interested in and executing the build command in step 4. When you want to add more samples, copy the additional ASP.NET pages and source files to the appropriate directories and reexecute the build command in step 4.
For additional information about deploying ASP.NET applications see the ASP.NET QuickStart --> Deployment.