Sunday, July 31, 2016

ASP.Net

ASP.Net




ASP.Net Events

Events in ASP.NET raised at the client machine, and handled at the server machine.

Syntax  private void EventName (object sender, EventArgs e);

Application and Session Events


  • Application_Start
  • Application_End
  • Session_Start
  • Session_End  

Page and Control Events 

Common page and control events are: 

  • DataBinding - It is raised when a control binds to a data source. 
  • Disposed - It is raised when the page or the control is released. 
  • Error - It is a page event, occurs when an un-handled exception is thrown. 
  • Init - It is raised when the page or the control is initialized.
  • Load - It is raised when the page or a control is loaded. 
  • PreRender - It is raised when the page or the control is to be rendered. 
  • Unload - It is raised when the page or control is unloaded from memory.
Event Handling Using Controls

 All ASP.NET controls are implemented as classes, and they have events which are fired when a user performs a certain action on them. For example, when a user clicks a button the 'Click' event is generated. For handling events, there are in-built attributes and event handlers. Event handler is coded to respond to an event, and take appropriate action on it.

<asp:Button ID="btnCancel" runat="server" Text="Cancel" />

The event handler for the Click event:

Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click 
End Sub

An event can also be coded without Handles clause.
<asp:Button ID="btnCancel" runat="server" Text="Cancel" Onclick="btnCancel_Click" />

The event handler for the Click event:
Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) End Sub

Postback vs Non-Postback events








ASP.Net Server Side

Page itself gets instantiated as control object. All web forms are instances of ASP.Net page class.

Server Object
Are instances of the System.Web.HttpServerUtility. 

PropertyDescription
MachineNameName of server computer
ScriptTimeOutGets and sets the request time-out value in seconds.
The following table provides a list of some important methods:
MethodDescription
CreateObject(String)Creates an instance of the COM object identified by its ProgID (Programmatic ID).
CreateObject(Type)Creates an instance of the COM object identified by its Type.
Equals(Object)Determines whether the specified Object is equal to the current Object.
Execute(String)Executes the handler for the specified virtual path in the context of the current request.
Execute(String, Boolean)Executes the handler for the specified virtual path in the context of the current request and specifies whether to clear the QueryString and Form collections.
GetLastErrorReturns the previous exception.
GetTypeGets the Type of the current instance.
HtmlEncodeChanges an ordinary string into a string with legal HTML characters.
HtmlDecodeConverts an Html string into an ordinary string.
ToStringReturns a String that represents the current Object.
Transfer(String)For the current request, terminates execution of the current page and starts execution of a new page by using the specified URL path of the page.
UrlDecodeConverts an URL string into an ordinary string.
UrlEncodeTokenWorks same as UrlEncode, but on a byte array that contains Base64-encoded data.
UrlDecodeTokenWorks same as UrlDecode, but on a byte array that contains Base64-encoded data.
MapPathReturn the physical path that corresponds to a specified virtual file path on the server.
TransferTransfers execution to another web page in the current application.
Request Object

Is an instance of System.Web.HttpRequest.
It represents the values and properties of HTTP Request that makes page loading into browser.

PropertyDescription
AcceptTypesGets a string array of client-supported MIME accept types.
ApplicationPathGets the ASP.NET application's virtual application root path on the server.
BrowserGets or sets information about the requesting client's browser capabilities.
ContentEncodingGets or sets the character set of the entity-body.
ContentLengthSpecifies the length, in bytes, of content sent by the client.
ContentTypeGets or sets the MIME content type of the incoming request.
CookiesGets a collection of cookies sent by the client.
FilePathGets the virtual path of the current request.
FilesGets the collection of files uploaded by the client, in multipart MIME format.
FormGets a collection of form variables.
HeadersGets a collection of HTTP headers.
HttpMethodGets the HTTP data transfer method (such as GET, POST, or HEAD) used by the client.
InputStreamGets the contents of the incoming HTTP entity body.
IsSecureConnectionGets a value indicating whether the HTTP connection uses secure sockets (that is, HTTPS).
QueryStringGets the collection of HTTP query string variables.
RawUrlGets the raw URL of the current request.
RequestTypeGets or sets the HTTP data transfer method (GET or POST) used by the client.
ServerVariablesGets a collection of Web server variables.
TotalBytesGets the number of bytes in the current input stream.
UrlGets information about the URL of the current request.
UrlReferrerGets information about the URL of the client's previous request that is linked to the current URL.
UserAgentGets the raw user agent string of the client browser.
UserHostAddressGets the IP host address of the remote client.
UserHostNameGets the DNS name of the remote client.
UserLanguagesGets a sorted string array of client language preferences.
The following table provides a list of some important methods:

