ASP/ ASP.NET

My Notes – ASP.NET

?

Every Web page in .NET

extends System.Web.UI.Page class

==

IL is short for Intermediate Language

Another term for IL is Managed Code. This intermediate or managed code is generated by the JIT compiler. JIT is short for Just in Time compiler.

The C#, VB.NET, Cobol.NET, and all other compilers that support the .NET Framework generate IL when compiling a set of code. To get an idea of what IL looks like, start up ILDASM by opening a Visual Studio .NET Command Prompt (Start -> All Programs -> Microsoft Visual Studio .NET -> Visual Studio .NET Tools -> Visual Studio .NET Command Prompt) and type ILDASM. The ILDASM tool is an IL Disassembler for the .NET framework which is installed as part of the .NET SDK. To view the IL for any .NET component on your system go to File -> Open and select a .NET assembly.

How to write ILAsm

http://www.codeproject.com/dotnet/ilassembly.asp

==

The GAC (aka Global Assembly Cache) is the central repository for assemblies installed on a Windows machine. It provides a uniform, versioned and safe access of assemblies by their strong assembly name. C:\WINDOWS\assembly

DataReader

You can use the ADO.NET DataReader to retrieve a read-only, forward-only stream of data from a database. Results are returned as the query executes, and are stored in the network buffer on the client until you request them using the Read method of the DataReader. Using the DataReader can increase application performance both by retrieving data as soon as it is available, rather than waiting for the entire results of the query to be returned, and (by default) storing only one row at a time in memory, reducing system overhead.

Note that while a DataReader is open, the Connection is in use exclusively by that DataReader. You will not be able to execute any commands for the Connection, including creating another DataReader, until the original DataReader is closed.

Output parameters or return values are only available through the DataReader once the connection is closed.

==DataAdapter

Adapters are used to exchange data between a data source and a dataset.

  • To retrieve rows into a dataset, use the Fill method on a data adapter object. When you invoke the Fill method, it transmits an SQL SELECT statement to the data store.

? To transmit a dataset table of the dataset to the data store, use the adapter’s Update method. When you invoke the method, it executes whatever SQL INSERT, UPDATE or DELETE statements are needed, depending on whether the affected record is new, changed, or deleted.

==

DataView

A data view is an object that acts as a layer on top of the data table, providing a filtered and sorted view of the table’s contents. A data view is similar to a view in a database, in that it is not a copy of the data. Instead, it is simply a different way of seeing the data in a table.

==

DataGrid

The DataGrid Web server control displays data in a tabular layout. By default, the DataGrid displays data in read-only mode, but the DataGrid is also capable of automatically displaying the data in editable controls at run-time. The DataGrid control can also create the Select, Edit, Update, and Cancel buttons and programming structure. Additionally, the DataGrid supports paging, though you may also use the custom navigation features of the control to improve performance by controlling the amount of data sent to the client browser.

DataSet

Datasets store data in a disconnected cache. The structure of a dataset is similar to that of a relational database; it exposes a hierarchical object model of tables, rows, and columns. In addition, it contains constraints and relationships defined for the dataset.

You can populate a dataset in a variety of ways:

  • Call the Fill method of a data adaptery.

  • Manually populate tables in the dataset by creating DataRow objects and adding them to the table’s Rows collection. (You can only do this at run time; you cannot set the Rows collection at design time.)

  • Read an XML document or stream into the dataset. For more information, see the ReadXml method.

  • Merge (copy) the contents of another dataset. This scenario can be useful if your application gets datasets from different sources (different XML Web services, for example), but needs to consolidate them into a single dataset. For more information, see the DataSet.Merge method.

==

ViewState

Before ASP.NET, restoring the values back into the form fields across multiple postbacks was entirely the responsibility of the page developer, who had to pick them out, one-by-one, from the HTTP form, and push them back into the fields. Happily, ASP.NET does this trick automatically, thus eliminating both a lot of grunt work and a lot of code for forms. But that’s not ViewState.

ViewState is the mechanism ASP.NET uses to keep track of server control state values that don’t otherwise post back as part of the HTTP form. For example, the text shown by a Label control is saved in ViewState by default. As a developer, you can bind data or programmatically set the Label just once when the page first loads, and on subsequent postbacks, the label text will be repopulated automatically from ViewState. So in addition to less grunt work and less code, the benefit of ViewState is often fewer trips to the database.

