Thursday, March 18, 2010

71-515 .NET 4 Web Dev Server Controls

Hey Now,

Let’s continue with the MS .NET 4 Web Dev Beta exam 71-515!

Server controls should be a good place to start, it’s a high percentage in both exams .NET 3.5 & 4, very important topic since it’s used all the time. After rereading the skills measured the key point for this sections are as follows:

1. Validate User Input
2. Create Page Layout
3. Implement User Controls
4. Implement Server Controls
5. Interface Controls from Code Behind

Let’s get into some detail from the 3.5 book on controls.

‘Adding & Configuring Server Controls’ – is a chapter and broken up into 3 lessons

Understanding & Using Server Controls
Exploring Common Server Controls
Exploring Specialized Server Controls

Developing and Using Web Forms Controls (18%)

  • Validate user input.
    This objective may include but is not limited to:
    • client side,
    • server side, and
    • via AJAX;
    • custom validation controls;
    • regex validation;
    • validation groups;
    • datatype check;
    • jQuery validation
      This objective does not include:
      • RangeValidator and
      • RequiredValidator
  • Create page layout.
    This objective may include but is not limited to:
    • AssociatedControlID;
    • Web parts;
    • navigation controls;
    • FileUpload controls
      This objective does not include: 
      • label;
      • placeholder,
      • panel controls;
      • CSS, HTML, referencing CSS files, inlining
  • Implement user controls.
    This objective may include but is not limited to:
    • registering a control;
    • adding a user control;
    • referencing a user control;
    • dynamically loading a user control;
    • custom event;
    • custom properties;
    • setting toolbox
    • visibility
  • Implement server controls.
    This objective may include but is not limited to: composite controls,
    • INamingContainer,
    • adding a server control to the toolbox,
    • global assembly cache,
    • creating a custom control event,
    • globally registering from web.config;
    • TypeConverters
      This objective does not include:
      • postback data handler,
      • custom databound controls,
      • templated control
  • Manipulate user interface controls from code-behind.
    This objective may include but is not limited to: HTML encoding to avoid cross-site scripting, navigating through and manipulating the control hierarchy;
    • FindControl;
    • controlRenderingCompatibilityVersion;
    • URL encoding;
    • RenderOuterTable
      This objective does not include properties:
      • Visibility
      • Text
      • Enabled

Below is the skilled measured from the MS official page

There are many examples used here are some examples of key points made in the sample exam. The #’s are not in numberical order but just use them as a guide for a little organization:

3 You can use a RegularExpressionValidator to validate the format of almost any kind of text input. The Microsoft Visual Studio interface provides standard regular expressions to match phone numbers.

4 HierarchicalDataBoundControl is provided as the base class for hierarchical controls, such as those that provide a tree or menu structure.

5 Setting the AutoPostBack property to False will prevent the page from posting each time the text change

6 Page.IsValid returns True if all validators on the page were successful.

7 You can use the MultiView control to perform tasks such as the following:
* Provide alternate sets of controls based on user choice or other conditions.
* Create a multipage form.

8 The ASP.NET ListView control enables you to bind to data items that are returned from a data source and display them. By supporting templates, it provides a fine control over the rendered output. By associating a DataPager with the ListView you can easily support paging.

9 To configure the Alt+N access key, set the LabelName control's AssociatedControlID property to TextBoxName and set the LabelName control's AccessKey property to N.

10 By default, events raised by TextBox controls are not processed until the user presses a button or performs some other action that sends a response to the server. To cause the event to be processed immediately, set the control's AutoPostBack property to True.

11 You use the @ Register directive when you add a user control to the page declaratively.

12 Use the PlaceHolder control as a container to store server controls that are dynamically added to the Web page. The PlaceHolder control does not produce any visible output and is used only as a container for other controls on the Web page. You can use the PlaceHolder.Controls collection to add, insert, or remove a control in the PlaceHolder control.

13 Setting the form's DefaultButton property to the ID of the button to click if the user presses Enter will have the desired result.

14 The DetailsView control displays a single record from a data source, where each data row represents a field in the record. It provides paging and editing capabilities

15 With templated controls, you should always use the Placeholder control. Developers who implement your templated control can then add their own control types.

18 To perform validation that occurs on the client-side, you must add a JavaScript function to your page.

To configure the CustomValidator to recognize and invoke your client-side validation function, set the CustomValidator.ClientValidationFunction to the name of the function.

19 Given the requirements, you should create a templated control using ITemplate. Templated controls allow you to separate the control data from the presentation so other developers can implement the user interface at design time. The developer creates templates of the type defined by the user control and can then add controls and markup to the templates.

21 The DataGrid control requires you to write a lot of custom code to handle common operations such as paging, sorting, editing, and deleting data. The GridView supports these capabilities automatically.

24 CustomValidator enables you to write custom code to validate input, which would be required to check input against a database

25 When overriding the PerformSelect method, you must follow a very orderly structure. First, check whether DataSource or DataSourceID is being used. If DataSource is being used, call the OnDataBinding method. Then, you must perform tasks in a specific order to ensure dependencies are fulfilled. First, call the Select method. Then, set RequiresDataBinding to False and call MarkAsDataBound. Then, raise the DataBound event.

