Web Development 1 2
Web Development 1 2
Web Development 1 2
Concepts:
Server-side scripting: A type of scripting technology where scripts are executed
on the server before the web page is sent to the user.
Dynamic web page: A web page that can change its content depending on the
user's input or other variables.
What is ASP.NET?
Concepts:
→ CLR: Common Language Runtime is the virtual machine component of the .NET
Framework that manages the execution of code written in different languages.
→ C#: C# is an object-oriented programming language derived from C and C++ that
was developed by Microsoft.
→ .NET Core: .NET Core is a cross-platform, open-source, and modular .NET platform
for creating modern web apps, microservices, libraries, and console applications.
→ Dynamic Websites: Websites with content that is generated in response to user
actions.
Concepts:
→ Integrated Development Environment (IDE): A software application that provides
comprehensive facilities to computer programmers for software development.
→ Development Tools: Software programs used to create, debug, maintain, and
document the source code of applications, websites, and other software.
→ Programming Languages: A set of instructions that can be used to produce different
types of output or to control the operation of a computer or other device.
→ Visual Studio is the most popular IDE for developing in .NET
→ The first version of Visual Studio was released in 1997
→ Visual Studio Code is a lightweight version of Visual Studio designed for web
development
Check the checkbox for the license terms and privacy policy.
If you’re installing the full version of Visual Studio, click the Next button that
appeared when you agreed to the license terms. You see a screen similar to
Figure 1-2. Make sure you select at least the Microsoft Web Developer Tools
option.
3. In both cases, click the Install button to start the installation process.
4. After a while, you should see a message indicating that Visual Studio has been
installed successfully. The installer may need to reboot your machine during or
after the installation. Once the installer has finished, Visual Studio is ready for
use.
Take a look at Figure 1-9 to learn more about the many tools that come with VS. It
shows the same screen you saw after making your first website in VS, but now the most
important parts of the screen are highlighted. If you know how to use an older version of
Visual Studio, you can skip this section and pick up where you left off with the next Try It
Out exercise later in this chapter.
If you have a previous version of Visual Studio installed, your screen may look different
because Visual Studio 2013 is able to import settings from older versions.
The main menu is at the top of the application, right below the Windows title bar. This
menu bar has things like the File, Edit, and Help menus found in many other Windows
programs. It also has menus that are unique to VS, like the Website and Debug menus.
The menu changes based on the task you're working on, so as you move through the
application, you'll see menu items appear and disappear. You can set up both online
and offline help using the Help Set Help Preference menu. Before you can use offline
help, you have to install it and be connected to the Internet to use online help. On the
far right, you'll see a link that says "Sign in." This lets you sign in with your Microsoft
account and allow VS settings to be shared between machines.
The application's title bar has a small flag icon to the left of the Windows Close,
Minimize, and Maximize buttons. When you click on the flag icon, the notification
window appears. This is where Visual Studio tells you important things. It will show
things like new documentation content, licenses that have expired, product updates,
and more that can be downloaded. The color of the flag icon in the title bar changes
depending on how important the notifications are. You can also get to the Notifications
window from the View menu. If you installed the RTM version of Visual Studio, you may
see a few updates that you can safely install now.
The toolbar area is right below the menu. It can show different toolbars that give you
quick access to VS's most-used features. In Figure 1-9, only two of the toolbars are
turned on, but Visual Studio comes with a lot of other toolbars that you can use for
different tasks. Some toolbars show up automatically when you're working on a task that
needs a certain toolbar, but you can also turn toolbars on and off as you like. To turn on
or off a toolbar, right-click an existing toolbar or the menu bar and choose the toolbar
from the menu that appears.
The Toolbox
The toolbox tab is on the left side of the main screen, near the edge of VS. If you click
on the tab, the Toolbox opens up and shows you what it has. If you click the little pin
icon in the upper-right corner of the Toolbox (or any of the other panels that have this
pin icon), it gets pinned to the IDE so it stays open.
Just like the menu bar and toolbars, the Toolbox automatically updates to show content
that is relevant to the task you are working on. When you edit a standard ASPX page,
the Toolbox shows you all of the controls you can use on that page. You can just drag
an item from the Toolbox and drop it where you want it to show up on your page. In
Chapter 4, a lot more is said about these controls. Note that there is also a pointer icon
in each Toolbox category. But this isn't controlled by itself. In other Visual Studio
designers, like Win Forms, this icon is used to get out of drawing mode. In ASP.NET,
however, it isn't very useful. The Toolbox has several categories that you can expand or
collapse to make it easier to find the tool you need. You can also change the order of
the items in the list, add and remove items from the Toolbox, and even add your own
tools to it. We will talk about customizing the IDE later in this chapter.
If the Toolbox isn't showing up on the screen, you can open it by pressing Ctrl+Alt+X or
by going to View > Toolbox if you have Expert Settings selected in the Tools > Settings
menu.
The Solution Explorer is on the right side of the screen. The Solution Explorer is an
important window because it gives you an overview of all the files that make up your
website. With Solution Explorer, you can store your files in separate folders instead of
putting them all in one big folder. This makes your site's structure more logical and
organized. You can use Solution Explorer to add new files to your site, move existing
files around by dragging and dropping or cutting and pasting, rename files and delete
them from the project, and do other things. A lot of Solution Explorer's features are
hidden in the right-click menu, which changes depending on what you right-click on.
At the top of the Solution Explorer is a small toolbar that gives you quick access to
some functions related to your website. For example, you can quickly refresh the
Solution Explorer window, nest related files, or set up your website by clicking on one of
these buttons. Most of these features will be talked about later in the book.
You can get to the Solution Explorer by choosing View > Solution Explorer from the
main menu or by pressing Ctrl+Alt+L.
This window lets you work with your databases and other services. In Figure 1-9, it is
hidden behind the Solution Explorer.
You can get to the Server Explorer by choosing View > Server Explorer or by pressing
Ctrl+Alt+S.
The chapters about databases go into more depth about the Server Explorer.
This window, hidden behind the Solution Explorer in Figure 1-9, is used to connect to
and work with Microsoft's Application Lifecycle Management tool Team Foundation
Server (TFS), which is used for source control, tracking work items, and more. Check
out http://tfs.visualstudio.com for more information and to sign up for a free hosted
account for TFS. Team Explorer and TFS are not talked about in this book.
With the Properties Grid, you can see and change the properties of many things in
Visual Studio, such as files in the Solution Explorer, controls on a web page, the
properties of the page itself, and much more. The window is always updated to show
the item that was chosen. By pressing F4, you can quickly open the Properties Grid.
You can use this same keyboard shortcut to force the Properties Grid to show the
details of a selected item.
The Document Window dominates the application. The action is mostly here. The
Document Window lets you edit ASPX, HTML, CSS, JavaScript, VB, C#, XML, text, and
picture files. The same window lets you manage databases, generate duplicates of your
site, examine its pages in the built-in mini-browser, and more.
By default, the Document Window can host many documents, each with a tab
containing the filename at the top. Each tab's right-click menu has shortcuts for saving,
closing, and opening File Explorer's parent folder.
To switch documents, use Ctrl+Tab, click the tab, or click the down arrow in the upper-
right corner of the Document Window, adjacent to the Solution Explorer (Figure 1-9).
The down arrow displays a list of open documents for easy selection.
Ctrl+Tab + Ctrl is another technique to swap documents. The right-hand column of the
pop-up window lets you choose a document. Use the cursor keys to scroll through the
open document list. This simplifies file selection.
The dialog box lists all active tool windows. Clicking a window in the list displays it on-
screen, moving it if necessary.
Click a file in Solution Explorer to preview it without modifying it. A file in preview mode
has its tab docked to the right of the tab row, unlike open files, which are docked to the
left.
Figure 1-9 shows Design, Split, and Source buttons underneath the Document Window.
Markup files like ASPX pages automatically display these buttons. They let you view a
page's Design View, Markup View, or both at once. For now, know that you can move
between Markup, Split, and Design View by clicking one of the three buttons. Chapter 2
explains how this works. Markup View is often called Source View or Code View. This
book utilizes Markup View exclusively to avoid confusion with the Code Behind code
editor.
The Document Window loads the Start Page when VS starts. Start iPage lets you easily
develop and open websites and other projects. The Start Page links to web
development news and resources. Click the pin symbol to the left of your favorite
projects in the recent projects list to pin them to the Start Page. Right-click a project to
unpin it. View O Start Page reopens the Start Page.
The preceding chapter gave you a quick overview of creating a website in VS. You
simply chose New Web Site from the File menu, selected a language, selected the
standard ASP.NET Web Forms Site template, and clicked OK. However, there’s more
to the New Web Site dialog box than you saw in the previous chapter. You may have
noticed that you can choose among a number of different templates that enable you to
create different kinds of sites. But before looking at the different templates on which you
can base your new website, you need to know a little more about the different project
types that are available in Visual Studio.
Each framework targets a unique development methodology. The one you choose
depends on a combination of your programming assets (knowledge, abilities, and
development experience), the type of application you're producing, and the
development style you're comfortable with.
Web Forms
With ASP.NET Web Forms, you can use a familiar drag-and-drop, event-driven model
to build dynamic websites. With a design surface and hundreds of controls and
components, you can quickly make sophisticated, powerful sites with data access that
are driven by the user interface.
MVC
ASP.NET MVC gives you a powerful, pattern-based way to build dynamic websites that
makes it easy to separate concerns and gives you full control over markup for fun, agile
development. ASP.NET MVC has many features that make it easy to create
sophisticated applications that use the latest web standards quickly and with TDD.
ASP.NET Web Pages and the Razor syntax make it easy to combine server code and
HTML to make dynamic web content in a way that is quick and light. You can link to
social networking sites, add video, connect to databases, and do a lot more to make
beautiful sites that meet the latest web standards.
Web APIs
ASP.NET Web API is a framework that makes it easy to build HTTP services that can
be used by a wide range of clients, such as browsers and mobile devices. On the.NET
Framework, ASP.NET Web API is the best way to build RESTful applications.
All three ASP.NET frameworks are built on the.NET Framework and have many of the
same core features of both.NET and ASP.NET. For example, all three frameworks offer
a login security model based on membership, and they all share the same core
ASP.NET facilities for managing requests, handling sessions, and so on.
Also, the three frameworks are not completely separate, and using one does not mean
you can't use the others. Since different frameworks can be used in the same web
application, it's not unusual for different frameworks to be used to make different parts
of an application. For example, the parts of an app that the customer sees might be built
with MVC to improve the markup, while the parts that deal with data access and
administration might be built with Web Forms to make use of data controls and easy
data access.
In Visual Studio, there are many ways to start a new project. When you open Visual
Studio for the first time, you see the start window. From there, you can choose Create a
new project.
If Visual Studio's development environment is already open,
choose File > New > Project from the menu bar to start a new project. You can also
press Ctrl+Shift+N.
Tip
If you don't see the template you're looking for, you might be missing a workload for
Visual Studio. To install additional workloads, for example, Azure Development or
Mobile Development with .NET, select the Install more tools and features link to open
Visual Studio Installer. From there, select the workloads you want to install, and then
select Modify. After that, additional project templates will be available to choose from.