It’s a hidden form field managed by the ASP.NET page framework. When ASP.NET executes a page, the ViewState values from the page and all of the controls are collected and formatted into a single encoded string, and then assigned to the value attribute of the hidden form field (specifically, <input type=hidden>).

– You must have a server-side form tag (<form runat=server>) in your ASPX page if you want to use ViewState.

– In cases where the page does not post back, you can eliminate ViewState from a page by omitting the server side <form> tag.

Not very good for:

Large amounts of data.Secure data that is not already displayed in the UI

Objects not readily serialized into ViewState, for example, DataSet.

Disabling ViewState

Per control (on tag)

<asp:datagrid EnableViewState="false" ? />

Per page (in directive)

<%@ Page EnableViewState="False" ? %>

Per application (in web.config)

<Pages EnableViewState="false" ? />

Trace.Write()

==

Rich output caching. ASP.NET output caching can dramatically improve the performance and scalability of your application. When output caching is enabled on a page, ASP.NET executes the page just once, and saves the result in memory in addition to sending it to the user. When another user requests the same page, ASP.NET serves the cached result from memory without re-executing the page. Output caching is configurable, and can be used to cache individual regions or an entire page.

==

Web-Farm Session State.

ASP.NET session state lets you share session data user-specific state values across all machines in your Web farm. Now a user can hit different servers in the web farm over multiple requests and still have full access to her session. And since business components created with the .NET Framework are free-threaded, you no longer need to worry about thread affinity.

===

Managed code is compiled for the .NET run-time environment. It runs in the Common Language Runtime (CLR), which is the heart of the .NET Framework. The CLR provides services such as security, memory management, and cross-language integration. (3) Managed applications written to take advantage of the features of the CLR perform more efficiently and safely, and take better advantage of developers? existing expertise in languages that support the .NET Framework.

There can be no memory leaks in 100% managed code.

Another significant advantage of using managed code is that the CLR provides automatic lifetime management of components and modules. Lifetime control includes:

  • Garbage collection, which frees and compacts memory.

  • Scalability features, such as thread pooling and the ability to use a non-persistent connection with a dataset.

  • Support for side-by-side versions.

Managed code does not have direct access to memory, machine registers, or pointers.

CLR

Common Language Runtime 


Figure 1: .NET Architecture
 

The CLR as a development platform

The CLR is a development platform. Like any platform, it provides a runtime, defines functionality in some libraries, and supports a set of programming languages.

 

 The job of the CLR is to watch over your code, taking care of its needs and wants. In fact, code that takes advantage of the CLR is said to be “managed code”, because the runtime is taking care of it, making sure that it has everything it needs and ensuring that it doesn’t do anything it’s not supposed to. “Unmanaged code” is the code that either doesn’t know about or doesn’t want to use the runtime.

===

if a method input parameter is declared as accepting a 4-byte value, the common language runtime will detect and trap attempts to access the parameter as an 8-byte value. Type safety also means that execution flow will only transfer to known method entry points. There is no way to construct an arbitrary reference to a memory location and cause code at that location to begin execution

Unmanaged code includes all code written before the .NET Framework was introduced?this includes code written to use COM, native Win32, and Visual Basic 6. Because it does not run inside the .NET environment, unmanaged code cannot make use of any .NET managed facilities.

==

All .NET compilers produce metadata about the types defined in the modules they produce. This metadata is packaged along with the module (modules in turn are packaged together in assemblies), and can be accessed by a mechanism called reflection. The System.Reflection namespace contains classes that can be used to interrogate the types for a module/assembly.

Using reflection to access .NET metadata is very similar to using ITypeLib/ITypeInfo to access type library data in COM, and it is used for similar purposes – e.g. determining data type sizes for marshaling data across context/process/machine boundaries.

Reflection can also be used to dynamically invoke methods (see System.Type.InvokeMember), or even create types dynamically at run-time (see System.Reflection.Emit.TypeBuilder).

==

Code Access Security

CAS is the part of the .NET security model that determines whether or not code is allowed to run, and what resources it can use when it is running. For example, it is CAS that will prevent a .NET web applet from formatting your hard disk.

C# supports constructor chaining

class Person
    {
        public Person( string name, int age ) { ... }
        public Person( string name ) : this( name, 0 ) {}
        public Person() : this( "", 0 ) {}
    }

===

User Control vs Custom Control [Composite Control]

The main difference between user controls and composite controls is that user controls are persisted as .ascx text files, whereas composite controls are compiled and persisted in assemblies.

