Programmatically Speaking ...

This site

Fav Blogs

Sponsors

  • MaximumASP
  • Packet Sniffer
    Home Loan
  • optimum rewards

March 2008 - Posts

The Microsoft AJAX Library - some basics

The Microsoft AJAX library consists of three javascript files:

MicrosoftAjax.js: the core file that deals with communication, DOM, JavaScript extension, etc.

MicrosoftAjaxTimer.js: client side javascript responding to Timer server control

MicrosoftAjaxWebForms.js: deals with the UpdatePanel of Web forms

The Microsoft AJAX library has the following namespaces that cover different classes for different purposes

Sys: base class

Sys.Net: networking class

Sys.UI: client side controls and DOM

Sys.Services: Classes for accessing ASP.NET services like profile, membership, and authentication:

Sys.Serialization: JSON serialization/deserialization

Sys.WebForms: for web form partial rendering

The Microsoft AJAX library emulates an server-side web application in a number of ways:

an application model which has a life-cycle similar to that of a Web form,

a component model that can add and remove event delegates the same way as web server controls,

authentication services to take advantage of server-side membership and profile.

The Microsoft AJAX library has a dedicated communication layer between client and server, the essence of AJAX. It supports server-side web form's partial rendering using updatepanel.

On the pure client side, it provides a API to iron out the incompatible wrinkles among differnt browsers.

The newest Visual Studio 2008 / Visual Web Developer 2008 Express provdies Javascipt debugging and intellisense support.

A simple AJAX-enabled webpage using The Microsoft AJAX library: Client Page Life Cycle

<asp:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager>

<script type="text/javascript">

<!--

function pageLoad() { alert("Client Page Event: Page load!");

}

function pageUnload() { alert("Client Page Event: Page unload!");

}

//-->

</script>

The above is just my learning from the book: AJAX in action.

 

Common ASP .NET performance myths

 

In an MSDN article, Rob Howard writes about some of the most common performance myths with regards to ASP .net:

1. C# code runs faster than VB .NET.

Not true.

Rob Howard: similar code produces similar results.

Me: however, there is generally a higher respect paid to C#.
 

2. Code behind faster than inline script.

Absolutely false

Rob Howard:  Sometimes I prefer to use inline code as changes don't incur the same update costs as codebehind. For example, with codebehind you have to update the entire codebehind DLL, which can be a scary proposition.

Me: Codebehind has better intellisense support and does make the code cleaner.
 

3. Components are faster than pages

False.

Rob Howard: Organizationally, it is better to group functionality logically this way, but again it makes no difference with regard to performance.

Me: Ditto.

4. Every functionality that you want to occur between two apps should be implemented as a Web service.

???

Rob Howard: Web services should be used to connect disparate systems or to provide remote access to system functionality or behaviors. They should not be used internally to connect two similar systems. While easy to use, there are much better alternatives. The worst thing you can do is use Web services for communicating between ASP and ASP.NET applications running on the same server, which I've witnessed all too frequently.

My take: There are also better and lighter alternatives that Web services. Also, there are web services that  provide XML data over HTTP, in a lightweight approach sometimes referred to as REST (Representational State Transfer), and there are also heavy set web services using the SOAP (Simple Object Access Protocol) web services stack. The former has achieved a greater success and popularity, for example, Google, Yahoo, Amazon ...

Some useful little tips in .NET coding
The following are some useful little tips for myself.

The @ symbol in C#
Instead of writting double \\s in a file or folder path,
prefacing the string with "@", as following:

string s = @"c:\webs\aspnet\csharp";

Prefacing a string with "@" also enables you write a
string as the following without fussing around with
stringing lines together.

string s = @"Line 1
Line2

Line4";


Double Quote Symbol in a String

For double quote character " to work in a string literal,
the way to go is to use two consecutive double-quotes, as such:

s = @"She said: ""Hello""");

The above will be output as: She said "Hello".


~ In ASP .NET Controls;

This character references the application's root.
Many ASP.NET server controls allow for this type of syntax.

Example syntax:

Returns the correct path based on the application's root.
For example, if the application was rooted at the virtual
directory Foo, the return value would be
<code>/Foo/Images/Skyline.jpg...</code>



Server-Side Comment Syntax: <%-- Comment --%>
Server-side comments enable page developers to prevent server code (including server controls) and static content from executing or rendering. The following sample demonstrates how to block content from executing and being sent down to a client. Note that everything between <%-- and --%> is filtered out and only visible in the original server file, even though it contains other ASP.NET directives.


<%--
<asp:calendar id="MyCal" runat=server/>
<% for (int i=0; i<45; i++) { %>
Hello World <br>
<% } %>
--%>


<%--
<asp:calendar id="MyCal" runat=server/>
<% For I=0 To 44 %>
Hello World <br>
<% Next %>
--%>


<%--
<asp:calendar id="MyCal" runat=server/>
<% for (var i:int=0; i<45; i++) { %>
Hello World <br>
<% } %>
--%>

 

The leading UI suite for ASP.NET - Telerik radControls
Outstanding performance. Full ASP.NET AJAX support. Nearly codeless development.