Introduction to Web Programming


In this module, you will learn about Internet applications and the tools you use to create them.

This module introduces you to the concepts and terms used throughout this course, including how Web applications work, the parts of a Web application, how the Microsoft .NET Framework is organized, and how to use the Microsoft Visual Studio .NET programming environment.

Estimated lesson time: 55 minutes
Estimated lab time: 30 minutes

Goal:
– Describe four different types of Internet applications and know where to look for training on developing each type of application
– Explain how a Web application executes over the Internet and how that differs from a traditional, static Web site
– Understand the role that ASP.NET plays in creating Web applications
– List the parts that make up ASP.NET and describe some of its advantages over other Web application technologies, such as the Common Gateway Interface (CGI)

What Can You Create?

Web applications.

These provide content from a server to client machines over the Internet. Users view the Web application through a Web browser, such as Microsoft Internet Explorer or Netscape Navigator.

Web services.
These components provide processing services from a server to other applications over the Internet.
Internet-enabled applications.
These are stand-alone applications that incorporate aspects of the Internet to provide online registration, Help, updates, or other services to the user over the Internet.
Peer-to-peer applications.
These are stand-alone applications that use the Internet to communicate with other users running their own instances of the application.
This course Next Course Next Course Next Course

How Web Applications Work


Web applications use a client/server architecture. The Web application resides on a server and responds to requests from multiple clients over the Internet, as shown in the figure below .

cli_srv


On the client side, the Web application is hosted by a browser, such as Internet Explorer or Netscape Navigator. The application’ s user interface takes the form of Hypertext Markup Language (HTML) pages that are interpreted and displayed by the client’ s browser.

On the server side, the Web application runs under Microsoft Internet Information Services (IIS). IIS manages the application, passes requests from clients to the application, and returns the application’ s responses to the client. These requests and responses are passed across the Internet using Hypertext Transport Protocol (HTTP). A protocol is a set of rules that describe how two or more items communicate over a medium, such as the Internet

The Web application composes responses to requests from resources found on the server. These resources include the executable code running on the server (what we traditionally think of as the “application” in Microsoft Windows programming), Web Forms, HTML pages, image files, and other media that make up the content of the application.

Web applications are much like traditional Web sites, except that the content presented to the user is actually composed dynamically by executable, rather than being served from a static page stored on the server.

The executable portion of the Web application enables you to do many things that you cannot do with a static Web site, such as:

  • Collect information from the user and store that information on the server.
  • Perform tasks for the user such as placing an order for a product, performing complex calculations, or retrieving information from a database.
  • Identify a specific user and present an interface that is customized for him or her.
  • Present content that is highly volatile, such as inventory, pending order, and shipment information.

This is only a partial list. Basically, you can do anything with a Web application that you can imagine doing with any client/server application. What makes a Web application special is that the client/server interaction takes place over the Internet.

What ASP.NET Provides

ASP.NET is the platform that you use to create Web applications and Web services that run under IIS. ASP.NET is not the only way to create a Web application. Other technologies, notably the CGI, also enable you to create Web applications. What makes ASP.NET special is how tightly it is integrated with the Microsoft server, programming, data access, and security tools.

ASP.NET provides a high level of consistency across Web application development. In a way, it is similar to the level of consistency that Microsoft Office brought to desktop applications. ASP.NET is part of the .NET Framework and is made up of several different components.

  • Visual Studio .NET Web development tools. These include visual tools for designing Web pages and application templates, project management, and deployment tools for Web applications.
  • The System.Web namespaces. These are part of the .NET Framework, and include the programming classes that deal with Web-specific items such as HTTP requests and responses, browsers, and e-mail.
  • Server and HTML controls. These are the user-interface components that you use to gather information from and provide responses to users.
  • In addition to the preceding components, ASP.NET also uses the following, more general programming components and Windows tools. These items aren’ t part of ASP.NET. However, they are key to ASP.NET programming.
  • Microsoft Internet Information Services (IIS). As mentioned in the previous section, IIS hosts Web applications on the Windows server.
  • The Microsoft Visual Basic .NET, Microsoft Visual C#, and JScript programming languages. These three languages have integrated support in Visual Studio .NET for creating Web applications.
  • The .NET Framework. This is the complete set of Windows programming classes; they include the ASP.NET classes as well as classes for other programming tasks such as file access, data type conversion, array and string manipulation, and so on.
  • ADO.NET database classes and tools. These components provide access to Microsoft SQL Server and ODBC databases. Data access is often a key component of Web applications.
  • Microsoft Application Center Test (ACT). This Visual Studio .NET component provides an automated way to stress-test Web applications.

ASP.NET is the most complete platform for developing Web applications that run under IIS. However, it is important to remember that ASP.NET is not platform-independent. Because it is hosted under IIS, ASP.NET must run on Windows servers. To create Web applications that run on non-Windows/IIS servers, such as Linux/Apache, you must use other tools—generally CGI.

 

Advantages of ASP.NET


ASP.NET has many advantages over other platforms when it comes to creating Web applications. Probably the most significant advantage is its integration with the Windows server and programming tools. Web applications created with ASP.NET are easier to create, debug, and deploy because those tasks can all be performed within a single development environment—Visual Studio .NET.

ASP.NET delivers the following other advantages to Web application developers:

  • Executable portions of a Web application compiled so they execute more quickly than interpreted scripts
  • On-the-fly updates of deployed Web applications without restarting the server
  • Access to the .NET Framework, which extends the Windows API
  • Use of the widely known Visual Basic programming language, which has been enhanced to fully support object-oriented programming
  • Introduction of the new Visual C# programming language, which provides a type-safe, object-oriented version of the C programming language (we will be focusing on VB.NET and not enter in this section further)
  • Automatic state management for controls on a Web page (called server controls) so that they behave much more like Windows controls
  • The ability to create new, customized server controls from existing controls
  • Built-in security through the Windows server or through other authentication/authorization methods
  • Integration with Microsoft ADO.NET to provide database access and database design tools from within Visual Studio .NET
  • Full support for Extensible Markup Language (XML), cascading style sheets (CSS), and other new and established Web standards
  • Built-in features for caching frequently requested Web pages on the server, localizing content for specific languages and cultures, and detecting browser capabilities

 

Lesson 2: Using ASP.NET

In this lesson, you will learn how ASP.NET organizes a Web application into parts, and you will learn the roles and names of those parts. You will be introduced to Web Forms, which are the central user-interface element of Web applications.

ASP.NET is part of the larger .NET Framework, so this lesson will also discuss how the .NET Framework is organized and how .NET applications run differently from the traditional Windows applications you might be used to.

