Friday, April 23, 2010

Youtube Educational Hub

You can watch video lectures from the most prestigious universities including MIT, Stanford University, UC Berkeley, UCLA, Dartmouth, Yale, Harvard Business, IIT/IISc, Vanderbilt University and about 100 leading universities at Youtube educational hub. YouTube EDU (youtube.com/edu) is a hub for videos(lectures, student films, athletic events etc) from over 100 of leading university and college partners.

YouTube EDU - Educational Hub,video lectures

According to YouTube EDU, there are over 20,000 videos on this hub and growing. It is a volunteer project sparked by a group of employees who wanted to find a better way to collect and highlight all the great educational content being uploaded to YouTube by colleges and universities.

YouTube EDU - Educational Hub,video lectures

This is excellent initiative by youtube, you get to see good lectures of the prestigious universities, which is not possible otherwise for most. Here are some :

For more videos visit YouTube EDU, or EDU Directory for list of all available educational hub.

Wednesday, April 21, 2010

Session Cookies

Websites typically use session cookies to ensure that users are recognized when they move from page to page within one site and that any information you have entered is remembered. For example, if an e-commerce site which uses session cookies then items placed in a shopping cart would appear by the time you reach the checkout. We will introduce you how to work with the cookies in ASP.NET 2.0 and C# in this tutorial.

The browser is responsible for managing cookies on a user system. Cookies are sent to the browser via the HttpResponse object that exposes a collection called Cookies. You can access the HttpResponse object as the Response property of your Page class. Any cookies that you want to send to the browser must be added to this collection. When creating a cookie, you specify a Name and Value.

When a browser makes a request to the server, it sends the cookies for that server along with the request. In this ASP.NET applications, we can read the cookies using the HttpRequest object, which is available as the Request property of Page class.

We added one text box, two buttons and 1 label to the web page. The text box is used for inputting the information of cookie. By clicking Add button, the sample application will create a new cookie. By clicking View button, you will see the cookie created. The expiration date of cookie will be set to 2006-10-1.

The flow for the code behind page is as follows:







Introduction to .Net Framework

You can make use .Net Framework as a development environment or a platform for developing user friendly web-based applications that can allow seamless access by users from any where in the world and from any type of client machines. You can apply the open standards such as XML (eXtensible Markup Language), SOAP (Simple Object Access Protocol) and HTTP (HyperText Transfer Protocol) for developing your web-applications and web applications created with such open standards can interact well with other applications of other platforms.

You can use different programming languages such as C#, VBScript, VB.NET, Managed C++ for developing your applications in .NET Framework, as the .NET Framework is not dependent on one particular language or platform and can support many kinds of platforms and programming languages that are in use today. Further, you can use .NET Framework for running your applications in almost all platforms such as Linux, Macintosh and Unix without any hitches.

The presence of many off-the-shelf libraries in .NET Framework can assist you in developing your applications in a faster, cheaper and easier manner. The most recent .Net Framework version is capable of supporting over 20 different programming languages today.

The functionality of .Net Framework supporting many programming languages is due to the use of the powerful CLR, the Common Language Runtime engine. The application programming codes are first compiled by CLR into a Microsoft Intermediate Language (MSIL) code instead of native codes and the MSIL, which is nothing but an instruction set, in turn creates the native code for running the application.

The main advantage of language and platform independent feature of .NET Framework can be attributed to CLR and the same CLR also takes care of run-time services such as memory processes, security enforcement, integration of language, and thread management. Hence, you can make use of the various infrastructures that have been provided in .NET Framework for creating your web-applications.

As per the classification by the Microsoft, there are two categories of .NET Framework and they are CLR and .Net Framework class library.

Common Language Runtime: The CLR is responsible for providing a common runtime environment or services with which all .NET applications can run. Further, the various capabilities of CLR can enable any developer to write even big applications with ease using the features such as strong type naming, life-cycle management, dynamic binding that is capable of making any business logic into re-usable component and finally the cross-language exception handling.

.Net Framework class library: This class library constitutes various predefined functional sets that are very useful while developing the applications by developers. There are three main components in this class library and they are:

· ASP.NET.
· Windows Forms.
· ADO.NET.

With the .Net Framework you can make your codes written in fewer lines and other favourable features such as easy web settings, easy deployment of applications, easy compilation procedures, easy Web configuration makes the .NET Framework a great platform to work with. In an overall scenario, the developers will be able to concentrate more on Web controls and spend an efficient time in application design and implementation and to have an effective control over the flow of the application sequence.

Another great feature that any developer can take note of is the feature of .NET Framework taking into cognisance all the Web controls, server-side blocks of codes and Web forms and getting them compiled whenever a call for the page compilation is completed.