26 DetailsView, FormView, and GridView all support paging, which enables you to display the data across multiple pages.

Menu, TreeView, and DataList do not support paging. Therefore, you must display all of their data on a single page.

28 To set default focus in a form or panel, set the DefaultFocus attribute of the form element in the page or of a Panel control to the ID of the control to receive focus

29 Use the PlaceHolder control as a container to store server controls that are dynamically added to the Web page. The PlaceHolder control does not produce any visible output and is used only as a container for other controls on the Web page. You can use the PlaceHolder.Controls collection to add, insert, or remove a control in the PlaceHolder control.

20 A template property is one that returns a value of type ITemplate. You must apply the TemplateContainer attribute to template properties.
[TemplateContainer(typeof(SimpleRepeater)) ]

public ITemplate ItemTemplate

30 You use the @ Reference directive when you intend to load the control programmatically.

31 The scenario calls for a custom server control. To create a custom server control, extend the WebControl class and override the Render method.

32 The easiest way to require the user to complete a TextBox control is to add both the TextBox control and the RequiredFieldValidator controls beside each other and then specify the RequiredFieldValidator.ControlToValidate and RequiredFieldValidator.ErrorMessage properties.

35 The Page.LoadControl method loads a Control object from a file based on a specified virtual path.

36 When you develop templated controls, you should implement the INamingContainer interface to avoid naming conflicts on a page. INamingContainer creates a new ID namespace within a page's control hierarchy, guaranteeing that all names will be unique.

37 The ValidationSummary control will display detailed error information if you add it to the page with the ChangePassword control and set the ValidationSummary.ValidationGroup property to the ID of your ChangePassword control.

39 The DataPager provides paging functionality for data-bound controls that implement the IPageableItemContainer interface, such as the ListView control.

Let’s get to some code!
The specialized server controls code is a nice example. It has three basic screens the user selects an office, clicks next, selects a date, clicks next then there is a summary page, click finish & then a confirmation page. The image uses a nifty property hotspot, along with a wizard control. The main point being these controls are more specialized & not used as often.

Here is some code from an example of using server controls:

ASPX File:
<asp:Label ID="LabelInformation" runat="server"></asp:Label>
<br />
User Name<br />
<asp:TextBox ID="TextBoxUserName" runat="server" MaxLength="12"></asp:TextBox>
<br />
<asp:CheckBox ID="CheckBoxAdmin" runat="server" Text="System Administrator"
AutoPostBack="True" oncheckedchanged="CheckBoxAdmin_CheckedChanged" />
<br />
Applicaiton role:
<br />
<asp:RadioButton ID="RadioButton1" runat="server" Text="User"
GroupName="ApplicationRole" />
&nbsp;<asp:RadioButton ID="RadioButton2" runat="server" Text="Manager"
GroupName="ApplicationRole" />
&nbsp;<asp:RadioButton ID="RadioButton3" runat="server" Text="Director"
GroupName="ApplicationRole" />
<asp:Button ID="ButtonSave" runat="server" Text="Save"
onclick="ButtonSave_Click" />

.CS File important lines of code:
protected void ButtonSave_Click(object sender, EventArgs e)
LabelInformation.Text = "User information saved.";
protected void CheckBoxAdmin_CheckedChanged(object sender, EventArgs e)
if (CheckBoxAdmin.Checked)
CheckBoxAdmin.Text = "System Administrator";
CheckBoxAdmin.Text = "Check to set as system administrator";


Below are a few more sample questions from the book, they can be good for us to focus on some key concepts:
Chapter 2

Q1 Q How to add an HTML Server control :
A To convert an HTML element into a server control you add the runat+”server” attribute & value to the element

Q2 How to make a CheckBox cause an automatic PostBack
A To indicate that a control’s default event should cause a Postback you set the AutoPostBack property of the control to true

Q3 Q Dynamically create an instance of Textbox. Which page event? Preinit ofcouse
A The PreInit event is where you want to create & recreate your dynamically generated controls. This ensursures they will be available for initialization. ViewState connection & code inside other events such as Load.

Q4 Q: write code to dynamically create an instance of a Textbox server control. You want to make sure the control displays on the page: Call the ShowControl Method on the TextBox.
A Dynamically created control must be added to the form element assosciated with the page. The form element must also be set to runat=”server”

Lesson 2

Q1 Q If radiobutton
The RadioButton controls GroupName Property is used to group two or more mutually exclusive radio buttons.

Q2 Other than the normal submit button use the Command Button.
A. You Create a commond button by setting the CommandName property of the button & responding to the Command event for the button.

Q3 Q How to create an event handler for a server control.
D The easiest way to create an event handler for the default event of a control is to double click the control in Design view.

Lesson 3

Q1 Best use of Table, TableRows & TableCells is good for displaying tabular set of data

Q2 Best way to incorporate an imange on a site for navigation.
D The imageMap provides the ability to define hot spot areas & the PostBackValue can be used to determine the area that was clicked.

Q3 C Wizard Control:
The Wizard control will solve this issue by providing an easy to implement solution for collecting multiple page data from users.

There we have it, there is quite a bit of content on ASP.NET Server Controls.

That is all, and there will be more!

Bye now,


No comments: