Saturday 22 November 2014

ASP.NET - Client Side

ASP.Net client side coding has two aspects:

  • Client side scripts: that would run on the browser and in turn would speed up the execution of page. For example, client side data validation which can catch invalid data and warn the user accordingly without making a round trip to the server.
  • Client side source code: that the ASP.NET pages generate. For example, the HTML source code of an ASP.NET page contains a number of hidden fields and automatically injected blocks of JavaScript code, which keeps information like view state or does other jobs to make the page work.

Client Side Scripts:

All ASP.Net server controls allow calling client side code written using JavaScript or VBScript. Some ASP.Net server controls use client side scripting to provide responses to the users without posting back to the server, for example, the validation controls, which we will discuss in due time.
Apart from these scripts the Button control has a property OnClientClick, which allows executing client-side script, when the button is clicked.
The traditional and server HTML controls has the following events that can execute a script when they are raised:
EventDescription
onblurWhen the control loses focus
onfocusWhen the control receives focus
onclickWhen the control is clicked
onchangeWhen the value of the control changes
onkeydownWhen the user presses a key
onkeypressWhen the user presses an alphanumeric key
onkeyupWhen the user releases a key
onmouseoverWhen the user moves the mouse pointer over the control
onserverclickIt raises the ServerClick event of the control, when the control is clicked

Client Side Source Code

We have already discussed that, ASP.NET pages are generally written in two files:
  • The content file or the markup file .aspx
  • The code-behind file
The content file contains the HTML or ASP.Net controls tags and literals to form the structure of the page and the code behind file contains the class definition. At run time, the content file is parsed and transformed into a page class.
This class along with the class definition in the code file and some other system generated code make the executable code assembly that processes all posted data and generates the response and sends it back to the client.
Consider the simple page:
<%@ Page Language="C#" AutoEventWireup="true" 
                       CodeBehind="Default.aspx.cs" 
                       Inherits="clientside._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  
      <asp:Button ID="Button1" runat="server" 
        OnClick="Button1_Click" Text="Click" />
    </div>
    <hr />
    <h3><asp:Label ID="Msg" runat="server" Text=""></asp:Label>
    </h3>
    </form>
</body>
</html>
When this page is run on the browser, the View Source option shows the HTML page sent to the browser by the ASP.Net runtime:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
 Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" 
value="/wEPDwUKMTU5MTA2ODYwOWRk31NudGDgvhhA7joJum9Qn5RxU2M=" />
</div>
 
<div>
<input type="hidden" name="__EVENTVALIDATION" 
id="__EVENTVALIDATION" 
value="/wEWAwKpjZj0DALs0bLrBgKM54rGBhHsyM61rraxE+KnBTCS8cd1QDJ/"/>
</div>

<div>
<input name="TextBox1" type="text" id="TextBox1" />  
<input type="submit" name="Button1" value="Click" id="Button1" />
</div>

<hr />
<h3><span id="Msg"></span></h3>
</form>
</body>
</html>
Looking closely at the code would reveal that first two <div> tags contain the hidden fields which store the view state and validation information.

ASP.NET - Server Side

ASP.NET - Server Side



We have studied the page life cycle and how a page contains various controls. The page itself is instantiated as a control object. All web forms are basically instances of the ASP.Net Page class. The page class has the following extremely useful properties that correspond to intrinsic objects like:
  • Session.
  • Application
  • Cache
  • Request
  • Response
  • Server
  • User
  • Trace
We will discuss each of these objects in due time. In this tutorial we will explore the Server object, the Request object and the Response object.

The Server Object:

The Server object in Asp.Net is an instance of the System.Web.HttpServerUtility class. The HttpServerUtility class provides numerous properties and methods to perform various jobs.

Properties and Methods of the Server object:

