FeedAgg.com Logo
Your Account | Sign In | Sign Up

Add Feed | Search | Home | Help | Contact | Blog

Feed: ASP.NET - AggScore: 50.0



Summary: ASP.NET


Tutorials, Examples with code, very useful for beginers and advanced users

Building a Code Sample Website



Overview of the Sample Website
The primary purpose of the website is to act as a code sample website for .NET code. Anyone who visits the website can post a new code sample entry. A code sample entry can consist of one or more code sample files. The author of the code sample entry can provide a description of each of the files. Furthermore, the author can add one or more tags to the code samples to categorize and describe their purpose. Visitors to the website can browse the existing code sample entries. They can rate code samples when they view them. Furthermore, they can copy the code samples so they can use the samples in their own applications.

The website also includes a simple blog. The administrator of the website can post blog entries about the code samples or about any other topic. Visitors to the website can add comments to a blog entry. The website exposes both an ATOM and RSS feed. If someone wants to subscribe to the blog, that person can subscribe to either the ATOM or RSS feed. The home page of the website displays a code cloud and a list of recent blog entries (see Figure 1). The code cloud consists of a distinct list of all the code entry tags. The more code entries that share a tag, the larger the tag appears in the code cloud. In the figure, you’ll notice that a lot of code samples are related to validation. If you click a tag in the code cloud, you are transferred to a page that contains a list of code samples associated with the tag.

Figure 1:

Read more »
Date Published: Jan 27, 2011 - 1:44 am



Using Client-Side ASP.NET AJAX


Making JavaScript Look Like C#
Let me start by saying that there is nothing wrong with JavaScript the language. It is not a toy language. It is not a limited language. JavaScript simply has it roots in a different programming language family than other languages you are familiar with, such as C# and VB.NET. For a great, quick introduction to JavaScript the language, I recommend that you read “A re-introduction to JavaScript” at http://developer.mozilla.org/en/docs/A_re-introduction_to_JavaScript. JavaScript is an object-oriented programming language. In fact, one could argue that it is more object-oriented than languages such as C# and VB.NET. In a language such as C#, you make a distinction between classes (Aristotelian forms) and objects (Aristotelian matter). An object is an instance of a class, but a class does not exist in its own right. In JavaScript, classes do not exist. The only thing that exists are objects (everything is matter). Objects are not related to one another by being instances of the same class. Instead, one object can be related to another object when one object is the prototype for another object. Another major difference between JavaScript and C# is that JavaScript is a dynamic language. The type of a variable can change at any moment during runtime. When JavaScript code is executed, a String might transform into an Integer and back again. The C# language, on the other hand, is statically typed. Once declared, a String is a String and it can never be anything else.

Using the Microsoft AJAX Library
The supporting code for the client-side Microsoft AJAX Framework is contained in a single JavaScript file named MicrosoftAjax.js. This file is included in a page automatically when you add an ASP.NET ScriptManager control to a page. If you add an AJAX Web Form to a website within Visual Web Developer, the page contains the ScriptManager control automatically.

Creating an AJAX Client Library
Before we do anything else, we need to discuss how you create an external JavaScript file and reference it in an AJAX Web Form page. You create a JavaScript file by selecting the menu option Website, Add New Item and selecting the AJAX Client Library  For example, the file in Listing contains a single JavaScript function called sayMessage() that displays a JavaScript alert with a message.

Read more »
Date Published: Jan 27, 2011 - 1:43 am





Ajax


Ajax, shorthand for Asynchronous Javascript and XML, is a set of technologies that allows you to create Web applications that don't need to refresh Web pages in the browser. You can operate behind the scenes, connecting to the server, uploading and downloading data, and display the results in the browser using dynamic HTML. Using Ajax gives your Web pages the feel of a desktop application-the whole display will no longer flash when you click a button. VTC Author Steve Holzner helps you get started developing and building your own Ajax capable web pages. A familiarity with JavaScript, XML, PHP is recommended for this course. To begin learning, simply click the links.

Read more »
Date Published: Jan 21, 2011 - 3:03 am


Using the ASP.NET AJAX Control Toolkit



The ASP.NET AJAX Control Toolkit is not included with the ASP.NET 3.5 Framework. The Toolkit is being continuously updated. A new release of the Toolkit is available every couple months. The Toolkit is maintained as a project at Microsoft CodePlex. You can download the latest release of the ASP.NET AJAX Control Toolkit at the following location:

