ASP.NET Cookbook: The Ultimate ASP.NET Code Sourcebook
|
| Price: |
21 new or used available from £3.29
Average customer review:Product Description
Developers who want to create dynamic, data-driven web sites running on Microsoft web servers have long relied on Active Server Pages (ASP). ASP.NET is Microsoft's latest evolution of ASP. While ASP.NET has a lot in common with its predecessor, this new technology takes advantage of object-oriented programming to dramatically improve developer productivity and convenience. Using the .NET Framework and Microsoft's new object-oriented languages, ASP.NET brings the same rapid drag-and-drop productivity to web applications that the Visual Basic programming language brought to Windows applications. ASP.NET also introduces web services, which allow developers to expose the functionality of an application via HTTP and XML, so that clients on any platform can access it via the Internet. ASP.NET is not a simple upgrade of ASP. It s a quantum leap ahead. There are many benefits to using ASP.NET, and one major drawback: the time developers must devote to mastering this new Web application technology. The ASP.NET Cookbook provides a wealth of plug-and-play solutions to problems commonly encountered when developing ASP.N ET web applications and services in the popular problem-solution-discussion Cookbook format. The coding solutions in ASP.NET Cookbook appeal to a wide range of developers, from the inexperienced to the expert. For every problem addressed in the book, there's a worked-out solution or recipe a short, focused piece of code that web developers can insert directly into their applications. Developers can save hours by using just a single one of over 100 recipes included in this invaluable cookbook. But the ASP.NET Cookbook provides far more than just a wide range of cut-and-paste code solutions. Each recipe is followed by a discussion including tips, tricks, and possible pitfalls--so developers can learn to adapt the problem-solving techniques to a myriad of similar situations. Each recipe provides an immediate solution to a pressing problem, while simultaneously allowing developers who prefer to a hands-on learning style with the experience they need to master ASP.NET. This ultimate ASP.NET code sourcebook will quickly earn the dog-eared corners and coffee rings that mark a web developer's most valued resource.
Product Details
- Amazon Sales Rank: #463803 in Books
- Published on: 2004-08-23
- Original language: English
- Number of items: 1
- Binding: Paperback
- 650 pages
Editorial Reviews
About the Author
Michael Kittel has nearly 30 years experience in the software industry. He has been working with Microsoft technologies for more than 10 years and with ASP.NET since the alpha release of 1.0. He has been the system architect and led the development of applications for Lexis-Nexis, Plow & Hearth, ReturnBuy, and many others. Michael has a Microsoft Certified Solutions Developer certification and is currently a senior consultant at Dominion Digital, Inc. (www.dominiondigital.com), a firm that specializes in helping companies envision and achieve maximum business value from investments in technology.
Geoff LeBlond is the co-author of Using 1-2-3, the first computer book that sold over 1 million copies. Geoff is the author of numerous computer books, and was the developer of Oriel, an early scripting language for Microsoft Windows. More recently, Geoff has been focusing his attention on developing web applications using ASP and ASP.NET.
Excerpted from ASP.NET Cookbook by Michael A. Kittel, Geoffrey T. LeBlond. Copyright © 2004. Reprinted by permission. All rights reserved.
CHAPTER 12 Dynamic Images
12.0 Introduction
The ability to draw or retrieve and display graphic images on your web pages on the fly can add powerful functionality to an application. This is a nearly impossible task in classic ASP, unless you use a third-party component of some kind. By contrast, the drawing library provided in the .NET Framework makes it relatively easy to create your own images when you need them. Indeed, it provides the ability to do almost anything you can imagine in the way of image generation. The examples shown in this chapter show you how to:
• Draw button images on the fly using text generated during the running of your application
• Create bar charts on the fly
• Display images stored in a database
• Display thumbnails from full-sized images stored in a database
These represent just a sampling of what you can do with the .NET drawing libraries and a little bit of custom code.
12.1 Drawing Button Images on the Fly
Problem
You need to create a button image on the fly using text generated during the running of your application.
Solution
Create a web form that is responsible for creating the button image using the System.Drawing classes and then streaming the image to the Response object.
In the .aspx file, enter an @ Page directive, but omit any head or body tags. The @ Page directive links the ASP.NET page to the code-behind class that draws the image.
In the code-behind class for the page, use the .NET language of your choice to:
1. Import the System.Drawing and System.Drawing.Imaging namespaces.
2. Create a makeButton (or similarly named) method that creates a bitmap for a button using text generated during the running of the application—for example, text passed in on the URL.
3. Create a MemoryStream object and save the bitmap in JPEG format (or other format) to the memory stream.
4. Write the resulting binary stream to Response object.
Examples 12-1 through 12-3 show the .aspx file and VB and C# code-behind files for an application that creates a button image whose label is provided by the application user.
To use a dynamically generated image in your application, you need to set the Src attribute of the image tags for your button bitmaps to the URL of the ASP.NET page that creates the images, passing the image text in the URL.
In the .aspx file for the page, add an img tag for displaying the dynamically created
image.
In the code-behind class for the page that uses the image, use the .NET language of your choice to set to the Src attribute of the image tag to the URL for the web form that will draw the image, passing the text it needs in the URL.
Examples 12-4 through 12-6 show the .aspx file and VB and C# code-behind files for an application that uses the dynamic image generation. Figure 12-1 shows some typical output from the application.
Discussion
Creating button images on the fly can be handy for a couple of related reasons. First, using button images may help provide the look you want for your application. Second, generating them on the fly can avoid you having to create and save a wholeseries of button images to the filesystem on the prospect that they may be needed someday. For example, you might want to use images to improve the appearance of reports.
The approach we favor for generating images on the fly involves first drawing them and then streaming the images to the Response object. How does this work? The process begins when the browser first makes a request for a page to display. During the rendering of the page, whenever the browser encounters an image tag, it sends a request for that image to the server. The browser expects the server to stream the requested image back to the browser with the content type set to indicate an image of a certain type is being returned—for example, "image/jpg", indicating an image in JPEG format. Our approach does exactly that, but with a unique twist. Instead of a static image, which is the norm, our approach returns an image that has been created on the fly on the server. The browser neither knows nor cares where the stream is coming from, which is why our approach works just fine.
Two web forms are used in our example that illustrates this solution. The first one renders no HTML but instead processes a user request for a dynamically created button image. A second web form is used to display the requested image.
The .aspx file of the first form contains no head or body; it simply contains the @ Page directive to link the code-behind class for the page.
In the Page_Load event of the code-behind of the first page, the text for the image button passed in the URL is retrieved and passed to the makeButton method to create the button image.
Customer Reviews
So relevant and easy to understand
Moving over to ASP.NET from ASP was not proving to be an easy step. Having baffled myself trying to read Essential ASP.Net by Fritz Onion (obviously only for very experienced programmers), I needed an easier read with easy to find and implement examples.
This book is exactly what I needed.
It states The Problem, The Solution, The Discussion and the code in VB.Net and C# for approx 100 day to day problems. I knew from the minute I picked the book up and flicked through the contents I would be using many of the examples!
It has numerous tips and details about the steps required to get to the solution, and commented code throughout the examples so you can work through and understand it. It is also layed out brilliantly so is very readable and your eye is drawn to the most relevant pieces of information.
A very good book, but not for complete beginners.
disappointing
I have had chance to look at the C# cookbook and was very impressed. I assumed this would be of a similar standard, I was wrong. This is pretty basic, the .NET 2.0 features disappointed me. If you are a beginner with ASP.NET then by all means have a look at this book, it will save you time getting up to speed. Anyone who has prior experience, stay away.