Finally, this lesson ends with a discussion of the programming languages you can use to create Web applications. ASP.NET is not bound to any one programming language, and the end of this lesson lists some of the other available languages and explains some of the major differences between the two languages (Visual Basic .NET and Visual C#).

Goal:

  • List the parts of a Web application and describe how they run on the server
  • Explain how a Web form differs from and is similar to both an HTML page and a Windows form
  • Describe some of the different components you can place on a Web form
  • Explain the parts of the .NET Framework and how the common language run­time (CLR) executes .NET applications
  • Understand how the .NET Framework is organized and know where to look for classes that handle common application programming tasks
  • Compare the Visual Basic .NET and Visual C# programming languages

Parts of a Web Application

A Web application consists of three parts: content, program logic, and Web configuration information.

Parts of an ASP.NET Web Application

Part

Types of files

Description

Content

Web Forms, HTML, images, audio, video, other data

Content files determine the appearance of a Web application. They can contain static text and images as well as elements that are composed on the fly by the program logic (as in the case of a database query).

Program logic

Executable files, scripts

The program logic determines how the application responds to user actions. ASP.NET Web applications have a dynamic-link library (DLL) file that runs on the server, and they can also include scripts that run on the client machine.

Configuration

Web configuration file, Style sheets, IIS settings

The configuration files and settings determine how the application runs on the server, who has access, how errors are handled, and other details.

The Web form is the key element of a Web application. A Web form is a cross between a regular HTML page and a Windows form: It has the same appearance and similar behavior to an HTML page, but it also has controls that respond to events and run code, like a Windows form.

In a completed Web application, the executable portion of the Web form is stored in an executable (.dll) that runs on the server under the control of IIS. The content portion of the Web form resides in a content directory of the Web server

When a user navigates to one of the Web Forms pages from his or her browser, the following sequence occurs:

  1. IIS starts the Web application’ s executable if it is not already running.

  2. The executable composes a response to the user based on the content of the Web Forms page that the user requested and any program logic that provides dynamic content.

  3. IIS returns the response to the user in the form of HTML.

Once the user gets the requested Web form, he or she can enter data, select options, click buttons, and use any other controls that appear on the page. Some controls, such as buttons, cause the page to be posted back to the server for event processing and the sequence repeats itself

This cycle of events is described in greater detail in Lesson 2, “Creating Web Forms Applications.”

Web Form Components

Web Forms can contain several different types of components, as summarized below.

Components on a Web Form

Component

Examples

Description

Server controls

TextBox, Label, Button, ListBox, DropDownList, DataGrid

These controls respond to user events by running event procedures on the server. Server controls have built-in features for saving data that the user enters between page displays. You use server controls to define the user interface of a Web form.

HTML controls

Text area, Table, Image,
Submit Button, Reset Button

These represent the standard visual elements provided in HTML. HTML controls are useful when the more complete feature set provided by server controls is not needed.

Data controls

SqlConnection, SqlCommand, OleDbConnection,
OleDbCommand, DataSet

Data controls provide a way to connect to, perform commands on, and retrieve data from SQL and OLE databases and XML data files.

System components

FileSystemWatcher, EventLog, MessageQueue

These components provide access to various system-level events that occur on the server.

You use the server and HTML controls to create the user interface on a Web form. The data controls and system components appear on the Web form only at design time to provide a visual way for you to set their properties and handle their events.
At run time, data controls and system components do not have a visual representation.

image_controls

The .NET Framework

ASP.NET is an important part of the .NET Framework, but it is just one part. Understanding what else the .NET Framework provides will help you program your ASP.NET application effectively and avoid writing new code to perform tasks that are already implemented within the .NET Framework.

First, a little background. The .NET Framework is the new Microsoft programming platform for developing Windows and Web software. It is made up of two parts:

  • An execution engine called the common language runtime (CLR)

  • A class library that provides core programming functions, such as those formerly available only through the Windows API, and application-level functions used for Web development (ASP.NET), data access (ADO.NET), security, and remote management

.NET applications aren’ t executed the same way as the traditional Windows applications you might be used to creating. Instead of being compiled into an executable containing native code, .NET application code is compiled into Microsoft intermediate language (MSIL) and stored in a file called an assembly. At run time, the assembly is compiled to its final state by the CLR. While running, the CLR provides memory management, type-safety checks, and other run-time tasks for the application.

Applications that run under the CLR are called managed code because the CLR takes care of many of the tasks that would have formerly been handled in the application’ s executable itself. Managed code solves the Windows programming problems of component registration and versioning (sometimes called DLL Hell) because the assembly contains all the versioning and type information that the CLR needs to run the application. The CLR handles registration dynamically at run time, rather than statically through the system registry as is done with applications based on the Common Object Model (COM).

The .NET class library provides access to all the features of the CLR. The .NET class library is organized into namespaces. Each namespace contains a functionally related group of classes. Table 1-4 summarizes the .NET namespaces that are of the most interest to Web application programmers.

A Summary of the .NET Framework Class Library

Category

Namespaces

Provides classes for

Common types

System

All the common data types, including strings, arrays, and numeric types. These classes include methods for converting types, for manipulating strings and arrays, and for math and random number tasks.

Data access

System.Data, System.Data.Common, System.Data.OleDb,
System.Data.SqlClient,
System.Data.SqlTypes

Accessing databases. These classes include methods for connecting to databases, performing commands, retrieving data, and modifying data.

Debugging

System.Diagnostics

Debugging and tracing application execution.

File access

System.IO, System.IO.IsolatedStorage, System.DirectoryServices

Accessing the file system. These include methods for reading and writing files and getting paths and filenames.

Network communication

System.Net, System.Net.Sockets

Communicating over the Internet using low-level protocols such as TCP/IP. These classes are used when creating peer-to-peer applications.

Security

System.Security,
System.Security.Cryptography, System.Security.Permissions, System.Security.Policy, System.Web.Security

Providing user authentication, user authorization, and data encrypting.

Web applications

System.Web, System.Web.Caching, System.Web.Configuration, System.Web.Hosting, System.Web.Mail,
System.Web.SessionState
, System.Web.UI, System.Web.UI.Design, System.Web.UI.WebControls, System.Web.UI.HtmlControls

Creating client-server applications that run over the Internet. These are the core classes used to create ASP.NET Web applications.

Web services

System.Web.Services, System.Web.Services.Configuration, System.Web.Services.Description,
System.Web.Services.Discovery,
System.Web.Services.Protocols

Creating and publishing components that can be used over the Internet. These are the core classes used to create ASP.NET Web services.

Windows applications

System.Windows.Forms, System.Windows.Forms.Design

Creating applications using the Microsoft Windows user interface components. These classes provide Windows forms and controls as well as the ability to create custom controls.

XML data

System.Xml, System.Xml.Schema, System.Xml.Serialization, System.Xml.Xpath, System.Xml.Xsl

Creating and accessing XML files.

Since the .NET namespaces organize classes by function, you can use them to help locate the classes and class members that provide the CLR features you want to use. For example, the System namespace is one of the most commonly used namespaces because it contains the classes for all the fundamental data types. Any time you declare a variable with a numeric, string, or array type, you are using the System namespace.

This approach allows the .NET Framework to provide built-in methods for converting data types and manipulating strings and arrays. For instance, the following lines of code use the built-in methods of the String and Array classes to sort a list.

Visual Basic .NET
' Declare and initialize a string.
Dim strFruit As String = "oranges apples peaches kumquats nectarines mangos"
' Declare an array.
Dim arrFruit As String()
' Place each word in an array element
arrFruit = strFruit.Split(" ")
' Sort the array.
System.Array.Sort(arrFruit)
' Put the sorted data back in the string.
strFruit = String.Join(" ", arrFruit)
Visual C#
// Declare and initialize a string.
string strFruit = "oranges apples peaches kumquats nectarines mangos";
// Declare an array
string[] arrFruit;
// Place each word in an array element.
arrFruit = strFruit.Split(" ".ToCharArray());
// Sort the array.
System.Array.Sort(arrFruit);
// Put the sorted array back in the string.
strFruit = System.String.Join(" ", arrFruit);

Many of the class methods in the System namespace can be used directly without first creating an object from the class. These are called shared members in Visual Basic .NET and static members in Visual C#. Shared and static members can be called from the class name itself, as in the System.Array.Sort line in the preceding code. Another example of a class with shared/static members is the Math class, as shown by the following Pi and Pow methods:

Visual Basic .NET
' Get the area of a circle.
dblCircArea = System.Math.Pi * System.Math.Pow(intRadius, 2)
Visual C#
// Get the area of a circle.
dblCircArea = System.Math.PI * System.Math.Pow(intRadius, 2);

The .NET Framework provides about 100 different namespaces. Only about 40 of the most common ones are summarized in Table 1-4. For a complete list of the .NET Framework namespaces, see the topic titled “Class Library” in the Visual Studio .NET online Help.

Programming Languages

ASP.NET and, indeed, the whole .NET Framework are programming language–independent. That means you can choose any language that has implemented a CLR-compliant compiler. In addition to developing its own programming languages, Microsoft has formed partnerships with many language vendors to provide .NET support for Perl, Pascal, Eiffel, Cobol, Python, Smalltalk, and other programming languages.

This book covers creating Web applications with the Visual Basic .NET and the Visual C# programming languages. These two languages are functionally equivalent, which means that they each provide equal abilities to create Web applications. The differences between the two languages are syntactical and stylistic.

Most current programmers will choose the language they are most familiar with. Current Visual Basic programmers will be more comfortable developing Web applications in Visual Basic .NET; C or C++ programmers will be more comfortable developing with Visual C#.

If you are new to programming or if you are choosing to extend your programming skills to new languages, learning both Visual Basic .NET and Visual C# is a practical goal. This is especially true when you create Web applications, since most of the tasks are performed through the .NET Framework classes, which means Visual Basic .NET code and Visual C# code often look nearly identical.

Table 1-5 summarizes some significant differences between Visual Basic .NET and Visual C#. This information is useful to keep in mind if you are choosing a programming language for the first time or if you are planning to switch between languages.

Visual Basic .NET and Visual C# Differences

Feature

Visual Basic .NET

Visual C# .NET

Case sensitive

Not case sensitive:

response.write("Yo") ' OK

Case sensitive:

response.write("Yo"); // Error Response.Write("Yo"); // OK

Functional blocks

Use beginning and ending statements to declare functional blocks of code:

Sub Show(strX as String)
  Response.Write(strX)
End Sub

Use braces to declare functional blocks of code:

void Show (string strX)
{
Response.Write(strX);
}

Type conversion

Implicit type conversions are permitted by default:

Dim intX As Integer
intX = 3.14  ' Permitted

You can limit conversions by including an Option Strict On statement at the beginning of modules.

Type conversions are performed explicitly by casts:

int intX;
intX = 3.14; // Error!
intX = (int)3.14; //Cast, OK.

Or, use type conversion methods:

string strX;
strX = intX.ToString();

Arrays

Array elements are specified using
parentheses:

arrFruit(1) = "Apple"

Array elements are specified using square brackets:

arrFruit[1] = "Apple";

Methods

You can omit parentheses after method names if arguments are omitted:

strX = objX.ToString

You must include parentheses after all methods:

strX = objX.ToString();

Statement
termination

Statements are terminated by carriage return:

Response.Write("Hello")

Statements are terminated by the semicolon (;):

Response.Write("Hello");

Statement
continuation

Statements are continued using the underscore (_):

intX = System.Math.Pi * _
  intRadius

Statements continue until the semicolon (;) and can span multiple lines if needed:

intX = System.Math.PI * 
  intRadius;

String operator

Use the ampersand (&) or plus sign (+) to join strings:

strFruit = "Apples" & _
  " Oranges"

Use the plus sign (+) to join strings:

strFruit = "Apples" + 
  " Oranges";

Comparison
operators

Use =, >, <, >=, <=, <> to compare values:

If intX >= 5 Then

Use ==, >, <, >=, <=, != to compare values:

if (intX >= 5)

Negation

Use the Not keyword to express logical negation:

If Not IsPostBack Then

Use the ! operator to express logical negation:

if (!IsPostBack)

Object comparison

Use the Is keyword to compare object
variables:

If objX Is objY Then

Use == to compare object variables:

if (objX == objY)

Object existence

Use the Nothing keyword or the IsNothing function to check if an object exists:

If IsNothing(objX) Then

Use the null keyword to check if an object exists:

if (objX == null)

In addition to the differences shown, there are significant keyword differences between the two languages. The code examples throughout this book illustrate those differences. The Visual Studio .NET Help topic “Language Equivalents” provides a complete comparison of Visual Basic .NET, Visual C#, and other Microsoft languages.

 

 

Using Visual Studio .NET

The Visual Studio .NET programming environment presents new window types, new ways to manage those windows, and new integration with Internet content. This lesson offers a tour of these new features as well as an overview of some of the older Visual Studio .NET debugging and Help features presented from a Web application–programming viewpoint.

After this section, you will be able to

  • Use the Start page to open new or existing projects, get current product information, and set environment preferences
  • List the two different Visual Studio .NET window types and use the Auto Hide feature to make the most out of screen space for editing documents
  • Cut and paste items using the Clipboard Ring on the Toolbox
  • Edit Web forms and HTML pages visually or in HTML
  • Write code using the Code Editor’ s automated features and modify Visual Studio .NET settings to turn those features on or off
  • Build, run, and debug applications using Visual Studio .NET
  • Get Help and set Help filters for your preferred programming language

The Start Page


When you start Visual Studio .NET, the first thing you see is the Start page, as shown in the image below.
The Start page contains various panes to make information easier to find and to help simplify some common tasks, such as opening a recent file.

startpage


The Projects pane, shown on the left hand side, displays the most recently saved projects in the form of hyperlinks. To open one of these recent projects, click the project name. To create a new project or to open an existing project not displayed in the recent projects list, click the appropriate button on the Projects pane (top area).

To the left of the Start page is a list of other topics containing current information about Visual Studio .NET, other Microsoft products, programming, guidance, and other information. If you click one of these topics, the Start page displays the topic, as shown in figure below.

startpane


The information displayed in the Start page is dynamic, with much of the information coming from the Internet. This ensures that the information is current; it’ s a good idea to check the Headlines and Downloads panes occasionally to get the latest news.

Creating a New Project


Click on the “New Project” Link in the start page. A pop-up will appear asking you what type of project you would like to start.

projects


Select from the left pane Visual Basic>Web and from the middle list “ASP.NET Web Application”.

At the bottom, type in your project name (make sure it does not contain any spaces or invalid characters like “$”, “^”, “%”, “” or “/”.

Choose the location where you would like your project to be saved. By default, it will go into your Documents Folder Visual Studio 2010Projects.
The solution is the entity which can hold one or more projects. If you are building a DLL and you would like to create an installer for it, you would create two projects which belong to the same solution.

For starting, the solution will be named the same as the application and it is recommended that you keep the .sln file (the file extension for solutions is .sln) outside the build directory.

For this, make sure you tick “Create Directory for Solution” tickbox.

Leave the “Add to Source control” unticked as we will be working without a Source Safe Server.

Press OK when done.

Visual Studio .NET Windows


Visual Studio .NET has two types of windows: Document windows and Tool windows.
Document windows display the content of your application: the forms, Web pages, and code all appear in Document windows.
You can have multiple Document windows open at once, and you can choose between them by clicking their tabs near the top of
the screen, as shown below.

projects


The Tool windows display the components you use to create your application. These components include the controls, database connections, classes, and properties you use in the project. Tool windows are displayed to the left and right of the Document windows and they can be set to slide in or out of view by clicking their tabs.

To cause a tabbed Tool window to remain on screen, toggle the Auto Hide icon at the top right of the Tool window. The Auto Hide icon looks like a tiny pushpin. Click the pushpin again to cause the Tool window to return to tabbed display. You can use the tabbed display to hide the Tool windows on both sides of the Document window and provide more space for editing your application’ s content

page2


The Visual Studio .NET Toolbox displays the controls and components you can add to a Document window. The contents of the Toolbox change depending on the type of document you are currently editing. When you are editing a Web form, for example, the Toolbox displays the server controls, HTML controls, data controls, and other components that you can add to a Web form, as shown

toolbox The components in the Toolbox are categorized. When you click one of the categories, the Toolbox displays the items in that category. You can scroll through the items in the Toolbox by clicking the up and down arrows at the top and the bottom of the component list.

One helpful feature is that you can hold your mouse pointer over a control and it will pop up a help message that talks about it a bit. Here you can see that a ComboBox “displays an editable text box with a drop-down list of permitted values.” Try this with some controls that don’t sound familiar. There are some controls that you might never use, but explore what’s there and you might find something new that makes things easier for you.

When the current document is code, the Toolbox contains only the Clipboard Ring. The Clipboard Ring keeps track of the last 20 items you have copied (Ctrl+C) or cut (Ctrl+X) so that you can paste them back into a document.
To paste an item from the Clipboard Ring, click the item and drag it to where you want to insert it.

When you move the mouse pointer over an item in the Clipboard Ring, Visual Studio expands that item to show you more of the text it contains.

 

Editing Web Documents


You can edit Web forms and HTML documents visually by using the same drag-and-drop techniques that you use when editing Windows forms, or you can edit them as text files. To switch between edit modes, click the Design or HTML tabs at the bottom of the Document window.

There is no way to do some tasks visually, so you will often need to edit Web documents as text. Using the HTML mode can also be more convenient than using the visual tools if you are already familiar with HTML. The IntelliSense technology in Visual Studio .NET provides help for completing HTML elements.

You can switch back to Design mode to preview any changes you make in HTML mode simply by clicking on the Design tab at the bottom of the Document window.


splitpage


Web Forms pages have code-behind files associated with them. These files are created automatically when you create a new Web form.

They have the same base name as the Web form with the .vb or .cs filename extension added. You can view them by pressing F7 or right clicking on the .aspx file and choosing Show Code as shown below.

view_code


The Visual Studio .NET Code Editor also provides completion through IntelliSense for keywords and class members that you use in code

If you are programming in Visual Basic, the autocomplete feature will also correct the capitalization of keywords and member names when you complete a line. If you are using Visual C#, however, Visual Studio .NET will not recognize a keyword or member name if it is not capitalized correctly. This is because Visual Basic .NET is not case sensitive, but Visual C# is.

The Visual Studio .NET Code Editor highlights syntax errors and undeclared variables as you complete each line. These errors are underlined with a squiggly line, and if you move the mouse pointer over the error, a description of the error is displayed

You can turn most of the Code Editor’ s automatic features on or off by changing the settings in the Tools>Options settings.You can also use the Options dialog box to change automatic indentation, code block completion, and other language-specific settings.

The Solution Explorer


Visual Studio .NET organizes applications into projects and solutions. A project is a collection of files that will ultimately make up a single executable. A solution is a group of projects that make up a single functional unit. You view the files in a solution by using the Solution Explorer.

solution_explorer
The project shown in bold is the start-up project. The start-up project is the project that runs when you click Start in Visual Studio .NET. When you’ re developing multiple projects as part of a single solution, the start-up project usually calls the other projects in the solution.
Information about a solution is stored in a solution file (.sln), which is placed in your My Documents folder by default. You can open the solution using this file, or you can open projects directly using their project files (.vbproj or .csproj), which are placed in the project folders. If you open a project file, Visual Studio .NET creates a new solution file when you save the project.

Running a Project


You can run a project within Visual Studio .NET by clicking Start on the toolbar, by choosing Start from the Debug menu, or by pressing F5. When you run a project, Visual Studio .NET builds the project files and displays any errors that occur in the Task List window.
The same error list appears when you decide to compile/deploy your project by pressing Build/Build[Applicationname] from the menu.

Double-clicking the error description in the Task List selects the line with the error in the Document window so that you can correct the error.

pagebuild


If no errors occur during the build, Visual Studio .NET starts the application in debug mode and, in the case of a Web application, starts Internet Explorer, and displays the application’ s start page.

If an error occurs while the application is running in debug mode, Visual Studio .NET displays the error in the browser.

You have two choices at this point:

If you know what caused the error, you can stop the application by closing the browser window to return to Visual Studio .NET and correct the error shown.

If you are unsure of what caused the error, you can click Back in the browser, switch to Visual Studio .NET to set a breakpoint at a position in the code before the error occurred, and then switch back to the browser to try the task again. Visual Studio .NET will stop the application at the breakpoint you set so that you can step through the code to locate the source of the error.

Once you locate the error, you must stop the application before you can correct it. In previous versions of Visual Studio .NET, you could correct errors in debug mode and continue running the application.

 

Setting Breakpoints and Watching Variables


You can stop a project at a particular line of code by setting a breakpoint. When Visual Studio .NET runs the project, Visual Studio .NET will stop the project and display the line with the breakpoint in the Code Editor before that line executes.

To set a breakpoint, click the gray margin to the left of the line you want to break at, or select the line and press F9

pagebuild


Once Visual Studio .NET stops at a breakpoint, you can view the value of active variables by moving the mouse pointer over the variable. If the variable is a complex type, such as an object or an array, you can view its data by adding it to the Watch window below.

After you have stopped at a breakpoint, you can continue running your application by clicking Continue on the toolbar or by pressing F5. Alternately, you can execute one line at a time by pressing F10 or F11.

F10 executes each procedure call as a single statement. In other words, it steps over a procedure by executing it and stopping at the next line in the current procedure. F11 executes procedure calls by stepping in to the procedure and stopping at the first line in the called procedure. To execute a single line of code outside of the context of the project, type the code in the Command window.

Advertisements

How to be a MCPD

Microsoft Certified Professional Developer Requirements


MCPD-LOGO-480x480This is the information collected from the Microsoft website for those who are thinking about becoming a web-developer in ASP.NET 4 using Visual Studio 2010.

MCPD certifications help validate a comprehensive set of skills that are necessary to design, build, and deploy applications successfully by using Microsoft Visual Studio and the Microsoft .NET Framework. This certification builds on the MCTS certification and is designed to help provide hiring managers with a strong indicator of your potential job success. Candidates for the MCPD typically have two to three years of relevant experience and a commitment to remaining current in best practices and technologies.

Goal:To design, build, and deploy web-based applications by using Visual Studio 2010. Exams required as prerequisites:

MCTS: .NET Framework 4, Web Applications
and
MCTS: .NET Framework 4, Service Communication Applications
and
MCTS: .NET Framework 4, Data Access Exam to be taken
New Exam Needed:
Exam 70-519: PRO: Designing and Developing Web Applications Using Microsoft .NET Framework 4

Exam1: MCTS: .NET Framework 4, Web Applications

About this Exam


This exam is designed to test the candidate’s knowledge and skills for developing Web applications using ASP.NET and the .NET Framework 4.

Questions that contain code will be presented in either VB or C#. Candidates can select one of these languages when they start the exam.

Audience Profile

Candidates for this exam are professional Web developers who use Microsoft Visual Studio. Candidates should have a minimum of two to three years of experience developing Web-based applications by using Visual Studio and Microsoft ASP.NET. Candidates should be experienced users of Visual Studio 2008 and later releases and should have a fundamental knowledge of the .NET Framework 4 programming languages (C# or Microsoft Visual Basic). In addition, candidates should understand how to use the new features of Visual Studio 2010 and the .NET Framework 4.

Candidates should also have a minimum of one year of experience with the following:

 

  • • Accessing data by using Microsoft ADO.NET and LINQ
  • • Creating and consuming Web and Windows Communication Foundation (WCF) services
  • • State management
  • • ASP.NET configuration
  • • Debugging and deployment
  • • Application and page life-cycle management
  • • Security aspects such as authentication and authorization
  • • Client-side scripting languages
  • • Internet Information Server (IIS)
  • • ASP.NET MVC

 

Skills Being Measured

This exam measures your ability to accomplish the technical tasks listed below.The percentages indicate the relative weight of each major topic area on the exam.

Developing Web Forms Pages (19%)

• Configure Web Forms pages.

This objective may include but is not limited to: page directives such as ViewState, request validation, event validation, MasterPageFile; ClientIDMode; using web.config; setting the html doctype

This objective does not include: referencing a master page; adding a title to a Web form

• Implement master pages and themes.

This objective may include but is not limited to: creating and applying themes; adding multiple content placeholders; nested master pages; control skins; passing messages between master pages; switching between themes at runtime; loading themes at run time; applying a validation schema

This objective does not include: creating a master page; basic content pages

• Implement globalization.

This objective may include but is not limited to: resource files, browser files, CurrentCulture, currentUICulture, ASP:Localize

• Handle page life cycle events.

This objective may include but is not limited to: IsPostback, IsValid, dynamically creating controls, control availability within the page life cycle, accessing control values on postback, overriding page events

• Implement caching.

This objective may include but is not limited to: data caching; page output caching; control output caching; cache dependencies; setting cache lifetimes; substitution control

This objective does not include: distributed caching (Velocity)

• Manage state.

This objective may include but is not limited to: server-side technologies, for example, session and application; client-side technologies, for example, cookies and ViewState; configuring session state (in proc, state server, Microsoft SQL Server; cookieless); session state compression; persisting data by using ViewState; compressing ViewState; moving ViewState

Developing and Using Web Forms Controls (18%)

• Validate user input.

This objective may include but is not limited to: client side, server side, and via AJAX; custom validation controls; regex validation; validation groups; datatype check; jQuery validation

This objective does not include: RangeValidator and RequiredValidator

• Create page layout.

This objective may include but is not limited to: AssociatedControlID; Web parts; navigation controls; FileUpload controls

This objective does not include: label; placeholder, panel controls; CSS, HTML, referencing CSS files, inlining

• Implement user controls.

This objective may include but is not limited to: registering a control; adding a user control; referencing a user control; dynamically loading a user control; custom event; custom properties; setting toolbox visibility

• Implement server controls.
This objective may include but is not limited to: composite controls, INamingContainer, adding a server control to the toolbox, global assembly cache, creating a custom control event, globally registering from web.config; TypeConverters
This objective does not include: postback data handler, custom databound controls, templated control

• Manipulate user interface controls from code-behind.
This objective may include but is not limited to: HTML encoding to avoid cross-site scripting, navigating through and manipulating the control hierarchy; FindControl; controlRenderingCompatibilityVersion; URL encoding; RenderOuterTable
This objective does not include: Visibility, Text, Enabled properties

Implementing Client-Side Scripting and AJAX (16%)

• Add dynamic features to a page by using JavaScript.

This objective may include but is not limited to: referencing client ID; Script Manager; Script combining; Page.clientscript.registerclientscriptblock; Page.clientscript.registerclientscriptinclude; sys.require (scriptloader)

This objective does not include: interacting with the server; referencing JavaScript files; inlining JavaScript

• Alter a page dynamically by manipulating the DOM.
This objective may include but is not limited to: using jQuery, adding, modifying, or removing page elements, adding effects, jQuery selectors
This objective does not include: AJAX

• Handle JavaScript events.

This objective may include but is not limited to: DOM events, custom events, handling events by using jQuery

• Implement ASP.NET AJAX.
This objective may include but is not limited to: client-side templating, creating a script service, extenders (ASP.NET AJAX Control Toolkit), interacting with the server, Microsoft AJAX Client Library, custom extenders; multiple update panels; triggers; UpdatePanel.UpdateMode; Timer
This objective does not include: basic update panel and progress

• Implement AJAX by using jQuery.
This objective may include but is not limited to: $.get, $.post, $.getJSON, $.ajax, xml, html, JavaScript Object Notation (JSON), handling return types
This objective does not include: creating a service

Configuring and Extending a Web Application (15%)

• Configure authentication and authorization.
This objective may include but is not limited to: using membership, using login controls, roles, location element, protecting an area of a site or a page
This objective does not include: Windows Live; Microsoft Passport; Windows and Forms authentication

• Configure providers.
This objective may include but is not limited to: role, membership, personalization, aspnet_regsql.exe

This objective does not include: creating custom providers

• Create and configure HttpHandlers and HttpModules.

This objective may include but is not limited to: generic handlers, asynchronous handlers, setting MIME types and other content headers, wiring modules to application events

• Configure initialization and error handling.

This objective may include but is not limited to: handling Application_Start, Session_Start, and Application_BeginRequest in global.asax, capturing unhandled exceptions, custom error section of web.config, redirecting to an error page; try and catch; creating custom exceptions

• Reference and configure ASMX and WCF services.
This objective may include but is not limited to: adding service reference, adding Web reference, changing endpoints, wsdl.exe, svcutil.exe; updating service URL; shared WCF contracts assembly
This objective does not include: creating WCF and ASMX services

• Configure projects and solutions, and reference assemblies.

This objective may include but is not limited to: local assemblies, shared assemblies (global assembly cache), Web application projects, solutions, settings file, configuring a Web application by using web.config or multiple .config files; assemblyinfo

• Debug a Web application.

This objective may include but is not limited to: remote, local, JavaScript debugging, attaching to process, logging and tracing, using local IIS, aspnet_regiis.exe

• Deploy a Web application.

This objective may include but is not limited to: pre-compilation, publishing methods (e.g.,MSDeploy, xcopy, and FTP), deploying an MVC application

This objective does not include: application pools, IIS configuration

Displaying and Manipulating Data (19%)

• Implement data-bound controls.
This objective may include but is not limited to: advanced customization of DataList, Repeater, ListView, FormsView, DetailsView, TreeView, DataPager, Chart, GridView

This objective does not include: working in Design mode

• Implement DataSource controls.
This objective may include but is not limited to: ObjectDataSource, LinqDataSource, XmlDataSource, SqlDataSource, QueryExtender, EntityDataSource

This objective does not include: AccessDataSource, SiteMapDataSource

• Query and manipulate data by using LINQ.

This objective may include but is not limited to: transforming data by using LINQ to create XML or JSON, LINQ to SQL, LINQ to Entities, LINQ to objects, managing DataContext lifetime

This objective does not include: basic LINQ to SQL

• Create and consume a data service.

This objective may include but is not limited to: WCF, Web service; server to server calls; JSON serialization, XML serialization
This objective does not include: client side, ADO.NET Data Services

• Create and configure a Dynamic Data project.

This objective may include but is not limited to: dynamic data controls, custom field templates; connecting to DataContext and ObjectContext

Developing a Web Application by Using ASP.NET MVC 2 (13%)

• Create custom routes.

This objective may include but is not limited to: route constraints, route defaults, ignore routes, custom route parameters

• Create controllers and actions.

This objective may include but is not limited to: Visual Studio support for right-click context menus; action filters (including Authorize, AcceptVerbs, and custom) and model binders; ActionResult sub-classes

• Structure an ASP.NET MVC application.

This objective may include but is not limited to: single project areas (for example, route registration, Visual Studio tooling, and inter-area links); organizing controllers into areas; shared views; content files and folders

• Create and customize views.

This objective may include but is not limited to: built-in and custom HTML helpers (for example, HTML.RenderAction and HTML.RenderPartial), strongly typed views, static page checking, templated input helpers, ViewMasterPage, ViewUserControl

This objective does not include: Microsoft.Web.Mvc Futures assembly

10 Benefits Of Bluetooth

Below, are 10 benefits and reasons to use Bluetooth technology.

bluetooth_logo1. Wireless
As you probably already know, there are many benefits and advantages to using wireless devices. Along with improving safety as a result of eliminating wires you don’t need, wireless also offers you plenty of other advantages. When traveling with your laptop
or other wireless devices, you’ll no longer have to worry about bringing connection cables.

2. Bluetooth is actually inexpensive
The technology of Bluetooth is cheap for companies to implement, which results in lower costs for the company. These savings are then passed from the company on to you.

3. Bluetooth is automatic
Bluetooth doesn’t have you set up a connection or push any buttons. When two or more devices enter  a range of up to 30 feet of each other, they will automatically begin to communicate without you  having to do anything.

4. Standardized protocol
Bluetooth is standardized wireless, meaning that a high level of compatibility among devices is  guaranteed. Bluetooth will connect devices to each other, even if they aren’t the same model.

5. Low interference
Bluetooth devices almost always avoid interference from other wireless devices. Bluetooth uses a  technique known as frequency hopping, and also  low power wireless signals.

6. Low energy consumption
As a result of Bluetooth using low power signals, the technology requires very little energy and will use less battery or electrical power as a result.
This is an excellent benefit for mobile devices,  as Bluetooth won’t drain the battery.

7. Sharing voice and data
The standard for Bluetooth will allow compatible devices to share data and voice communications.
This is great for mobile phones and headsets, as Bluetooth simplifies driving and talking on your cell phone.

8. Instant PAN (Personal Area Network)
You can connect up to seven Bluetooth devices to each other within a range of up to 30 feet, forming a piconet or PAN. For a single room, you can also set up multiple piconets.

9. Upgradeable
Upgradeable is the standard for Bluetooth. There are newer versions of Bluetooth in the works,  which offer many new advantages and backward  compatible with older versions.

10. The technology stays
Bluetooth technology is a world wide, universal wireless standard. With it being as popular as it is, you can count on it being around for years to come. As more and more devices start to use Bluetooth technology, more manufacturers will be eager to make their products compatible. A chain reaction will occur, making Bluetooth the standard for cutting edge wireless.

 

The Pros and Cons of Video Blogging

VlogsVideo blogging has a lot of advantages over text-based blogging, and it is little wonder that this new technology is catching on all over the globe. Video blogs very effectively grab the attention of web surfers, and people are much more likely to become excited about the dynamic content of a video blog than they are likely to find a written posting very thrilling. The more enthusiastic viewers are about a site, the quicker the word of mouth spreads, and the more traffic the site will get.

Of course, there are plenty of disadvantages to video blogging as well. Hosting a v-blog requires quite a bit of server space, which can make it difficult to get started. It takes more time to process and upload a video file than it does to dash off a quick bit of text, which means that running and updating a video blog can be quite a bit of work. In addition, web surfers sometimes grow frustrated with the slow loading times of the files on many video blogs. Whether you opt for a video blog or not depends on what kind of subject matter you want to cover, and how much time you can devote to video blogging. Before you decide to pursue a video blog, consider if there is an easier way for you to get your message across.

 

String Functions ASP.NET VB

In this article, I have compiled some common String operations that we encounter while working with the String class. 
All the samples are based on two pre-declared string variables: strOriginal and strModified.
    Dim strOriginal As String = “These functions will come handy”

    Dim strModified As String = String.Empty

1. Iterate a String – You can use the ‘for’ loop or ‘foreach’ loop to iterate through a string. The ‘for’ loop gives you more flexibility over the iteration.

For i As Integer = 0 To strOriginal.Length – 1

            Response.Write(strOriginal(i).ToString())

      Next i

Or

For Each c As Char In strOriginal

            Response.Write(c.ToString())

Next c

2. Split a String – You can split strings using String.Split(). The method takes an array of chars, representing characters to be used as delimiters. In this example, we will be splitting the strOriginal string using ‘space’ as delimiter.

      Dim delim As Char() = {” “c}

      Dim strArr As String() = strOriginal.Split(delim)

      For Each s As String In strArr

            Response.Write(s)

      Next s

3. Extract SubStrings from a String – The String.Substring() retrieves a substring from a string starting from a specified character position. You can also specify the length.

      ‘ only starting position specified

      strModified = strOriginal.Substring(25)

      Response.Write(strModified)

      ‘ starting position and length of string to be extracted specified

      strModified = strOriginal.Substring(20, 3)

      Response.Write(strModified)

4. Create a String array – There are different ways to create a Single Dimensional and Multi Dimensional String arrays. Let us explore some of them:

‘ Single Dimensional String Array

      Dim strArr As String() = New String(2) { “string 1”, “string 2”, “string 3”}

      ‘ Omit Size of Array

      Dim strArr1 As String() = New String() { “string 1”, “string 2”, “string 3” }

      ‘ Omit new keyword

      Dim strArr2 As String() = {“string 1”, “string 2”, “string 3”}

      ‘ Multi Dimensional String Array

      Dim strArr3 As String(,) = New String(1, 1) { { “string 1”, “string 2” }, { “string 3”, “string 4” } }

      ‘ Omit Size of Array

      Dim strArr4 As String(,) = New String(, ) { { “string 1”, “string 2” }, { “string 3”, “string 4” } }

      ‘ Omit new keyword

      Dim strArr5 As String(,) = { { “string 1”, “string 2” }, { “string 3”, “string 4” } }

5. Reverse a String – One of the simplest ways to reverse a string is to use the StrReverse() function.

    Dim strModified As String = StrReverse(strOriginal)

      Response.Write(strModified)

6. Compare Two Strings – You can use the String.Compare() to compare two strings. The third parameter is a Boolean parameter that determines if the search is case sensitive(false) or not(true).

      If (String.Compare(strOriginal, strModified, False)) < 0 Then

            Response.Write(“strOriginal is less than strOriginal1”)

      ElseIf (String.Compare(strOriginal, strModified, False)) > 0 Then

            Response.Write(“strOriginal is more than strOriginal1”)

      ElseIf (String.Compare(strOriginal, strModified, False)) = 0 Then

            Response.Write(“Both strings are equal”)

      End If

7. Convert a String to Byte[] (Byte Array) – The Encoding.GetBytes() encodes all the characters into a sequence of bytes. The method contains six overloads out of which we will be using the Encoding.GetBytes(String).

Dim b As Byte() = Encoding.Unicode.GetBytes(strOriginal)

Note: You can adopt different character encoding schemes (ASCII, Unicode etc.) based on your requirement.

8. Convert Byte[] to String – The Encoding.GetString() decodes a sequence of bytes into a string.

      ‘ Assuming you have a Byte Array byte[] b

      strModified = Encoding.Unicode.GetString(b)

9. Convert a String to Char[](Char Array) – To convert a String to Char Array, use the String.ToCharArray() which copies the characters in the string to a Unicode character array.

      Dim chArr As Char() = strOriginal.ToCharArray()

10. Convert a Char[] to String – A convenient way to convert a character array to string is to use the String constructor which accepts a character array

      strModified = New String(chArr)

11. Test if String is null or Zero Length – A simple way to test if a string is null or empty is to use the String.IsNullOrEmpty(string) which returns a Boolean value.

       Dim check As Boolean = String.IsNullOrEmpty(strOriginal)

Create a String of characters accepted from user –

12. Convert the Case of a String – The String class contains methods to convert a string to lower and upper cases. However, it lacks a method to convert a string to Proper Case/Title Case. Hence we will use the ‘TextInfo’ class to do the same.
      Dim cultureInfo As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture

      Dim textInfo As System.Globalization.TextInfo = cultureInfo.TextInfo

      ‘ Lower Case

      Response.Write(textInfo.ToLower(strOriginal))

      ‘ Upper Case

      Response.Write(textInfo.ToUpper(strOriginal))

      ‘ Proper Case

      Response.Write(textInfo.ToTitleCase(strOriginal))

13. Count the occurrences of words in a String – You can adopt multiple ways to find the occurrence of a word in a string. One of them is to use the String.IndexOf() which is one of the ways of finding the occurrence of the word. In VB.NET, use String.InStr().
Another simple way is to use ‘Count’ property of the Regex.Matches() collection. However this method is slow. We will explore both these methods in the sample.

      ‘ Using IndexOf

       Dim strt As Integer = 0

       Dim cnt As Integer = -1

       Dim idx As Integer = -1

       strOriginal = “She sells sea shells on the sea shore”

       Dim srchString As String = “sea”

       Do While strt <> -1

             strt = strOriginal.IndexOf(srchString, idx + 1)

             cnt += 1

             idx = strt

       Loop

       Response.Write(srchString & ” occurs ” & cnt & ” times”)

      ‘ Using Regular Expression

       Dim rex As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex(srchString)

      Dim count As Integer = rex.Matches(strOriginal).Count

      Response.Write(srchString & ” occurs ” & count & ” times”)

14. Insert Characters inside a String – The String.Insert() inserts text at a specified index location of a string. You can insert either a character or a string at a given index location. For eg: We will insert a string “very” at index 26 in string strOriginal.

strModified = strOriginal.Insert(26, “very “)

Response.Write(strModified)

15. Replace characters in a String – The String.Replace() removes characters from a string and replaces them with a new character or string.

      strModified = strOriginal.Replace(“come handy”, “be useful”)

      Response.Write(strModified)

16. Count Words and Characters In a String – You can use Regular Expression to do so as shown below:

      ‘ Count words

      Dim wordColl As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(strOriginal, “[S]+”)

      Response.Write(wordColl.Count.ToString())

      ‘ Count characters. White space is treated as a character

      Dim charColl As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(strOriginal, “.”)

      Response.Write(charColl.Count.ToString())

17. Remove characters in a String – The String.Remove() deletes a specified number of characters beginning at a given location within a string

      ‘ Removes everything beginning at index 25

      strModified = strOriginal.Remove(25)

      Response.Write(strModified)

Or

      ‘ Removes specified number of characters(five) starting at index 20

      strModified = strOriginal.Remove(20,5)

      Response.Write(strModified)

18. Create Date and Time from String – Use the DateTime.Parse() to convert a string representing datetime to its DateTime equivalent. The DateTime.Parse() provides flexibility in terms of adapting strings in various formats.

      strOriginal = “20/06/2011”

      Dim dt As DateTime = DateTime.Parse(strOriginal)

19. Convert String to Base64 – You will have to use the methods in System.Text.Encoding to convert string to Base64. The conversion involves two processes:

a.    Convert string to a byte array

b.    Use the Convert.ToBase64String() method to convert the byte array to a Base64 string

      Dim byt As Byte() = System.Text.Encoding.UTF8.GetBytes(strOriginal)

      ‘ convert the byte array to a Base64 string

      strModified = Convert.ToBase64String(byt)

20. Convert Base64 string to Original String – In the previous example, we converted a string ‘strOriginal’ to Base64 string ‘strModified’. In order to convert a Base64 string back to the original string, use FromBase64String(). The conversion involves two processes:

a.   The FromBase64String() converts the string to a byte array

b.   Use the relevant Encoding method to convert the byte array to a string, in our case UTF8.GetString();

      Dim b As Byte() = Convert.FromBase64String(strModified)

      strOriginal = System.Text.Encoding.UTF8.GetString(b)

21. How to Copy a String – A simple way to copy a string to another is to use the String.Copy(). It works similar to assigning a string to another using the ‘=’ operator.

      strModified = String.Copy(strOriginal)

 
22. Trimming a String – The String.Trim() provides two overloads to remove leading and trailing spaces as well as to remove any unwanted character. Here’s a sample demonstrating the two overloads. Apart from trimming the string, it also removes the “#” character.

      strOriginal = ” Some new string we test ##”

      strModified = strOriginal.Trim().Trim(Char.Parse(“#”))

 

23. Padding a String – The String.PadLeft() or PadRight() pads the string with a character for a given length. The following sample pads the string on the left with 3 *(stars). If nothing is specified, it adds spaces.

      strModified = strOriginal.PadLeft(34,”*”c)

 

24. Create a Delimited String – To create a delimited string out of a string array, use the String.Join()

      Dim strArr As String() = New String(2) { “str1”, “str2”, “str3”}

      Dim strModified As String = String.Join(“;”, strArr)

 

25. Convert String To Integer – In order to convert string to integer, use the Int32.Parse(). The Parse method converts the string representation of a number to its 32-bit signed integer equivalent. If the string contains non-numeric values, it throws an error.

Similarly, you can also convert string to other types using Boolean.Parse(), Double.Parse(), char.Parse() and so on.

      strOriginal = “12345”

      Dim temp As Integer = Int32.Parse(strOriginal)

 

26. Search a String – You can use IndexOf,LastIndexOf, StartsWith, and EndsWithto search a string.

27. Concatenate multiple Strings – To concatenate string variables, you can use the ‘+’ or ‘+=’ operators. You can also use the String.Concat() or String.Format().

      strModified = strOriginal & “12345”

      strModified = String.Concat(strOriginal, “abcd”)

      strModified = String.Format(“{0}{1}”, strOriginal, “xyz”)

However, when performance is important, you should always use the StringBuilder class to concatenate strings.

28. Format a String – The String.Format() enables the string’s content to be determined dynamically at runtime. It accepts placeholders in braces {} whose content is replaced dynamically at runtime as shown below:

      strModified = String.Format(“{0} – is the original string”,strOriginal)

The String.Format() contains 5 overloads which can be studied over here

29. Determine If String Contains Numeric value – To determine if a String contains numeric value, use the Int32.TryParse() method. If the operation is successful, true is returned, else the operation returns a false.

      Dim i As Integer = 0

      strOriginal = “234abc”

      Dim b As Boolean = Int32.TryParse(strOriginal, i)

Note: TryParse also returns false if the numeric value is too large for the type that’s receiving the result.

30. Determine if a String instance starts with a specific string – Use the StartsWith() to determine whether the beginning of a string matches some specified string. The method contains 3 overloads which also contains options to ignore case while checking the string.

      If strOriginal.StartsWith(“THese”,StringComparison.CurrentCultureIgnoreCase) Then

            Response.Write(“true”)

      End If

Since this article contained only a short introduction of each method,
I would suggest you to explore each method in detail using the MSDN documentation. Mastering string operations can save
us a lot of time in projects and improve application performance too.

JAVASCRIPT: POP – UP WINDOWS

The big craze all over Cyberspace is the pop-up window. Here’s EXACTLY how to do all kinds…

It doesn’t get much easier than this:

Paste into HEAD

Then in the body:

<A HREF=”javascript:my_win()”>Click Here</A>

Change the URL for the page you want to open in the pop-up window, and specify whatever height and width you’d like. Works great for linking thumbnails to larger pictures, as your visitors won’t have to travel from one page to the other to view them both.

Now we get more complex. Here’s the script for an entry pop-up that works only one time… when they enter.

Entry Code Pop-Up

Insert this part of the code into the very top of your web site, between the
two head tags. It should be below <head> and above the </head> tag.
Just copy and paste into the HTML.

var expDays = 1; // number of days the cookie should last

var page = “only-popup-once.html”;
var windowprops =
“width=300,height=200,location=no,toolbar=no,menubar=no,
scrollbars=no,resizable=yes”;

function GetCookie (name) {
var arg = name + “=”;
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + “=” + escape (value) +
((expires == null) ? “” :
(“; expires=” + expires.toGMTString())) +
((path == null) ? “” : (“; path=” + path)) +
((domain == null) ? “” : (“; domain=” + domain)) +
((secure == true) ? “; secure” : “”);
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() – 1);
var cval = GetCookie (name);
document.cookie = name + “=” + cval + “;
expires=” + exp.toGMTString();
}
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt(){
var count = GetCookie(‘count’)
if(count == null) {
SetCookie(‘count’,’1′)
return 1
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie(‘count’)
SetCookie(‘count’,newcount,exp)
return count
}
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (“;”, offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
var count = GetCookie(‘count’);
if (count == null) {
count=1;
SetCookie(‘count’, count, exp);

window.open(page, “”, windowprops);

}
else {
count++;
SetCookie(‘count’, count, exp);
}
}
// End –>


Insert the below code into the main part of the web site. Just insert it anywhere
below the </head> tag.

<BODY OnLoad=”checkCount()”>

Now how about an EXIT pop-up?

Here’s the code:

Exit Code Pop-Up

Insert this part of the code between the two head tags.
It should be below the <head> tag and above the </head> tag:


var exit=true;
function leave() {
if (exit)
window.open(‘http://www.website.com/popup.html&#8217;,”,
‘toolbar=no,menubar=no,scrollbars=yes,resizable=yes,
location=no,height=400,width=400’);
}
// End –>


Insert this anywhere in the web site below the </head> tag:

<BODY onUnload=”leave()”>


When You use a pop-up on exit code, you should also specify which
links won’t cause the popup to appear. For example, you won’t want
a link to your order form to pull up a pop-up box. Insert the below code
into links you don’t want to bring the pop-up.

onclick=”exit=false”

This would make a link look like this in HTML:

<a href=”http://www.biznetstation.com&#8221; onclick=”exit=false”>This link won’t popup</p>

Finally A TIMED POPUP

<!– This goes in your body tag –>
<body onLoad=”setTimeout(window.close, 3000)”>
<!– Change the number, 3000 = 3 seconds –>

THIS SETS A TIMER FOR THE POPUP WINDOW

Button link: <form><input TYPE=”button” VALUE=”Close Window”
onClick=”window.close()”></form>
<BR>
Text link: <a href=”javascript:window.close()”><B>
CLOSE WINDOW</B></a>
<BR>
Image link: <a href=”javascript:window.close()”>
<IMG SRC=”closeme.gif”

BORDER=0 ALT=”CLOSE ME”></a>

THESE ARE BUTTON LINKS (3 TYPES) FOR CLOSING THE WINDOW

<A HREF=”javascript:void(0)”
ONCLICK=”open(‘sample2.htm’,’miniwin’,’toolbar=0,location=0,
directories=0,status=0,

menubar=0,scrollbars=0,resizable=0,width=300,height=300′)”>
Open A Window</A>

HERE’S A POPUP WITH ALL FEATURES TURNED OFF

A List of Window Features ( 0=off , 1=on )
» TEST all values set to 1 (on)
» TEST toolbar=0 (back, reload, home, etc.)
» TEST location=0 (url input field)
» TEST directories=0 (favorites)
» TEST status=0 (at bottom of page)
» TEST menubar=0 (file, edit, view, etc.)
» TEST scrollbars=0 (can the person scroll?)
» TEST resizable=0 (can the window be stretched)
» TEST width=600 (width of window in pixels)
» TEST height=400 (height of window in pixels)
» TEST all values set to 0 (off)

<A HREF=”javascript:void(0)”
ONCLICK=”open(‘sample.htm’,’miniwin’,’toolbar=1,
location=1,directories=1,
status=1,menubar=1,
scrollbars=1,resizable=1,
width=300,height=300′)”>
Open a Window</A>

WINDOW ATTRIBUTES

Lastly I want to leave you with the window.open attributes.
Also a warning. Be careful how you use popups. And where you use them.

The supported features are:

alwaysLowered=[yes|no|1|0] (Navigator 4.0 only)
Specifies whether to create a new window that floats below other windows, whether it is active or not. This is a secure feature and must be set in signed scripts.


alwaysRaised=[yes|no|1|0] (Navigator 4.0 only)
Specifies whether to create a new window that floats on top of other windows, whether it is active or not. This is a secure feature and must be set in signed scripts.


channelmode=[yes|no|1|0] (Internet Explorer 4.0 only)
Specifies whether to display the window in theater mode and show the channel band.


dependent=[yes|no|1|0] (Navigator 4.0 only)
Specifies whether to create a new window as a child of the current window. A dependent window closes when its parent window closes. On Windows platforms, a dependent window does not show on the task bar. It also has a narrow title bar, and a smaller “x” button to close the dependent window.


directories=[yes|no|1|0]
Specifies whether to create the standard browser directory buttons. In some browsers the directory buttons can be customized by the user.


fullscreen=[yes|no|1|0] (Internet Explorer 4.0 only)
Specifies whether to display the browser in a full-screen or normal window. Use Alt+F4 to close the window.


height=number
Specifies the height of the window in pixels. The minimum value should be 100.
hotkeys=[yes|no|1|0] (Navigator 4.0 only)


Specifies whether to enable most hotkeys in a new window that has no menu bar. The security and quit hotkeys remain enabled in any case.


innerHeight=number (Navigator 4.0 only)
Specifies the height, in pixels, of the window’s content area. A signed script is required to create a window smaller than 100 x 100 pixels. This feature replaces height, which remains for backwards compatibility.


innerWidth=number (Navigator 4.0 only)
Specifies the width, in pixels, of the window’s content area. A signed script is required to create a window smaller than 100 x 100 pixels. This feature replaces width, which remains for backwards compatibility.


location=[yes|no|1|0]
Specifies whether to display the Location field, the input field for entering URLs directly into the browser.


menubar=[yes|no|1|0]
Specifies whether to create the menu at the top of the window. In Internet Explorer, this feature is yes by default. A menu normally consists of a “File” option, an “Edit” option, and other browser-specific options.


outerHeight=number (Navigator 4.0 only)
Specifies the vertical dimension, in pixels, of the outside boundary of the window. A signed script is required to create a window smaller than 100 x 100 pixels.


outerWidth=number (Navigator 4.0 only)
Specifies the horizontal dimension, in pixels, of the outside boundary of the window. A signed script is required to create a window smaller than 100 x 100 pixels.


resizable=[yes|no|1|0]
Specifies whether to display resize handles at the corners of the window, which enable the user to resize the window. If this feature is not turned on explicitly, the user cannot resize the new window.


screenX=number (Navigator 4.0) left=number (Internet Explorer 4.0)
Specifies the distance the new window is placed from the left side of the screen. In Navigator, to place a window offscreen, set this feature in a signed scripts.


screenY=number (Navigator 4.0) top=number (Internet Explorer 4.0)
Specifies the distance the new window is placed from the top of the screen. In Navigator, to place a window offscreen, set this feature in a signed scripts.


scrollbars=[yes|no|1|0]
Specifies whether to display horizontal and vertical scroll bars, when the content exceeds the dimensions of the window. This feature is yes by default.


status=[yes|no|1|0]
Specifies whether to create a status bar at the bottom of the window. In Internet Explorer, this feature is yes by default.


titlebar=[yes|no|1|0] (Navigator 4.0 only)
Specifies whether to create a window with a title bar at the top. This feature is yes by default, but can be set to no in a signed script.


toolbar=[yes|no|1|0]
Specifies whether to display the browser toolbar, with buttons such as Back and Forward.


z-lock=[yes|no|1|0] (Navigator 4.0 only)
Specifies whether to create a new window that does not rise above other windows when activated. This is a secure feature and must be set in signed scripts.


width=number
Specifies the width of the window in pixels. The minimum value should be 100.

Many of these features can be either yes or no, 1 or 0. Alternatively, if you want to turn a feature on, you can simply specify the feature name in the comma-separated list.

How the alwaysLowered, alwaysRaised, and z-lock features behave depends on the windowing hierarchy of the platform. For example, on Windows, an alwaysLowered or z-locked browser window is below all windows in all open applications. On Macintosh, an alwaysLowered browser window is below all browser windows, but not necessarily below windows in other open applications. Similarly for an alwaysRaised window.

For compatibility reasons, you should always specify each feature explicitly. 

JAVASCRIPT: Welcome your users

So are we having fun yet?

Here’s a few more…

This one adds an alert box when the visitor comes to your homepage.

<html>

<head>
<title>Simple Alert Box</title>



{alert(“Do you know what Bravenet stands for? BRAVENET = Brad and Dave on the Net! :)”)
}
// –End Hiding Here –>

</head>

<!– This part of the script goes INSIDE your FIRST BODY TAG –>
<body onLoad=”loadalert()”>
<!– END ALERT BOX SCRIPT –>

</body>
</html>

Simple-simon stuff, huh? Bet you never thought it could be so easy…

Now let’s take it one step further. Let’s have a conversation with the new visitor and then write his name in a personalized message write on the web page he’s visiting.

In the <head>

And in the <body>


Hello, ” + name + ” ! Have you ever tried to install a cool script into your web page?

“);
//——->