Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Chapter 05: Input Validation and Site Navigation - MCTS Exam 70-515

RSS
Modified on Tue, Jan 03, 2012, 2:11 PM by Administrator Paths: MCTS Exam 70-515 Categorized as MCTS Exam 70-515

Lesson 1: Input Validation

Common Properties

  • ControlToValidate property
  • ErrorMessage property — text displayed in a ValidationSummary control when validation fails
  • Text property — text displayed in the validation control when validation fails
  • Display property — None, Static, or Dynamic
  • ValidationGroup property

Validation Controls

  • RequiredFieldValidator
  • CompareValidator — compares the value of a control to another control - OR - does a data type check
  • RangeValidator
  • RegularExpressionValidator
  • CustomValidator
  • ValidationSummary

Page Members

  • Validators property — collection of all validation controls on the page
  • Validate method — called automatically after the page has loaded to set the IsValid property
  • IsValid property — True only if ALL validation controls report valid input; False otherwise

Lesson 2: Site Navigation

Client-Side Navigation

  • Done via hyperlinks or JavaScript code

Cross-Page Posting

  • A control/form are configured to post back to a different page
  • Use the Page.PreviousPage property with the FindControl method to access the controls of interest on the previous page.

Client-Side Browser Redirect

  • Server code sends a Response.Redirect

Server-Side Transfer

  • Server code transfers control to another page (e.g. via Server.Transfer)

SiteMap Files and the SiteMap Class

  • A .sitemap file is an XML hierarchy of <siteMapNode> nodes representing the navigational structure of your website.
  • The SiteMap class provides programmatic access to the sitemap.
  • To display the sitemap to users, use a SiteMapDataSource with navigation control(s).
  • Navigation controls include: Menu, TreeView, and SiteMapPath.

Lesson 3: Web Parts

Controls

ControlDescriptionHosted Within
WebPartManager invisible control required on every page that includes Web Parts(not applicable)
WebPartA component of pre-defined functionality that can be added to, removed from, and moved around on a web page by the developer or the user.WebPartZone
CatalogPart UI for managing a group of available Web PartsCatalogZone
PageCatalogPart similar to CatalogPart, but only groups those Web Parts that are part of a specific page; can be used, for example, to return a Web Part to a page on which it's been closed.CatalogZone
EditorPart allows user customizationsEditorZone
DeclarativeCatalogPart allows developer to declare Web Parts available to a page or the entire site(not applicable)

Creation

  • Add a user control to a WebPartZone (inside its ZoneTemplate declaration)
  • Add a standard ASP.NET control to a WebPartZone: for example a Label, which is used as a content container
  • Create your own custom control derived from the WebPart class

Enabling User Arrangement and Editing

Change the display mode of the page via the WebPartManager control's DisplayMode property, which has the following settings.

Display ModeDescription
BrowseDisplayModeDefault mode in which users view content
DesignDisplayModeEnables dragging of web parts
EditDisplayModeEnabled dragging and editing (title, size, direction, appearance, and zone). Requires an EditorZone cotnrol, plus either an AppearanceEditorPart and LayoutEditorPart control, on the page
CatalogDisplayModeEnabled adding of web parts. Requires a CatalogZone control on the page
ConnectDisplayModeEnables connecting controls via a ConnectionZone control on the page

Connecting Web Parts with Static Connections

1. Create a provider web part (either a user control, or derived from WebPart class)

2. Create a public method in the provider web part decorated with the ConnectionProvider attribute and which returns the value the consumer web part will receive, like the example below.

public partial class Provider : System.Web.UI.UserControl
{
  string _textBoxValue = "";
  [ConnectionProvider("TextBox provider", "GetTextBoxValue")]
  string GetTextBoxValue()
  {
    return _textBoxValue;
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
    _textBoxValue = TextBoxProvider.Text;
  }
}

3. Create a consumer web part (either a user control, or derived from WebPart class)

4. Create a public method decorated with the ConnectionConsumer attribute, and that accepts the same data type that the provider's ConnectionProvider method returns, like the following example.

public partial class Consumer : System.Web.UI.UserControl
{
  [ConnectionConsumer("TextBox consumer", "ShowTextBoxValue")]
  void ShowTextBoxValue(string textBoxValue)
  {
    LabelConsumer.Text = textBoxValue;
  }
}

5. Create a web page with a WebPartManager and at least one WebPartZone container.

6. Add the provider and consumer web parts to the WebPartZone container(s).

7. Add the asp:WebPartConnection to the StaticConnections section of your WebPartManager control. The WebPartConnection should have the following properties set. Note that you should have one WebPartConnection control for each pair of connected controls.

PropertyDescription
IDUnique identifier
ProviderIDID of the provider control
ProviderConnectionPointIDName of the provider method
ConsumerIDID of the consumer control
ConsumerConnectionPointIDName of the consumer method

WebPartConnection Example
<asp:WebPartManager ID="WebPartManager1" runat="server">
  <StaticConnections>
    <asp:webPartConnection
      ID="conn1"
      ProviderID="Provider1"
      ProviderConnectionPointID="GetTextBoxValue"
      ConsumerID="Consumer1"
      ConsumerConnectionPointID="ShowTextBoxValue" 
      />
  </StaticConnections>
</asp:WebPartManager>

Enabling Dynamic Connections

1. Create a page with a provider and consumer connection, as in the previous section.

2. Optionally create a static connection (as in the previous section), which will act as the default connection.

3. Add a ConnectionsZone control to the web page.

4. Add a control to enable the user to enter connect mode.

Personalization

  • Personalization of Web Parts is done via the ASPNETDB SQL Server database.

  • To store custom personalization data, define a public property on the control and decorate it with the Personalizable attribute. This will store the personalization data for each user.

  • To enable shared personalization, which will allow personalization changes made by one user to be viewed by others, make the
    following change to your web.config file: within /system.web/authorization add a node for lt;allow verbs="enterSharedScope" users="SomeUser" roles="admin" />

  • To disable personalization for a page, set the WebPartManager.Personalization.Enabled attribute to false, like this.

<asp:WebPartManager runat="server">
  <Personalization Enabled="False" />
</asp:WebPartManager>

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.