Showing posts with label Server Control. Show all posts
Showing posts with label Server Control. Show all posts

Thursday, December 21, 2006

The Literal Server Contrl of ASP.NET 2.0

The best use for the Literal control is in scenarios where you want to render text and controls directly into a page without any additional markup.

The Literal control contains the Mode property, which is used to specify particular handling of the content of the Text property:

Mode : Description
PassThrough : The Text content is rendered as is.
Encode : The Text content is HTML-encoded.
Transform : The Text content is converted to match the markup languageof the requesting browser, such as HTML, XHTML, WML, or cHTML. If the markup language is HTML or XHTML, the content is passed through to the browser.

Security Alert:
By default, populating the Literal control with data from untrusted sources can create Cross Site Scripting (XSS) vulnerabilities. Set the Mode property to Encode to provide HTML encoding of untrusted data that will be placed into the Text property.

Monday, December 18, 2006

Login in ASP.NET

ASP.NET includes controls and classes to simplify the process of adding login capabilities to your Web application.

The login controls include:

  • Login 用户登录框
    A user interface that prompts for user names and passwords and (Remember me 记住我) enables users to select whether they want to be automatically authenticated the next time they visit.
    You can use the Login control with ASP.NET membership without writing any code, or you can write your own authentication code by adding a handler for the Authenticate event.
  • LoginStatus 用户登录按钮/链接 & 用户退出按钮/链接
    Displays a login link for users who haven’t been authenticated and a logout link for users who are currently logged in.
  • LoginName 当前用户的username
    Displays the current user’s user name, if logged in.
  • LoginView 登录后才可以看到的内容/链接
    Enables you to display different information to users who are logged in.
    For example, you could use this link to go to site features that are available only to authenticated users.
  • PasswordRecovery 找回密码
    Enables password retrieval for a user by sending an e-mail message to the user or by having the user answer a security question.
  • ChangePassword 修改密码
    Enables a user who is logged in to change his or her password.
  • CreateUserWizard 用户注册
    Gathers information from a new user and creates a new account.
  • You can use a ValidationSummary control to display detailed error information provided by some of these controls.

Saturday, December 16, 2006

ASP.NET AJAX Partial-Page Rendering Overview

Introduction

Partial-page rendering removes the need for the whole page to be refreshed as the result of a postback. Instead, only individual regions of the page that have changed are updated. As a result, users do not see the whole page reload with every postback, which makes user interaction with the Web page more seamless. Microsoft ASP.NET 2.0 AJAX Extensions enables you to add partial-page rendering to new or existing ASP.NET Web pages without writing client script.

Scenarios

ASP.NET 2.0 AJAX Extensions enables you to extend existing ASP.NET 2.0 applications and develop new ones that incorporate AJAX (Asynchronous JavaScript and XML) functionality. Use ASP.NET 2.0 AJAX Extensions when you want to do the following:

  • Improve the user experience with Web pages that are richer, that are more responsive to user actions, and that behave like traditional client applications.
  • Reduce full-page refreshes and avoid page flicker.
  • Enable cross-browser compatibility without writing client script.
  • Perform AJAX-style client/server communication without writing client script.
  • Use the controls and components from the ASP.NET AJAX Control Toolkit.
  • Develop custom Microsoft ASP.NET AJAX controls.

Partial-Page Rendering Features

Partial-page rendering relies on server controls in ASP.NET 2.0 AJAX Extensions and on client functions in the Microsoft AJAX Library. You do not have to use the Microsoft AJAX Library to enable partial-page rendering, because this functionality is provided automatically when you use the ASP.NET 2.0 AJAX Extensions server controls.

The primary features of Microsoft ASP.NET AJAX partial-page rendering include the following:

  • A declarative model that works like ASP.NET server controls. In many scenarios, you can specify partial-page rendering using only declarative markup.
  • Server controls that perform the underlying tasks required for partial-page updates. These include the ScriptManager control and the UpdatePanel control.
  • Integration between ASP.NET 2.0 AJAX Extensions server controls and the Microsoft AJAX Library for common tasks. These tasks include enabling users to cancel a postback, displaying custom progress messages during an asynchronous postback, and determining how multiple clicks are processed.
  • Error-handling options for partial-page rendering, which enable you to customize how errors are displayed in the browser.
  • Cross browser compatibility, which is built into the Microsoft AJAX Library. Simply using the server controls automatically invokes the correct browser functionality.

Server Controls for Partial-Page Updates

To add AJAX functionality to ASP.NET Web pages, you identify individual sections of the page that you want to update. You then put the content of these sections into UpdatePanel controls. The contents of an UpdatePanel control can be HTML or other ASP.NET controls. You can add an UpdatePanel control to the page as you would any other control.