When you download the Toolkit, you have the choice of either
(1) downloading the controls and the source code or
(2) downloading the controls only. You’ll need to unzip the download onto your hard drive.

As part of the download, you get a sample website that demonstrates each of the Toolkit controls. You can open the sample website by launching Visual Web Developer, selecting the menu option File, Open Website, and browsing to the SampleWebSite folder in the unzipped download.

Read more »
Date Published: Jan 21, 2011 - 2:29 am


Using Server-Side ASP.NET AJAX



The Ajax Vision
ASP.NET is a server-side technology for building web applications. Almost all the work happens on the web server and not the web browser. Whenever you perform an action in an ASP.NET page—such as clicking a button or sorting a GridView—the entire page must be posted back to the web server. Any significant action on a page results in a postback. If you think about it, this is incredibly inefficient. When you perform a postback in an ASP.NET page, the entire page must be transported across the Internet from browser to server. Next, the .NET class that corresponds to the page must re-render the entire page again from scratch. Finally, the finished page must be sent back across the Internet to the browser. This whole long, slow, agonizing process must occur even if you are updating a tiny section of the page.
Using a server-side technology such as ASP.NET results in a bad user experience. Every time a user performs some action on a page, the universe temporarily freezes. Whenever you perform a postback, the browser locks, the page jumps, and the user must wait patiently twiddling his thumbs while the page gets reconstructed. All of us have grown accustomed to this awful user experience. However, we would never design our desktop applications in the same way.