Once the components of .NET framework are compiled in your machine, the compiled version can easily be uploaded with all the relevant pages in the /bin directory of the system. The process of uploading is very easy when compared to the complicated process of web-application in ASP, where in you have to first upload the application pages with the relevant components and you also need to register them with the operating system.

In .NET Framework the simple uploading in /bin directory of the operating system is enough and you need not carry out the complicated process of registering the components of web-application with the operating system.

With the help of an XML based web.config file you can carry out the web settings which is nothing but configuring the .NET applications for successful running. The XML based web.config file can be modified through a program and when any such modification is done, the system recognises the change and registers it immediately that makes configuration of .NET applications easy and quick.


Lioness died at Hyderabad Zoo


Friday, April 16, 2010

Strings with StringBuilder in .NET

Strings are integral to most app dev projects, so it is imperative that they don't impair performance. The .NET StringBuilder class streamlines string values processing. It's hard to find an application that doesn’t deal with text in some way. As a result, developers are faced with a variety of string-related tasks every day. The .NET Framework includes many classes and methods for dealing with strings. One of these classes, StringBuilder, provides an approach to working with strings that is less resource intensive than its standard String class counterpart. Let's look first at why using String can lead to inefficient code. Then, we'll see how to use StringBuilder to save memory and processing time.

Placing strings in memory

When you declare and place a value in a .NET String data type, that value is stored in memory. The amount of memory utilised is determined by the actual text. The following code declares and populates a sample string:

Dim sample As String = "zeebyte.blogspot.com"


The same declaration in C# is:

C#:

string sample = "zeebyte.blogspot.com";

In both statements, a memory location is assigned with a length of 20. In fact, a new string (in memory) is created every time a String value is created. This is an important point, which we'll revisit when we look at the StringBuilder class. Let's examine a few more aspects of the String data type before we move on.

Although creating a static text value is routine, creating new values using multiple string data elements is a common task as well. You can use the plus sign (+) to piece together one or more text elements. The following sample illustrates concatenation in VB.NET first followed by C#.

VB.Net:

Dim sample1 As String = "zeebyte.blogspot.com"
Dim sample2 As String = "Tech Blog"
Dim sample3 As String
sample3 = sample1 + " " + sample2

C#:

string sample1 = "zeebyte.blogspot.com";
string sample2 = "Tech Blog";
string sample3;
sample3 = sample1 + " " + sample2;

Both code snippets result in the string "zeebyte.blogspot.com Tech Blog" and, in the process, four strings are created in memory. The sample1 string is created, followed by sample2 and then sample3. The last line creates another string in memory containing the results of the concatenation.

You may be thinking that this is a pointless concern—and you might be right, considering the miniscule amount of memory used by the sample code. But suppose you're creating a rather lengthy SQL statement using values from various sources. At this point, the amount of memory required (or wasted) and the processing time used for the creation of the numerous objects may become a bottleneck in your application. With this type of scenario in mind, Microsoft included the StringBuilder class in .NET.

StringBuilder class

The StringBuilder class allocates memory for a string according to characters. Additional memory is not always required using this approach. It contains various methods and properties, but we'll start by looking at basic usage. The StringBuilder class is located in the System.Text namespace, so you must reference this namespace to take advantage of it. The following code creates StringBuilder objects with our sample text.

VB.Net:

Imports System.Text
Dim sb As New StringBuilder("zeebyte.blogspot.com")
System.Console.Writeline(sb.ToString())

C#:

Using system.text;
StringBuilder sb = new StringBuilder("zeebyte.blogspot.com");
Console.WriteLine(sb.ToString());

The code results in the output of the "zeebyte.blogspot.com" string to the standard output or command line. It uses the ToString method to retrieve a String object with the text for presentation. The StringBuilder class provides other methods in addition to ToString. For example, the Append method allows multiple values to be concatenated like so:

VB.Net:

Dim sb As New StringBuilder("zeebyte.blogspot.com")
sb.Append(" Tech Blog")

C#:

StringBuilder sb = new StringBuilder("zeebyte.blogspot.com");
sb.Append(" Tech Blog");

You may be wondering if the StringBuilder code is more efficient than the code using String data types. The answer is no—at least not yet. As written here, the StringBuilder sample is not more efficient, because the system must reallocate memory to accommodate the new text appending to the end of the initial text. The initial length of the StringBuilder is set according to the value used to populate it. To make the code more efficient, you can use the Capacity property to allocate enough memory to handle the final value without memory reallocation and slowing down the system. The Capacity property sets the number of characters allocated for the string value. The following code reworks the previous code to set aside enough memory from the start:

VB.Net:

