C# Developeramp;#039;s Guide to ASP.NET, XML, and ADO.NET [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

C# Developeramp;#039;s Guide to ASP.NET, XML, and ADO.NET [Electronic resources] - نسخه متنی

Jeffrey P. McManus; Chris Kinsman

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید








Creating User Interfaces with Web Controls


The .NET framework provides a number of user-interface components that you can use.

These components are divided into several categories:


HTML controlsAn object-oriented way of creating standard HTML page elements such as text boxes and buttons.


Web forms controlsObjects that can incorporate standard and dynamic HTML into rich user-interface elements.


Validation controlsA type of Web form control specifically geared toward validating user input on a form, often without causing a round trip to the server. Validation controls are covered in Chapter 11, "Creating Database Applications with ADO.NET."



This section will show you how to use the controls that are included with the .NET framework. You can also create your own Web forms controlsChapter 9.

Programming Web Forms Controls


The first step to using Web forms controls on a page is to create an ASP.NET Web form. You do this by creating a conventional HTML FORM tag with the ASP.NET runat="server" attribute, as shown in Listing 2.25.

Listing 2.25 Basic ASP.NET Web Form Declaration


<form id='myform' method='post' runat='server'>
</form>

Control Event Model


Web controls raise events of their own as well as the events of the classes they inherit.

Web controls that inherit from System.Web.UI.WebControl.WebControl raise the events listed in Table 2.3.
































Table 2.3. Events Raised by Web Controls
Event
Description
DataBinding
Occurs Chapter 11.)
Disposed
Occurs when the control is destroyed; this is always the last event raised by the control.
Init
Occurs when the control is first created; this is always the first event raised by the control.
Load
Occurs when the control is loaded on the page.
PreRender
Occurs when the control is about to be rendered (displayed on the screen).
Unload
Occurs when the control is unloaded from memory.

Taking Advantage of Postback and View State


Postback is the Listing 2.5 demonstrated the HTML source of an ASP.NET Web page that contains chunks of encoded View state. Listing 2.26 shows a snippet of that voluminous code listing.

Listing 2.26 HTML Source for an ASP.NET Page Highlighting View State Information


<form name="WebForm1" method="post" action="calendar.aspx" id="WebForm1">
<input type="hidden" name="__VIEWSTATE" value="dDw1MzYzNjkxODU7Oz4=" />
<table id="Calendar1" cellspacing="0" cellpadding="2" border="0"
style="border-width:1px;border-style:solid;border-collapse:collapse;">
<tr>
<td colspan="7" style="background-color:Silver;">
<table cellspacing="0" border="0"
style="width:100%;border-collapse:collapse;">
<tr>
<td style="width:15%;">
<a href="'Calendar1','prevMonth')"
style="color:Black">&lt;</a>

Note that we've mercifully deleted the majority of the source code for brevity. YChapter 5, "Configuration and Deployment.")

Mobile Controls


The Microsoft.NET framework supports devices with small form factors and limited capabilities, such as mobile phones and Pocket PCs. These devices have demands on the user-interface developer that are totally different from the challenges presented by user-interface design on a desktop PC.

An in-depth discussion of mobile Web forms is beyond the scope of this book; however, many of the techniques discussed in this chapter will give you a good foundation for creating applications for mobile devices. Because the technical implementation (involving HTML, Dynamic HTML, WAP, and so forth) is abstracted behind the .NET Base Class Library, you can use similar programming techniques to code for Windows and Windows CE.

Data Binding


It is possible to bindChapter 11.

Determining Browser Capabilities


When you're creating a corporate intranet, you can often specify corporate standards for a Web browser. Although this tends to limit user choice, this is useful for the developer because it means you can utilize the capabilities of a specific Web browser.

For Web sites that are intended to be used by the general public, though, you can't know ahead of time what kind of browser the users will have. In this case, you may find it useful to have a programmatic way of determining things about the user's browser. For example, does the user's browser support JavaScript (or, perhaps, did the user deactivate JavaScript support)? How about cookies? Even though most modern browsers support them, users can choose to turn those off, too.

The HttpBrowserCapabilities class, found in the System.Web namespace, provides these capabilities in ASP.NET. An instance of an HttpBrowserCapabilities object is contained by the ASP.NET Request object (in this context an instance of the object, called Browser, is created for you automatically when a page is requested from the server). Listing 2.27 shows how to use this pre-created object to display information about the browser.

Listing 2.27 Complete Listing of All HttpBrowserCapabilities Contained in the Request Object


<%@ PAGE language='c#' debug='true' trace='false' %>
<HTML>
<HEAD>
<TITLE>ASP.NET Browser Capabilities</TITLE>
</HEAD>
<BODY>
<table width="350" border="0" cellspacing="1" cellpadding="3"
bgcolor="#000000">
<tr bgcolor="#FFFFFF">
<td>Supports ActiveX Controls</td>
<td><% =Request.Browser.ActiveXControls %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Is an America Online Browser</td>
<td><% =Request.Browser.AOL %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Supports background sounds</td>
<td><% =Request.Browser.BackgroundSounds %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Is a beta version browser</td>
<td><% =Request.Browser.Beta %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Browser name (user-agent)</td>
<td><% =Request.Browser.Browser %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Supports Channel Definition Format</td>
<td><% =Request.Browser.CDF %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Common Language Runtime version</td>
<td><% =Request.Browser.ClrVersion %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Cookies available</td>
<td><% =Request.Browser.Cookies %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Is this a Web search engine (&quot;crawler&quot;)?</td>
<td><% =Request.Browser.Crawler %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Version of JavaScript (ECMAScript) supported</td>
<td><% =Request.Browser.EcmaScriptVersion %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Supports frames</td>
<td><% =Request.Browser.Frames %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Supports client-side Java</td>
<td><% =Request.Browser.JavaApplets %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Supports JavaScript (ECMAScript)</td>
<td><% =Request.Browser.JavaScript %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Browser version</td>
<td>
<% =Request.Browser.MajorVersion + "." +
Request.Browser.MinorVersion %>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Microsoft XML Document Object Model version</td>
<td><%=Request.Browser.MSDomVersion %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Operating system platform</td>
<td><% =Request.Browser.Platform %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Supports HTML tables</td>
<td><% =Request.Browser.Tables %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Client browser type</td>
<td><% =Request.Browser.Type %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Browser supports VBScript</td>
<td><% =Request.Browser.VBScript %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Version of client browser</td>
<td><% =Request.Browser.Version %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>W3C HTML Document Object Model version</td>
<td><% =Request.Browser.W3CDomVersion %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Running 16-bit Windows?</td>
<td><% =Request.Browser.Win16 %></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Running 32-bit Windows?</td>
<td><% =Request.Browser.Win32 %></td>
</tr>
</table>
</BODY>
</HTML>

I used godless, archaic render blocks to create this page, mainly to make it easier for me to create, but also to make it simpler to read.

If you have more than one kind of browser installed on your computer, you may find it interesting to navigate to this page using both of them to see the different capabilities reported by the Browser object. For example, I found it interesting to learn that JavaScript 1.2 comes with Internet Explorer 6.0 beta, but that Opera 5.0 comes with the (presumably bigger and badder) JavaScript 1.3. Also, Opera doesn't return operating system platform information to the server the way Internet Explorer does. It's just as well; with well-designed Web applications, the server shouldn't need to know what operating system the browser is running on anyway.

/ 106