Google Docs (http://docs.google.com) demonstrates that you can build Microsoft Office better than Office by building it as a web application. Google Docs enables you to save your documents, spreadsheets, and presentations on a central server so that they don’t get lost and can be accessed anywhere. Furthermore, Google Docs enables people to collaborate on documents and spreadsheets over the Internet, which is something that you just cannot do in Microsoft Office. Google Suggest (http://www.google.com/webhp?complete=1&hl=en) was the Google application that convinced me that the future is Ajax. Google Suggest works like the normal Google home page, except for the fact that the Google Suggest page offers suggestions as you type. While you are typing, Google Suggest looks up matching words from its database and shows them to you in real time (before seeing Google Suggest, I would have thought this violated the laws of physics).

Read more »
Date Published: Jan 21, 2011 - 2:28 am


Building Templated Databound Controls


Creating Templated Controls
A template enables you to customize the layout of a control. Furthermore, a template can contain expressions that are not evaluated until runtime. The ASP.NET Framework supports two types of templates. First, you can create a one-way databinding template. You use a one-way databinding template to display data items. In a one-way databinding template, you use the Eval() expression to display the value of a data item.

Second, you have the option of creating a two-way databinding template. A two-way databinding template can be used not only to display data items, but also to update data items. You can use the Bind() expression in a two-way databinding template to both display a data item and extract the value of a data item. Typically, you use templates with a databound control. For example, the ListView, GridView, Repeater, DataList, FormView, and DetailsView controls all support an ItemTemplate that enables you to format the data items that these controls display.

Implementing the ITemplate Interface
You create a one-way databinding template by adding a property to a control that returns an object that implements the ITemplate interface. The ITemplate interface includes one method:
InstantiateIn—Instantiates the contents of a template in a particular control.
Read more »
Date Published: Jan 21, 2011 - 2:26 am


Building Custom Control



You must answer two questions before writing a custom control:
What type of control do I want to write?
From what class do I inherit?

The two basic types of controls are fully rendered and composite controls. When you build a fully rendered control, you start from scratch. You specify all the HTML content that the control renders to the browser. When you create a composite control, on the other hand, you build a new control from existing controls. For example, you can create a composite AddressForm control from existing TextBox and RequiredFieldValidator controls. When you create a composite control, you bundle together existing controls as a new control. The second question that you must address is the choice of the base control for your new control. You can inherit a new control from any existing ASP.NET control. For example, if you want to create a better GridView control, then you can inherit a new control from the GridView control and add additional properties and methods to your custom GridView control.

Typically, when building a basic control, you inherit your new control from one of the following base classes:
. System.Web.UI.Control
. System.Web.UI.WebControls.WebControl
. System.Web.UI.WebControls.CompositeControl

Read more »
Date Published: Jan 21, 2011 - 2:24 am


Configuring Applications



ASP.NET uses a hierarchical system of configuration. At the top of the hierarchy is the Machine.config file. This file contains all the default configuration settings for ASP.NET applications and all other types of applications built with the .NET Framework.

The Machine.config file is located at the following path:
C:WINDOWSMicrosoft.NETFrameworkv2.0.50727CONFIGMachine.config

This same folder also contains a Web.config file. The Web.config file contains settings specific to ASP.NET applications. The Web.config file overrides particular settings in the Machine.config file.

The CONFIG folder includes the following six files:
Machine.config—Contains the actual configuration settings.
Machine.config.default—Contains the default values for all configuration settings.
Machine.config.comments—Contains comments on each configuration setting.
Web.config—Contains the actual configuration settings.
Web.config.default—Contains the default values for all configuration settings.
Web.config.comments—Contains comments on each configuration setting.

Only the Machine.config and Web.config files are actually used. The other files are there for the purpose of documentation. You can place a Web.config file in the root folder of a website, such as the wwwroot
folder. A Web.config file located in the root folder of a website contains settings that apply to all applications contained in the website. You also can place a Web.config file in the root of a particular application. In that case, the Web.config file has application scope. Finally, you can place a Web.config file in an application subfolder. In that case, the Web.config file applies to all pages in that folder and below.

Read more »
Date Published: Jan 21, 2011 - 2:23 am


Working with the HTTP Runtime



Creating a Custom BuildProvider
When you write an ASP.NET page and save the page to your computer’s file system, the ASP.NET page gets compiled dynamically into a .NET class in the background. The page is compiled dynamically by a BuildProvider. The ASP.NET Framework includes a number of BuildProviders. Each BuildProvider is responsible for compiling a file with a particular extension that is located in a particular type of folder. For example, there are BuildProviders for Themes, Master Pages, User Controls, and Web Services. When a BuildProvider builds, it builds a new class in the Temporary ASP.NET Files folder. Any class added to the folder becomes available to your application automatically. When you use Visual Web Developer, any public properties and methods of the class appear in Intellisense.

You can create your own BuildProviders. This can be useful in a variety of different scenarios. For example, imagine that you find yourself building a lot of ASP.NET pages that display forms. You can tediously build each ASP.NET page by hand by adding all the necessary form and validation controls. Alternatively, you can create a new BuildProvider that takes an XML file and generates the form pages for you automatically.

Read more »
Date Published: Jan 21, 2011 - 2:22 am


Localizing Applications for Multiple Languages



One can localize an ASP.NET website so that it supports multiple languages and cultures. For example, you might need to create both an English language and Spanish language version of the same website.
One approach to localization is to simply create multiple copies of the same website and translate each copy into a different language. This is a common approach when building ASP Classic (or even ASP.NET 1.1) websites. The problem with this approach is it creates a website maintenance nightmare. Whenever you need to make a change to the website—no matter how simple—you must make the change in each copy of the website. When building ASP.NET applications, you do not need to create multiple copies of a website to support multiple languages. Instead, you can take advantage of resource files. A resource file contains language-specific content. For example, one resource file might contain a Spanish version of all the text in your website, and a second resource file might contain the Indonesian version of all the text in your website.

Setting the Current Culture
Two main properties of the Page class have an effect on localization:
UICulture
Culture
Read more »
Date Published: Jan 21, 2011 - 2:20 am


Caching Application Pages and Data



The ASP.NET 3.5 Framework supports the following types of caching:
. Page Output Caching
. Partial Page Caching
. DataSource Caching
. Data Caching

Using Page Output Caching
You enable Page Output Caching by adding an directive to a page. For example, the page in Listing caches its contents for 15 seconds.

LISTING CachePageOutput.aspx
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
void Page_Load()
{
lblTime.Text = DateTime.Now.ToString(“T”);
}

The page in Listing displays the current server time in a Label control. The page also includes an directive. If you refresh the page multiple times, you will notice that the time is not updated until at least 15 seconds have passed. When you cache a page, the contents of the page are not regenerated each time you request the page.
Read more »
Date Published: Jan 21, 2011 - 2:18 am


Building ASP.NET Applications


Developers who are new to programming for the web always have difficulty understanding the problem of maintaining state. The HTTP protocol, the fundamental protocol of the World Wide Web, is a stateless protocol. What this means is that from a web server’s perspective, every request is from a new user. The HTTP protocol does not provide you with any method of determining whether any two requests are made by the same person.

However, maintaining state is important in just about any web application. The paradigmatic example is a shopping cart. If you want to associate a shopping cart with a user over multiple page requests, then you need some method of maintaining state. This chapter looks at three methods included in the ASP.NET 3.5 Framework for associating data with a particular user over multiple page requests. In the first section, you learn how to create and manipulate browser cookies. A browser cookie enables you to associate a little bit of text with each website user.

Using Browser Cookies
Cookies were introduced into the world with the first version of the Netscape browser. The developers at Netscape invented cookies to solve a problem that plagued the Internet at the time. There was no way to make money because there was no way to create a shopping cart.

Read more »
Date Published: Jan 21, 2011 - 2:15 am


Using ASP.NET Membership


In the previous chapter, you learned how to use the Login controls to create an entire user registration system. This chapter looks under the covers and examines the security frameworks on which the Login controls are built. The ASP.NET Framework includes four frameworks related to security:
  • ASP.NET Authentication—Enables you to identify users.
  • ASP.NET Authorization—Enables you to authorize users to request particular resources.
  • ASP.NET Membership—Enables you to represent users and modify their properties.
  • Role Manager—Enables you to represent user roles and modify their properties.

Configuring Authentication
Authentication refers to the process of identifying who you are. The ASP.NET Framework supports three types of authentication:
  • Windows Authentication
  • NET Passport Authentication
  • Forms Authentication

A particular application can have only one type of authentication enabled. You can’t, for example, enable both Windows and Forms authentication at the same time. Windows authentication is enabled by default. When Windows authentication is enabled, users are identified by their Microsoft Windows account names. Roles correspond to Microsoft Windows groups.

Read more »
Date Published: Jan 05, 2011 - 6:56 am


Using the Login Controls


You can use the ASP.NET Login controls to easily build a user registration system for your website. You can use the Login controls to display user registration forms, login forms, change password forms, and password reminder forms. By default, the Login controls use ASP.NET Membership to authenticate  Users, create new users, and change user properties. When you use the Login controls, you are not required to write any code when performing these tasks. ASP.NET Membership is discussed in detail in the following chapter. In the first part of this chapter, you are provided with an overview of the Login controls. You learn how to passwordprotect a section of your website and enable users to register and log in to your website. In the remainder of this chapter, you learn how to use each of the following Login controls in detail:
  • Login—Enables you to display a user login form.
  • CreateUserWizard—Enables you to display a user registration form.
  • LoginStatus—Enables you to display either a log in or log out link, depending on a user’s authentication status.
  • LoginName—Enables you to display the current user’s registered username.
  • ChangePassword—Enables you to display a form that allows users to change their passwords.
  • PasswordRecovery—Enables you to display a form that allows a user to receive an email containing his or her password.
  • LoginView—Enables you to display different content to different users depending on the user’s authentication status or role.
Read more »
Date Published: Jan 05, 2011 - 6:56 am


Advanced Navigation


Websites tend to be organic—they grow and change over time. This can create problems when other applications link to your application. You need some way of modifying your website without breaking all the existing links to it.

Remapping URLs
The simplest way to remap a URL is to specify the remapping in your application’s web configuration file.

url=”~/Home.aspx”
mappedUrl=”~/Default.aspx”/>

The mappedUrl attribute can contain query strings. However, it cannot contain wildcards. You can use the element only when performing simple page-topage mappings. After you add the web configuration file to your application, any requests for the Home.aspx page are modified automatically to requests for the Default.aspx page. It doesn’t matter whether the Home.aspx page actually exists. If the Home.aspx page does exist, you can never open the page.

Read more »
Date Published: Jan 05, 2011 - 6:52 am


 
Visitor Rating: 5 (1) (Rate)

Story Clicks: 0

Feed Views: 37

Lenses (Add|?)

Comments (Log in to add)

Feed Details
Date Added: 01/21/2011
Date Approved: 01/21/2011
By:
Search FeedAgg.com




3600 mp9105 serv 1.1346 seconds to generate.