Using Controls

I l @ ve RuBoard

Controls are compiled code residing in .DLL files that can be accessed by the server. In many cases, these controls are part of the .NET Framework, but you can also create and use custom controls.

Declaring a Control

In order for a control to be visible to the application, it must be registered with the server. In traditional ASP, this was accomplished with regsrvr32. exe , and required you to shut down all Web services to make a change. In ASP.NET, registration is accomplished when the page is run via the Register directive:

 <%@ Register TagPrefix="cust" Namespace="MyCustomCtrls" Assembly="MyDLLFile" %> 

The preceding example assumes that the MyDLLFile.DLL file is in the bin directory for the application.

Referencing a Control

After the control is registered, add it to the page with the proper namespace alias to make it available from within the code.

 <script runat="server" language="VB"> function UserRanking     UserRanking = Scores.TopScore end function </script> <html> <head><title>Ranking Page</title></head> <body> <cust:Rankings id="Scores" sport="baseball" maxRanking="1000" runat="server" /> Your top score is <%= UserRanking %>. </body> </html> 
I l @ ve RuBoard


Asp. Net. By Example
ASP.NET by Example
ISBN: 0789725622
EAN: 2147483647
Year: 2001
Pages: 154

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net