TAILIEUCHUNG - Professional ASP.NET 1.0 Special Edition- P7
Professional Special Edition- P7:Those of us who are Microsoft developers can't help but notice that .NET has received a fair amount of visibility over the last year or so. This is quite surprising considering that for most of this period, .NET has been in its early infancy and beta versions. I can't remember any unreleased product that has caused this much interest among developers. And that's really an important point, because ignoring all the hype and press, .NET really is a product for developers, providing a great foundation for building all types of applications | be using in the page. @ Register tagprefix wrox Tagname footer Src Next we need to add it to the page where we want this information to be displayed. wrox footer runat server When we view the page in the browser we will see this on the page Converting a Page to a User Control Now that we can see how easy it is to create a user control from scratch let s look at the more common way of creating a user control. As you are developing your web application you will probably come across sections of code that you are using on multiple pages. In the past your options were to create an include file that kept the code in a single location or maybe creating a design-time control for Visual Studio. But neither of these methods was really that simple or straightforward to use. And all developers know that if something isn t simple and straightforward then chances are it won t get used. But now with user controls we can take that code segment from our existing page and turn it into a control that can be easily reused in multiple pages. At the beginning of this chapter we saw an example that enabled you to select from a list of shipping methods. This page included the database code to retrieve the list as well as the controls to display the list. If we can package that logic into a reusable control then we can ensure that wherever we need a list of shippers in our application or applications the data will be retrieved and displayed in the same way. A similar technique is used in Chapter 8 to build a control that returns data. The first part of our control will be the display. The selection list is a drop-down list server control. We will leave what to do with the data in the control up to the page that is hosting the control. Since the server control is using data binding the code that makes up the display will be quite simple. asp DropDownList id ShipMethod runat server The main work of the page is done in the code that sets up the page. Since in .
đang nạp các trang xem trước