Dim sb As New StringBuilder()
sb.Capacity = 20
sb.Append("zeebyte.blogspot.com")
sb.Append(" Tech Blog")

C#:

StringBuilder sb = new StringBuilder();
sb.Capacity = 20;
sb.Append("zeebyte.blogspot.com");
sb.Append(" Tech Blog");

This code results in the allocation of plenty of memory from the beginning, so no memory reallocation is necessary (unless the capacity is surpassed). In addition to using the Capacity property to allocate memory for a specific number of characters, you can use the MaxCapacity property to establish the maximum size (ceiling) of the object.


One property often confused with Capacity is Length. The Length property returns the current size of the string value, and it may also be set to truncate or expand the size of the string. Setting the length to less than the current value truncates the string to the specified new length. The following code chops the value down to zeebyte.blogspot.com from the initial value:

VB.Net:

Dim sb As New StringBuilder("zeebyte.blogspot.com Tech Blog")
sb.Length = 10
System.Console.Writeln(sb.ToString())

C#:

StringBuilder sb = new StringBuilder("zeebyte.blogspot.com Tech Blog");
sb.length = 10;
Console.WriteLine(sb.ToString());

Establishing the capacity of the StringBuilder object before using it in your code ensures that the system will not have to continuously reallocate memory to accommodate a growing value (size). But even if reallocation is encountered, the StringBuilder approach is still more efficient than using base string objects where new objects must be repeatedly created. For this reason, you should use the StringBuilder object in situations where string values must be created on the fly. If you're creating a rather long string, you can take advantage of the With statement (VB.NET only) to further optimize the code:

VB.Net:

Dim sb As New StringBuilder()
With sb
.Capacity = 150
.Append("zeebyte.blogspot.com")
.Append(" ")
.Append("is")
.Append(" ")
.Append("the ")
.Append("Tech ")
.Append("Blog ")
End With

Manipulating the text


Once text has been placed in the StringBuilder object, you can use additional methods:

  • The Chars method allows you to extract or replace individual characters.
  • The Replace method allows you to replace all occurrences of a string with another string.
  • The Insert method allows you to insert a value at a specified location.

A common task


Working with string values is a common task for all developers. Thankfully, the chore of building string values on the fly has been eased with the introduction of the StringBuilder class. This class provides the methods to easily manipulate text, and it is easy on system resources so program execution does not suffer.

ASP.NET Validation Controls

After you create a web form, you should make sure that mandatory fields of the form elements such as login name and password are not left blank; data inserted is correct and is within the specified range. Validation is the method of scrutinizing that the user has entered the correct values in input fields. In HTML you can perform validation either by checking the values at client-side or after submitting the form at the server-side. But these methods in HTML take lots of time to create and maintain the code. Moreover, if the user has disabled JavaScript then he or she may not receive the message regarding the error.

Therefore, in ASP.NET you can use ASP.NET Validation Controls while creating the form and specify what ASP.NET Validation Controls you want to use and to which server control you want bind this. ASP.NET Validation Controls are derived from a common base class and share a common set of properties and methods. You just have to drag and drop the ASP.NET Validation Control in the web form and write one line of code to describe its functionality.

This reduces the developer time from writing JavaScript for each type of validation. Moreover, through ASP.NET Validation Controls if any invalid data is entered the browser itself detects the error on the client side and displays the error without requesting the server. This is another advantage because it reduces the server load.

The five types of ASP.NET Validation Controls in ASP.NET Framework include:

• RequiredField Validation control: prompts message if any input field is left blank. This validation control can also be used to prompt message to the user if he or she has left any input field with its default value.

• Range Validation control: Prompts message to the user, if the data entered in the input field is not within the range of the values specified by the Maximum and Minimum properties of the validation control.

• Comparison Validation control: Allows the user to compare two values and check for comparisons such as equality, greater-than, less-than etc. In addition you can check whether the data entered in the input field is of the data type as specified by you.

• RegularExpression Validation control: Allows you to validate if the format of a certain input field is correct or not. You can check the validation of the commonly performed formats such as social security numbers, e-mail addresses, telephone numbers, and postal code.

• Custom Validation control: Allows you to define your own condition for validating the data in the input fields. Two validation functions can be performed using Custom Validation control: first on the server-side and second on the client-side. These functions contain logic defined by you to validate the input fields. These functions returns the True value and False value, if the condition you specified is correct or not respectively.

If the control’s value does not validate to what you have specified in the validation control tag, the web form displays an error message. Moreover, you can customize the format of the error message by using the control properties such as BackColor, BorderStyle, and BorderWidth. In addition, you can use Cascading Style Sheet (CSS) to format an error message.