MethodDescription
BinaryReadPerforms a binary read of a specified number of bytes from the current input stream.
Equals(Object)Determines whether the specified object is equal to the current object. (Inherited from object.)
GetTypeGets the Type of the current instance.
MapImageCoordinatesMaps an incoming image-field form parameter to appropriate x-coordinate and y-coordinate values.
MapPath(String)Maps the specified virtual path to a physical path.
SaveAsSaves an HTTP request to disk.
ToStringReturns a String that represents the current object.
ValidateInputCauses validation to occur for the collections accessed through the Cookies, Form, and QueryString properties.
Response Object

Represents server's response. It is an istance of System.Web.HttpResponse.

PropertyDescription
BufferGets or sets a value indicating whether to buffer the output and send it after the complete response is finished processing.
BufferOutputGets or sets a value indicating whether to buffer the output and send it after the complete page is finished processing.
CharsetGets or sets the HTTP character set of the output stream.
ContentEncodingGets or sets the HTTP character set of the output stream.
ContentTypeGets or sets the HTTP MIME type of the output stream.
CookiesGets the response cookie collection.
ExpiresGets or sets the number of minutes before a page cached on a browser expires.
ExpiresAbsoluteGets or sets the absolute date and time at which to remove cached information from the cache.
HeaderEncodingGets or sets an encoding object that represents the encoding for the current header output stream.
HeadersGets the collection of response headers.
IsClientConnectedGets a value indicating whether the client is still connected to the server.
OutputEnables output of text to the outgoing HTTP response stream.
OutputStreamEnables binary output to the outgoing HTTP content body.
RedirectLocationGets or sets the value of the Http Location header.
StatusSets the status line that is returned to the client.
StatusCodeGets or sets the HTTP status code of the output returned to the client.
StatusDescriptionGets or sets the HTTP status string of the output returned to the client.
SubStatusCodeGets or sets a value qualifying the status code of the response.
SuppressContentGets or sets a value indicating whether to send HTTP content to the client.
The following table provides a list of some important methods:
MethodDescription
AddHeaderAdds an HTTP header to the output stream. AddHeader is provided for compatibility with earlier versions of ASP.
AppendCookieInfrastructure adds an HTTP cookie to the intrinsic cookie collection.
AppendHeaderAdds an HTTP header to the output stream.
AppendToLogAdds custom log information to the InterNET Information Services (IIS) log file.
BinaryWriteWrites a string of binary characters to the HTTP output stream.
ClearContentClears all content output from the buffer stream.
CloseCloses the socket connection to a client.
EndSends all currently buffered output to the client, stops execution of the page, and raises the EndRequest event.
Equals(Object)Determines whether the specified object is equal to the current object.
FlushSends all currently buffered output to the client.
GetTypeGets the Type of the current instance.
PicsAppends a HTTP PICS-Label header to the output stream.
Redirect(String)Redirects a request to a new URL and specifies the new URL.
Redirect(String, Boolean)Redirects a client to a new URL. Specifies the new URL and whether execution of the current page should terminate.
SetCookieUpdates an existing cookie in the cookie collection.
ToStringReturns a String that represents the current Object.
TransmitFile(String)Writes the specified file directly to an HTTP response output stream, without buffering it in memory.
Write(Char)Writes a character to an HTTP response output stream.
Write(Object)Writes an object to an HTTP response stream.
Write(String)Writes a string to an HTTP response output stream.
WriteFile(String)Writes the contents of the specified file directly to an HTTP response output stream as a file block.
WriteFile(String, Boolean)Writes the contents of the specified file directly to an HTTP response output stream as a memory block.

HTML Server Control

HTML server controls are basic html controls enhanced to enable server side processing. They are not processed by servers instead they are sent to browser for display.

They are specifically converted to server control by adding runat="server" tag and an ID attribute.

Client Side

1. Client side scripting - Code that runs on browser and are not sent to server for processing.

2. Client side code - This is code behind of aspx. Contains number of hidden field to handle view state etc.

Basic Controls


.

No comments:

Post a Comment