пятница, 21 августа 2009 г.

Как получить .NET объект Color (GDI+) из web-цвета (HTML)

ColorTranslator.FromHtml - метод
Этот метод переводит строковое представление имени цвета HTML, такого как Blue (синий) или Red (красный), в структуру GDI+ Color.

Следующий пример кода предназначен для работы с Windows Forms; для него необходим объект PaintEventArgse, передаваемый в качестве параметра обработчику события Paint. Программа переводит имя цвета HTML в структуру Color, и затем использует этот цвет для заливки прямоугольника.

Язык C#
public void FromHtml_Example(PaintEventArgs e) {     // Create a string representation of an HTML color.     string htmlColor = "#00cc66";      // Translate htmlColor to a GDI+ Color structure.     Color myColor = ColorTranslator.FromHtml(htmlColor);      // Fill a rectangle with myColor.     e.Graphics.FillRectangle( new SolidBrush(myColor), 0, 0,          100, 100); }

Доступ к Session в HttpHandler (.ashx файлы)



Для того что бы получить доступ к Session в HttpHandler необходимо наследовать интерфейс System.Web.SessionState.IRequiresSessionState

<% @ webhandler language="C#" class="DownloadHandler" %>

using System;
using System.Web;
using System.Web.SessionState;

public class DownloadHandler : IHttpHandler, IRequiresSessionState
{
public bool IsReusable { get { return true; } }

public void ProcessRequest(HttpContext ctx)
{
ctx.Response.Write(ctx.Session["fred"]);
}
}

Label.AssociatedControlID - свойство

ASP.NET
<asp:Label AssociatedControlID="String" />

Значение свойства

Тип: System.String
Строковое значение, отвечающее ID для серверного элемента управления, содержащегося в веб-форме. Значением по умолчанию является пустая строка (""), что означает элемент управления Label не связан с другим серверным элементом управления.

Используйте свойство AssociatedControlID для привязки элемента управления Label и с иным серверным элементом управления в веб-форме. Если элемент управления Label связан с другим серверным элементом управления, его атрибуты могут использоваться для расширения возможностей привязанного элемента управления. Можно использовать элемент управления Label в качестве заголовка для иного элемента управления, также можно задать индекс закладки или горячую клавишу для привязанного элемента управления.

Если свойство AssociatedControlID задано, элемента управления Label передается как HTML элемент label с атрибутом for, имеющим значение свойства ID привязанного элемента управления. Атрибуты элемента label можно задать при помощи свойств Label. Например, можно использовать свойства Text и AccessKey для создания заголовка и горячих клавиш для привязанного элемента управления.

Значение для данного свойства нельзя установить с помощью тем или тем таблиц стилей. Дополнительные сведения см. в разделах ThemeableAttribute и Общие сведения о темах и обложках ASP.NET.

четверг, 20 августа 2009 г.

Комментарии в CSS

Очень часто с поисковиков заходят на сайт по запросу “Комментарии в CSS” и попадают на страницу Условные комментарии в CSS, что не совсем соответствует их критерию поиска. Чтобы исправить эту ситуацию и посетители находили то, что ищут, я решил написать о комментариях в CSS.

среда, 19 августа 2009 г.

Unlocking and Approving User Accounts

Along with a username, password, and email, each user account has two status fields that dictate whether the user can log into the site: locked out and approved. A user is automatically locked out if they provide invalid credentials a specified number of times within a specified number of minutes (the default settings lock a user out after 5 invalid login attempts within 10 minutes). The approved status is useful in scenarios where some action must transpire before a new user is able to log on to the site. For example, a user might need to first verify their email address or be approved by an administrator before being able to login.

Because a locked out or unapproved user cannot login, it’s only natural to wonder how these statuses can be reset. ASP.NET does not include any built-in functionality or Web controls for managing users’ locked out and approved statuses, in part because these decisions need to be handled on a site-by-site basis. Some sites might automatically approve all new user accounts (the default behavior). Others have an administrator approve new accounts or do not approve users until they visit a link sent to the email address provided when they signed up. Likewise, some sites may lock out users until an administrator resets their status, while other sites send an email to the locked out user with a URL they can visit to unlock their account.

This tutorial shows how to build a web page for administrators to manage users’ locked out and approved statuses. We will also see how to approve new users only after they have verified their email address.

Using autocomplete in HTML

Attribute for
AUTOCOMPLETE = ON | OFF

Usage Recommendation
use it, but don't rely on it

Autocompletion, which was first introduced by Microsoft Internet Explorer, is the browser feature of remembering what you entered in previous text form fields with the same name. So, for example, if the field is named name and you had entered several variants of your name in other fields named name, then autocompletion provides those options in a dropdown. This image shows autocompletion being used in a form field:

Image of text field with autocompletion

Generally autocompletion is a useful browser feature, but occasionally it can be harmful. If the form field contains information such as a credit card number that should be left stored on the user's hard drive then you should turn autocompletion off. You can turn it off by setting AUTOCOMPLETE to OFF:

Control.ClientIDMode Property

ASP.NET provides multiple algorithms for how to generate the ClientID property value. You select which algorithm to use for a control by setting its ClientIDMode property. The algorithms are identified by the ClientIDMode enumeration values that are listed in the following table.