The methods and properties of the HttpServerUtility class are exposed through the intrinsic Server object provided by ASP.NET.
The following table provides a list of the properties:
PropertyDescription
MachineNameName of server's computer
ScriptTimeOutGets and sets the request time-out value in seconds.
The following table provides a list of some important methods:
MethodDescription
CreateObjectStringCreates an instance of the COM object identified by its ProgID ProgrammaticID
CreateObjectTypeCreates an instance of the COM object identified by its Type
EqualsObjectDetermines whether the specified Object is equal to the current Object
ExecuteStringExecutes the handler for the specified virtual path in the context of the current request.
ExecuteString,BooleanExecutes 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
TransferStringFor 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

The Request Object:

The request object is an instance of the System.Web.HttpRequest class. It represents the values and properties of the HTTP request that makes the page loading into the browser.
The information presented by this object is wrapped up by the higher level abstractions thewebcontrolmodel, however, this object helps in checking some information like the client browser and cookies.

Properties and Methods of the Request Object:

The following table provides some noteworthy properties of the Request object:
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 suchasGET,POST,orHEAD used by the client.
InputStreamGets the contents of the incoming HTTP entity body.
IsSecureConnectionGets a value indicating whether the HTTP connection uses secure sockets thatis,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 GETorPOSTused 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 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.
EqualsObjectDetermines whether the specified Object is equal to the current Object. InheritedfromObject.
GetTypeGets the Type of the current instance.
MapImageCoordinatesMaps an incoming image-field form parameter to appropriate x-coordinate and y-coordinate values.
MapPathStringMaps 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.

The Response Object:

The Response object represents the server's response to the client request. It is an instance of the System.Web.HttpResponse class.
In ASP.Net, the Response object does not play a vital role in sending HTML text to the client, because the server-side controls have nested, object oriented methods for rendering themselves.
However, the HttpResponse object still provides some important functionalities, like the cookie feature and the Redirect method. The Response.Redirect method allows transferring the user to another page, inside as well as outside the application. It requires a round trip.

Properties and Methods of the Response Object:

The following table provides some noteworthy properties of the Response object:
PropertyDescription
BufferGets or sets a value indicating whether to buffer output and send it after the complete response is finished processing.
BufferOutputGets or sets a value indicating whether to buffer 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.
EqualsObjectDetermines 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.
RedirectStringRedirects a request to a new URL and specifies the new URL.
RedirectString,BooleanRedirects 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.
TransmitFileStringWrites the specified file directly to an HTTP response output stream, without buffering it in memory.
WriteCharWrites a character to an HTTP response output stream.
WriteObjectWrites an Object to an HTTP response stream.
WriteStringWrites a string to an HTTP response output stream.
WriteFileStringWrites the contents of the specified file directly to an HTTP response output stream as a file block.
WriteFileString,BooleanWrites the contents of the specified file directly to an HTTP response output stream as a memory block.

Example:

The following simple example has a text box control where the user can enter name, a button to send the information to the server and a label control to display the URL of the client computer.
The content file:
<%@ Page Language="C#" AutoEventWireup="true" 
                       CodeBehind="Default.aspx.cs" 
                       Inherits="server_side._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Enter your name:<br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" 
                    OnClick="Button1_Click" Text="Submit" />
        <br />
        <asp:Label ID="Label1" runat="server"/>

    </div>
    </form>
</body>
</html>
The code behind for Button1_Click:
protected void Button1_Click(object sender, EventArgs e)
{
   if (!String.IsNullOrEmpty(TextBox1.Text))
   {
       // Access the HttpServerUtility methods through
       // the intrinsic Server object.
       Label1.Text = "Welcome, " +
       Server.HtmlEncode(TextBox1.Text) +
       ".<br/> The url is " +
       Server.UrlEncode(Request.Url.ToString());
    }

 }
Run the page to see the following result
ASP.NET Server Side

SAP HANA DB ANALYSIS AFTER ISSUES

To be able to further analyze your issue and environment please download the attached shell script you can get from KBA: 3218277 - Collectin...