Using the Validation Controls
The demonstration application we provide includes a page that you can use to experiment with the validation controls open the Other Controls section of the left-hand menu . The page contains several textboxes where you have to enter specific values in order for validation to be successful. If you enter invalid values and then click the Submit button, a summary of all the errors is displayed errer LonLrol emami rai.Hr - MicreisaFt Internet 1 Kplarer I 4 - 0 i l3 I SHidi SjFavDfhE l rtjdia l jB '...
No Tools Required
Like ASP, ASP.NET requires no additional development tools. Everything we need to develop, deploy, and debug ASP.NET applications - or any other type of .NET application - is part of the .NET Framework SDK. For hard-core developers who want to save money, or just don't like IDEs, this minimalist approach to ASP.NET application development is certainly not restrictive in any way. Visual Studio .NET isn't remarkably cheap. However, for the price we'll get an allinone common IDE capable of...
Dt7i
i 1 L ivisili fr IrtiSM ths iflKUCe AwfcatioftrHmei Dfcaii gt -i Atp hHifpigt dfl, opens I Uflp Detaagna I v Ldv'is i -M jiudluni sij. D WINNT Mckji AH ET FrjfiB k ssck cwihlntyhicnmim hfran nik,k mHh CWMNNTWrnftftNETifMntwoilA asiiii ELV HNN 'JHutK gt i.NiiJ-ijMim jikl. flspk cawihnr'jhkidkftnltyum 1. i-il WINH Miao .rtrv Fiiiin lt l- vadsco cwinn ,j c ox fl e' flaylewlort mi CW1NHtWiii3S WT lt flm WMk snap CiWlhlNTlJiti Tlfra iik CVWIhlhUMicnMiJtWUFrwMiwoik'i GETJIDW GET HE GFT.HEAS IjETiHE ,...
Accessing Complex Data with a DataReader
We saw in the previous chapter how the DataReader object can be used to quickly and efficiently extract a rowset from a data store. We simply create a Connection object, use it to create a Command object for this connection, and then call the ExecuteReader method of the Command object. It returns the new DataReader object. The example code, like many of the relational data access examples in the previous and in this chapter, uses a separate user control that exposes the specific connection...
Stateless Versus Stateful
HTTP is a stateless protocol, and this doesn't change for ASP.NET Web Services that use HTTP to transport SOAP messages. ASP.NET provides workarounds for this stateless barrier, but the workarounds rely on the use of a session token which can either be stored in an HTTP cookie, or embedded within the URL. We should definitely take the stateless nature of HTTP into account when building web applications. If we need to solve that stateless problem with a solution such as Session state, it's worth...
Specifying Users and Groups
As well as simply specifying Windows authentication, we can also provide a list of users and groups that will be able to access the application. This is done within the lt authorization gt section of the web.config file, with a series of lt allow gt and lt deny gt elements. The general form of each of these elements is lt allow roles comma-separated list of Windows account group names users comma-separated list of Windows user account names verb GET POST HEAD lt deny roles comma-separated list...
Info Wnq
A server control could use it for one of its object properties, MyObject, as follows SampleClassProperty _exampleObjectProperty new SampleClassProperty public SampleClassProperty MyObject get return _exampleObjectProperty By enabling object properties to be initialized, server controls can group logically related attributes together and easily expose them on one or more controls, with very little code. The style object, used by most ASP.NET controls, is a good example of this. Another way of...
Events in Action
To support an event in our textbox control we first define a public event of the type EventHandler called TextChanged public event EventHandler TextChanged or in VB Next, we change the LoadPostData implementation to always return true _value postCollection postDataKey return true This will cause the RaisePostDataChangedEvent to be called, from which we know it is safe to raise events caused by postback. In this method we use the delegate to raise a TextChanged event, assuming there are...
Page ViewState
In this new round-trip model of Web Forms, there are potentially more interactions with a server than there would be in a traditional browser-server interaction. But at the core it is still stateless HTTP communication. This means that the server doesn't retain any information about the previous client request, such as values in form fields, or the state of objects instantiated to create the page. This would normally mean that the server is doing a lot of extra work in recreating the page each...
How Does AutoPostBack Work
The mechanism to implement automatic postback is simple. It uses exactly the same techniques as we would use if we were programming it ourselves in a lt form gt page. When the AutoPostBack property is True, the server control adds a client-side event to the control - for a buttontype control it is the onclick event, and for textboxes and list controls it is the onchange event lt input id MyControl type checkbox name MyControl gt This causes a client-side function named_doPostBack to run when...
Info Kps
- Purlin.i' Lht LQIltr Ola Other Controls - iijjuL- J LL L 1 TtJftSaK uiiixlength r rnrt- Ki 1 y- r lt - irln n'. p- irt_IT7riJ -ri rrril11 1 r'. r-ITrviT--r - -iTir- rryr._ rT oucj-.suge JoJ'osi Lac.i 1 HyContcDl , ' ' w liiDCT siii- avsiccipt gt
Using the SOAP Header
Let's look at how we use this proxy, along with its SOAP header to send additional data with the Web Service request. The following is a simple ASP.NET page written in VB.NET that uses the proxy lt Import Namespace Simple gt lt script runat server gt Public Sub Page_Load sender As Object, e As EventArgs ' Create a new instance of the UsingSoapHeaders ' proxy class used to call the remote .asmx file Dim soapHeaderExample As New UsingSoapHeaders ' Create a new instance of the mySoapHeader class...
Ccd
Once created, the object can be added to the collection Dim CCDC As New CounterCreationDataCollection CCDC.Add CCD Wrox Press Counters, CCDC This process can be abbreviated by combining creation and addition into one line, making adding multiple counters easier to read Dim CCDC As New CounterCreationDataCollection CCDC.Add New This counter is counter 1, _ CCDC.Add New This counter is counter 2, _ CCDC.Add New _ Counters per second, _ Wrox Press Counters, CCDC The allowable values for...
Custom Sampling
There are several ways in which you can extract the values from performance counters. The simplest, and quickest, is to examine the value of the RawValue property, which gives the uncalculated value of the counter. When using this value, you should remember that it represents the counter value at its last sampling, and may only represent a transient state. For example, a counter measuring CPU utilization may have high fluctuations, and the RawValue property will only reflect this if you happen...
Reading and Writing Files
The File and FileInfo classes provide a number of helper methods that can open and create files. These methods don't actually perform the reading and writing of files, rather they instantiate and return other classes, such as FileStream, for reading and writing bytes of data to and from a file StreamReader for reading characters from a stream StreamWriter class for writing characters to a stream The following code example shows how we can open a text file using the static OpenText method of the...
Sorting the List IComparer and IComparable
Collection classes such as ArrayList and Array use the System.Collections.IComparer interface to determine equality when they are sorting collections. This interface is used to establish if a type instance is less than, equal to, or greater than another type instance and has a single method called Compare public int Compare object x, object y Classes that implement this interface should check for equality between the objects passed in, and return one of the following Any negative value if...
The Code for this Example Page
The page contains the customary lt div gt elements to display the results and messages, and details of any errors that we encounter. It also creates the paths to the existing and new documents, and displays a hyperlink to the existing document. This is identical to the previous example, and we aren't repeating the code here. Instead, we start with the part that loads the existing document into a new XmlDocument object Dim objXMLDoc As New XmlDocument Try objXMLDoc.Load strXMLPath Catch objError...
Locking Down via Configuration Section Handler
If the settings specified in machine.config are acceptable defaults, and we don't want those settings changed by applications that inherit those settings, we can use the optional allowDefinition attribute on the configuration section handler. Let's look at an example. Below are the values taken from machine.config for the sessionState section handler as well as the lt sessionState gt settings. The section handler is highlighted lt xml version 1.0 encoding UTF-8 gt lt configuration gt lt...
The Code for the ContinueUpdateOnError Example
Most of the code we use in this example is identical to the previous example. The only real differences are in the preparation for the Update process, and in the way that we extract and display the row values afterwards. We don't set up any event handlers of course, because we're not going to be reacting to the RowUpdated event in this case. However, at the point where we're ready to call the Update method of the DataAdapter, we set the DataAdapter object's ContinueUpdateOnError property to...
PerRequest Application Events
Per-request application events are those events raised during each and every request made to an ASP.NET application, such as the beginning or end of the request events Application_OnBeginRequest - The Application_OnBeginRequest event is raised on each request that ASP.NET handles, for example, a page or web service. This is unlike the familiar ASP Application_OnStart event, which is only raised once when the application is started. We can use the Application_OnBeginRequest event to execute code...
Writing a TextBox Control
To understand some of the more advanced development aspects of server control, it is useful to actually write a simple control like a textbox. Although this isn't the most exciting control in the world to write, especially since it already exists, it clearly demonstrates some important aspects that control authors need to understand including Raising events from a control. To render a textbox our server control needs to output an HTML input element with a type attribute containing the value...
The NET Language Compilers
When working within the Visual Studio .NET environment, we don't need to worry about the compiler, because the editor takes care of all that for us. Likewise, when simply developing ASP.NET pages, we can rely on the framework to compile pages as required. However, when building components or controls, we'd want to compile code into a DLL, so we need to know how the compiler works. There is a separate compiler for each language, but luckily you use them all in the same way, and most of the...