A user control (ex. TextBox, ComboBox, ListBox, simple HTML elements) could simply be an extension of the functionality of an existing server control(s) (such as an image control that can be rotated or a calendar control that stores the date in a text box, DataGrid, DataSet, DataView, DataAdapter). Or, it could consist of several elements that work and interact together to get a job done (such as several controls grouped together that gather information about a user’s previous work experience).

An ASP.NET control (sometimes called a server control) is a server-side component that is shipped with .NET Framework. A server control is a compiled DLL file and cannot be edited. It can, however, be manipulated through its public properties at design-time or runtime. It is possible to build a custom server control (sometimes called a custom control or composite control).

==

all .NET event handlers are expected to accept two parameters.The first parameter (Sender) is a reference to the object that raised the event. You might think this is redundant because we’ve already decided that this handler will be associated with events from the Navigate button;however, as we shall see in Chapter 4, you can define event handling routines to be associated with multiple controls, and so the Sender parameter provides an easy way to identify which of these controls has raised the event.The second parameter (E) is a reference to an object that provides additional information about the event. In the case of a click event there’s no useful additional information, but for events such as ItemClick (ina ListBox) or ItemCommand (in a DataGrid) the E parameter includes details of which item or row has been selected or activated.

Typed versus Untyped Datasets

Datasets can be typed or untyped. A typed dataset is a dataset that is first derived from the base DataSet class and then uses information in an XML Schema file (an .xsd file) to generate a new class. Information from the schema (tables, columns, and so on) is generated and compiled into this new dataset class as a set of first-class objects and properties.

Note For more information about dataset schemas, see XML Schemas and Data.

Because a typed DataSet class inherits from the base DataSet class, the typed class assumes all of the functionality of the DataSet class and can be used with methods that take an instance of a DataSet class as a parameter

An untyped dataset, in contrast, has no corresponding built-in schema. As in a typed dataset, an untyped dataset contains tables, columns, and so on ? but those are exposed only as collections. (However, after manually creating the tables and other data elements in an untyped dataset, you can export the dataset’s structure as a schema using the dataset’s WriteXmlSchema method.)

You can use either type of dataset in your applications. However, Visual Studio has more tool support for typed datasets, and they make programming with the dataset easier and less error-prone.

=========

SERVER controls vs CLIENT controls.. ASP.NET

http://www.informit.com/articles/article.asp?p=173412&rl=1

=========

CMS

Software that provides a method of managing your website is commonly called a CMS or “Content Management System”. Many blogging software programs are considered a specific type of CMS.

=========

Delegates

 Microsoft gives this rather cryptic description:
A delegate is a reference type that refers to a Shared method of a type or to an instance method of an object. The closest equivalent of a delegate in other languages is a function pointer, but whereas a function pointer can only reference Shared functions, a delegate can reference both Shared and instance methods.

It means that a delegate is basically just a fancy function pointer like in C++. (you can also think of it like a callback) And a function pointer is just a reference to a function, it lets some other code, call your function without needing to know where your function is actually located.

A delegate is very much like a C/C++ ‘function pointer‘ or a ‘typedef that represents the address of a function’. In C/C++, the address of a function is just a memory address. The C/C++ function pointer holds only the address of a function. This address doesn’t carry any additional information, such as the number of parameters expected by the function, types of parameters it takes etc. In fact, this all makes a function pointer type unsafe. Traditionally, calling a function by its address depends on the language supporting the function pointers. And function pointers are inherently dangerous.Delegates add a safety to the idea of traditional function pointers. The .NET framework has added the bonus of providing a type-safe mechanism called delegates. They follow a Trust-But-Verify model, with automatic verification of the signature by the compiler. Unlike function pointers however, delegates are object-oriented, type-safe, and secured. In short, a delegate is a data structure that refers to a static method or to an object instance, and an instance method of that object. When the delegate references an instance method, it stores not only a reference to the method entry point, but also a reference to the object instance for which to invoke the method. Delegates are more efficient than interfaces as the method pointer is calculated (if virtual) when the delegate is first assigned, rather than each time it is invoked.

Leave a Reply

உங்கள் மின்னஞ்சல் வெளியிடப்பட மாட்டாது தேவையான புலங்கள் * குறிக்கப்பட்டன


To prove you're a person (not a spam script), type the security word shown in the picture.
You can enter the Tamil word or English word but not both
Anti-Spam Image

© 2024 - All Right Reserved. | Adadaa logo