By default, postbacks originating from controls inside the update panel (child controls) automatically initiate asynchronous postbacks and cause a partial-page update. You can also specify that controls outside the UpdatePanel cause an asynchronous postback and that they refresh the UpdatePanel control's content. A control that causes an asynchronous postback is referred to as a trigger.

An asynchronous postback behaves much like a synchronous postback. All the server page life-cycle events occur and view state and form data are preserved. However, in the rendering phase, only the contents of theUpdatePanel control are sent to the browser. The rest of the page remains unchanged.

To support partial-page rendering, you must put a ScriptManager control on the page.
The ScriptManager control:

  1. keeps track of all the update panels on the page and their triggers.
  2. coordinates partial-page rendering behavior on the server.
  3. determines which sections of the page to render as a result of an asynchronous postback.

Enabling Partial-Page Rendering Support

You enable or disable partial-page rendering for a page by setting the EnablePartialRendering property of the ScriptManager control.
You can also specify whether partial-page rendering is supported for a page by setting the SupportsPartialRendering property of the ScriptManager control.
If you do not set the SupportsPartialRendering property and if the EnablePartialRendering property is true (which is the default), the capabilities of the browser are used to determine whether partial-rendering is
supported.

If partial-page rendering is not enabled for a page, if it has been disabled, or if it is not supported in a browser, the page uses fallback behavior. Actions that ordinarily would perform an asynchronous postback instead perform a synchronous postback and update the whole page. Any UpdatePanel controls on the page are ignored, and their contents are rendered as if they were not inside an UpdatePanel control.

Tuesday, December 05, 2006

Notes on ASP.NET 2.0 CSS Friendly Control Adapter

A control adapter is an optional class that, if present and properly configured, is used to render the Web control instead of using the control's default rendering logic. In short, using control adapters you can take the core functionality of a Web control, but completely customize the markup emitted.

This set of free control adapters, released by Microsoft, provide a set of control adapters that render a variety of built-in ASP.NET controls using preferred CSS techniques.

Moreover, the CSS control adapters ignore any control-level style settings that would get rendered as inline style elements in the rendered markup and instead require that style information be separated out and specified via CSS classes.

While these could be created from scratch, Microsoft has provided the ASP.NET 2.0 CSS Friendly Control Adapters that can be downloaded and plugged into your ASP.NET web applications with minimal effort. Once installed, the control adapters will no longer render inline style attributes (you need to use CSS classes) and replaces the

layouts of the Menu, TreeView, and other controls with CSS techniques.

The presentation settings for these classes can be specified in the page's style element or, ideally, in a separate CSS file.

Indeed, you can modify any ASP.NET control so it produces exactly the HTML you want.

I think Microsoft will build the CSS features into ASP.NET 3.0 as an essence. We won't use inline style anymore, neither table tags for layout, at least I won't. :-)
Actually, I really do not care about what kind of code is beneith the screen/page, I only require it works well as I and users expected. CSS or inline style, table or div, I don't give a fuck. As we get the better one freely and effortlessly, why not better. ;-) That's it.



Thursday, October 26, 2006

Using CheckBoxList in ASP.NET

e .NET Framework Class Library CheckBoxList Members

Tuesday, October 17, 2006

The Literal control of ASP.NET 2.0

@ Add a Literal Web server control to your page when you want to set text programmatically without adding extra HTML tags. The Literal control is useful as a way to add text into a page dynamically without adding any elements that are not part of the dynamic text. For example, you can use the Literal control to display HTML that you read from a file or from a stream.

@ If you want to display static text, you can present it using HTML; you do not need a Literal control. Use a Literal control only if you need to render text programmatically.

@ You can use a Literal Web server control as a container for other content on the page. The Literal control is used most frequently when adding content dynamically to the page.

Comparing the Literal Control to Other Options
The Literal control represents one of several options for adding content to a page. For static content, you can add markup directly to a page as HTML, without using a container. However, if you want to add content dynamically, you must add the content to a container. Typical containers are the Label control, the Literal control, the Panel control, and the Placeholder control.
The Literal control differs from the Label control in that the Literal control does not add any HTML elements to the text. (The Label control renders a span element.) As a consequence, the Literal control does not support any style attributes, including position attributes. However, the Literal control allows you to specify whether content is encoded.
The Panel and Placeholder controls render as div elements, which create discrete blocks in the page, unlike rendering in-line the way the Label and Literal controls do.
In general, use a Literal control when you want to render text and controls directly into a page without any additional markup.

Tuesday, October 03, 2006

ASP.NET Inline Data-Binding Syntax

@ One-way data binding:

Eval("", "")

第一部分是Item的名称;第二部分是一个Formatter。

@ Two-way data binding:
<%# Bind("Name", "{0:mm dd yyyy}") ) %>
第一部分是Item的名称;第二部分是一个Formatter。