70-515 chapter7

41
Web Applications Development with Microsoft .NET Framework 4 - C# Question Number (ID) : 1 (515P_2.1_01) __________________________________________________________________________________________________________________ You are creating a webpage that includes a CustomValidator control. You add the following event handler to the control's ServerValidate event: protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) { // Add code here. } Which code segment can you use to verify that date input can be parsed into a DateTime object? 1. if (DateTime.TryParseExact(args.Value, "d", null)) { Validate(); } 2. Page.IsValid = DateTime.TryParseExact(args.Value, "d", null); 3. args.IsValid = DateTime.TryParseExact(args.Value, "d", null); <Correct> 4. try { DateTime.ParseExact(args.Value, "d", null); Validate(); } catch { } Explanation: To handle custom validation, respond to the CustomValidator.ServerValidate event. Then set the ServerValidateEventArgs.IsValid parameter to True if the validation succeeds or to False if the validation fails. You cannot set the Page.IsValid property; it is read-only. The Page.Validate method causes ASP.NET to perform validation on the page. It does not confirm validation. Objective: Developing and Using Web Forms Controls Sub Objective(s): Validate user input References: MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4 Chapter 5 - Lesson 1 Walkthrough: Validating User Input in a W eb Forms Page MSDN Library Link: http://msdn.microsoft.com/en-us/library/a0z2h4sw.aspx CustomValidator Class MSDN Library Link: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.aspx

description

70-515 quiz chapter 7

Transcript of 70-515 chapter7

Page 1: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 1 (515P_2.1_01)

______________________________________________________________________________________________________________________________________________

You are creating a webpage that includes a CustomValidator control. You add the following event handler to the control's ServerValidate event:

protected void CustomValidator1_ServerValidate(object source,ServerValidateEventArgs args)

{// Add code here.

}

Which code segment can you use to verify that date input can be parsed into a DateTime object?

1. if (DateTime.TryParseExact(args.Value, "d", null)){

Validate();}

2. Page.IsValid = DateTime.TryParseExact(args.Value, "d", null);

3. args.IsValid = DateTime.TryParseExact(args.Value, "d", null); <Correct>

4. try{

DateTime.ParseExact(args.Value, "d", null);Validate();

}catch{}

Explanation:To handle custom validation, respond to the CustomValidator.ServerValidate event. Then set the ServerValidateEventArgs.IsValid parameter to True if the validation succeeds or to False if the validation fails.

You cannot set the Page.IsValid property; it is read-only.

The Page.Validate method causes ASP.NET to perform validation on the page. It does not confirm validation.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Validate user input

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 5 - Lesson 1

Walkthrough: Validating User Input in a Web Forms PageMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/a0z2h4sw.aspx

CustomValidator ClassMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.aspx

Page 2: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 2 (515P_2.1_02)

______________________________________________________________________________________________________________________________________________

You need to ensure that web form users enter content into a TextBox control named Address before submitting the form.

Which solution should you use to accomplish this goal with the least amount of development effort?

1. Add a CustomValidator control to the web form. Set the CustomValidator.ControlToValidate property to the ID of the TextBox control. Then set the CustomValidator.ErrorMessage property.

2. Add a RequiredFieldValidator control to the web form. Set the RequiredFieldValidator.ControlToValidate property to the ID of the TextBox control. Then set the RequiredFieldValidator.ErrorMessage property. <Correct>

3. Add a RequiredFieldValidator control to the web form immediately after the TextBox. Then set the RequiredFieldValidator.ErrorMessage property.

4. Add a CustomValidator control to the web form immediately after the TextBox. Then set the CustomValidator.ErrorMessage property.

Explanation:The easiest way to require a user to enter content into a TextBox control is to add the TextBox control and the RequiredFieldValidator controls and then specify the RequiredFieldValidator.ControlToValidate and RequiredFieldValidator.ErrorMessage properties.

You must define an association between a control and a validator by setting the validator's ControlToValidate property, not by simply placing the validator next to the control.

The CustomValidator could be used, but a RequiredFieldValidator will require less effort.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Validate user input

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 5 - Lesson 1

Walkthrough: Validating User Input in a Web Forms PageMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/a0z2h4sw.aspx

RequiredFieldValidator Control (General Reference)MSDN LibraryLink: http://msdn.microsoft.com/en-us/library/5hbw267h.aspx

Page 3: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 3 (515P_2.1_03)

______________________________________________________________________________________________________________________________________________

You need to add a control to validate that a user enters a telephone number into a TextBox control in a valid format.

Which control should you use to accomplish this goal with the least amount of development effort?

1. CompareValidator

2. RangeValidator

3. RequiredFieldValidator

4. RegularExpressionValidator <Correct>

Explanation:You can use the RegularExpressionValidator control to validate the format of almost any kind of text input. First set the ControlToValidate property to the ID of the TextBox control. Then set the ValidationExpression property to a regular expression that matches the required telephone number format. The Microsoft Visual Studio 2010 interface provides standard regular expressions to match telephone number formats for many different countries.

The RequiredFieldValidator simply requires the user to enter content in a field; the content does not have to match a particular format.

Use RangeValidator to validate simple numbers that do not have special formatting.

Use CompareValidator to compare the values of multiple controls.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Validate user input

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 5 - Lesson 1

Walkthrough: Validating User Input in a Web Forms PageMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/a0z2h4sw.aspx

How to: Validate Against Patterns for ASP.NET Server ControlsMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/6xh899wy.aspx

Page 4: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 4 (515P_2.1_04)

______________________________________________________________________________________________________________________________________________

You need to add a control to validate that a user enters a value into a TextBox control that matches a value contained in a database.

Which control should you use?

1. CompareValidator

2. CustomValidator <Correct>

3. RegularExpressionValidator

4. RangeValidator

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

You can use RegularExpressionValidator to validate the format of almost any kind of text input such as telephone numbers. However, regular expressions cannot look up values in a database.

Use RangeValidator to validate simple numbers.

Use CompareValidator to compare the values of other controls, not values in a database.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Validate user input

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 5 - Lesson 1

Walkthrough: Validating User Input in a Web Forms PageMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/a0z2h4sw.aspx

How to: Validate Against Values in a Database for ASP.NET Server ControlsMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/s5z00s5e.aspx

Page 5: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 5 (515P_2.1_05)

______________________________________________________________________________________________________________________________________________

Your web form uses standard and custom Validator controls. To reduce the risk of a malicious user bypassing client-side validation, you need to check that the form passed validation in a Button.Click handler method.

Which solution should you use to validate the form input with the least amount of development effort?

1. Check the Page.IsValid property. <Correct>

2. Iterate through the Page.Controls collection and check each validator's IsValid property.

3. Call the Page.Validate method.

4. Iterate through the Page.Controls collection and check each control's IsValid property.

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

The Page.Validate method initiates validation but does not identify whether validation was successful.

Checking individual controls is not necessary and requires additional effort.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Validate user input

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 5 - Lesson 1

How to: Test Validity Programmatically for ASP.NET Server ControlsMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/dh9ad08f.aspx

Page.IsValid PropertyMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/system.web.ui.page.isvalid.aspx

Page 6: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 6 (515P_2.1_06)

______________________________________________________________________________________________________________________________________________

You are creating a webpage that enables users to change their passwords. The webpage includes a ChangePassword control.

Which control can you use to display an informational message to users if they enter incorrect information in the ChangePassword control?

1. RangeValidator

2. CompareValidator

3. CustomValidator

4. ValidationSummary <Correct>

Explanation: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.

The CustomValidator control enables you to implement custom validation, but it does not display error information from a ChangePassword control.

CompareValidator and RangeValidator enable you to restrict user input. They cannot display error information from a ChangePassword control.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Validate user input

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 5 - Lesson 1

ASP.NET Login Controls OverviewMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/ms178329.aspx

ChangePassword ClassMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.changepassword.aspx

Page 7: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 7 (515P_2.1_07)

______________________________________________________________________________________________________________________________________________

You add a CustomValidator control to a webpage to validate the contents of a TextBox. You need to add client script to perform partial validation.

Which steps must you complete to achieve this goal? (Each correct answer presents part of the solution. Choose two.)

1. Add a validation event handler to the page code-behind class.

2. Set the CustomValidator.ClientValidationFunction to the name of the function. <Correct>

3. Add the event handler to the CustomValidator.ServerValidate event.

4. Add a JavaScript function that performs validation to the page. <Correct>

5. Set the CustomValidator.ClientValidationFunction to true.

Explanation:ASP.NET includes validator controls that have JavaScript functions built in to provide validation. If none of these meet your needs, you can write your own JavaScript function to perform validation. To allow the function to run, add a CustomValidator control and set the CustomValidator.ClientValidationFunction to the name of your JavaScript function. ASP.NET will connect the control to the function so that the function runs when validation is required.

Because validation happens on the client, you do not need to handle events on the server in a code-behind class to add client script to perform partial validation.

The CustomValidator.ClientValidationFunction cannot be set to a Boolean value; it must be set to the name of your JavaScript function.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Validate user input

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 5 - Lesson 1

Client-Side Validation for ASP.NET Server ControlsMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/yb52a4x0.aspx

Walkthrough: Validating User Input in a Web Forms PageMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/a0z2h4sw.aspx

Page 8: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 8 (515P_2.1_08)

______________________________________________________________________________________________________________________________________________

You add a CustomValidator control to a webpage to verify that a user enters a valid date value into a TextBox. You add the following JavaScript function to your page to perform client-side validation.

<script language="javascript">function validateDate(oSrc, args){

var iDay, iMonth, iYear;var arrValues;arrValues = args.Value.split("/");iMonth = arrValues[0];iDay = arrValues[1];iYear = arrValues[2];

var testDate = new Date(iYear, iMonth - 1, iDay);if ((testDate.getDate() != iDay) ||

(testDate.getMonth() != iMonth - 1) ||(testDate.getFullYear() != iYear))

{// Add code to indicate that validation failed.

}

return true;}</script>

You need to add code to the if block in place of the comment, to indicate that client-side validation failed.

Which action should the code perform?

1. Set the args.IsValid property to false and return. <Correct>

2. Return false.

3. Throw an exception.

4. Set the args object to false and return.

Explanation:The user's entry is passed into the function as the args object's Value property, and you can set the object's IsValid property to indicate whether the value passes validation.

Throwing an exception is not the correct implementation.

Setting the args object to false and return is not the correct implementation.

Returning false is not the correct implementation.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Validate user input

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 5 - Lesson 1

Page 9: 70-515 chapter7

Client-Side Validation for ASP.NET Server ControlsMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/yb52a4x0.aspx

Walkthrough: Validating User Input in a Web Forms PageMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/a0z2h4sw.aspx

Page 10: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 9 (515P_2.1_09)

______________________________________________________________________________________________________________________________________________

You are developing a web form that includes several controls for users to input data. The form includes Validator controls that will perform client-side validation to verify the input. You need to display error messages next to the control that caused the validation error without changing the layout of the page.

Which method should you use to display an error message next to a control that causes a validation error without changing the page layout?

1. Set Static layout for each Validator control. <Correct>

2. Disable client-side validation.

3. Set Dynamic layout for each Validator control.

4. Add a ValidationSummary control to the form and set the display mode to List.

Explanation:Set Static layout to ensure that error messages display next to the control and the page layout does not change.

Setting Dynamic layout can change the layout of the page.

Disabling client-side validation does not accomplish the goal and interferes with normal validation behavior.

Use a ValidationSummary control to summarize error messages, not to display messages next to the control.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Validate user input

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 5 - Lesson 1

Client-Side Validation for ASP.NET Server ControlsMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/yb52a4x0.aspx

Walkthrough: Validating User Input in a Web Forms PageMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/a0z2h4sw.aspx

Page 11: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 10 (515P_2.4_01)

______________________________________________________________________________________________________________________________________________

You are creating a custom control. Your control must output raw HTML and provide rich design-time support.

Which method should you use to create the control?

1. Define the control in an .ascx file and override the Render method.

2. Create a control that extends the WebControl class and override the Render method. <Correct>

3. Create a control that extends the WebControl class and override the OnLoad method.

4. Create a control that extends the WebControl class and add an event handler to the Load event. Dynamically render HTML in the event handler.

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

The WebControl contents must be rendered with the HtmlTextWriter provided to a Render method override.

Adding an .ascx control defines a user control. A user control does not provide complete control over the HTML it generates, and does not provide rich design-time support.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement server controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 4 - Lesson 1

Walkthrough: Developing and Using a Custom Web Server ControlMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/yhzc935f.aspx

A Crash Course on ASP.NET Control Development: Building New Controls from the Ground UpMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/aa479309.aspx

Page 12: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 11 (515P_2.3_01)

______________________________________________________________________________________________________________________________________________

You are creating an ASP.NET web form. You use the following code segment to dynamically add a Label control to a PlaceHolder named PlaceHolder1:

protected void Page_Load(object sender, EventArgs e){

if (!IsPostBack){

Label Label1 = new Label();Label1.Text = "Sample Label";Label1.ID = "Label1";PlaceHolder1.Controls.Add(Label1);

}}

The Label control uses ViewState. When you submit the form, the dynamically added controls disappear.

Which solution will prevent the controls from disappearing when you submit the form?

1. Create and add the label only when IsPostBack is true.

2. Always create and add the label, not only when IsPostBack is false. <Correct>

3. Move the code to an event handler attached to the PreInit event.

4. Move the code to an event handler attached to the Init event.

Explanation:ASP.NET does not maintain dynamically created controls between postbacks. Therefore, you must add dynamically created controls whether or not the request is a postback. Otherwise, the control will disappear when the user submits the form.

Moving the code to a different event handler will not cause the controls to appear on postbacks.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement user controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 5 - Lesson 2

How to: Add Controls to an ASP.NET Web Page ProgrammaticallyMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/kyt0fzt1(VS.85).aspx

Understanding ASP.NET View StateMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/ms972976.aspx

Page 13: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 12 (515P_2.3_02)

______________________________________________________________________________________________________________________________________________

You are creating an ASP.NET webpage.

Which directive should you use to ensure that your page can reference a user control defined in an .ascx file?

1. @ Control

2. @ Register <Correct>

3. @ Reference

4. @ Import

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

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

The @ Import directive explicitly imports a namespace into an ASP.NET application file (such as a webpage, a user control, a master page, or a Global.asax file), making all classes and interfaces of the imported namespace available to the file.

The @ Control directive defines .ascx-based user control attributes that are used by the ASP.NET page parser and compiler.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement user controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 1

ASP.NET User ControlsMSDN LibraryLink: http://msdn.microsoft.com/en-us/library/y6wb1a0e.aspx

Page 14: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 13 (515P_2.4_02)

______________________________________________________________________________________________________________________________________________

You are creating a composite server control that includes a label, a text box, and a button. You need to persist properties containing information about the control's state, including the user's preferences, which aren't standard properties of the child controls.

How can you do this? (Each correct answer presents a complete solution. Choose two.)

1. Decorate the properties that need to be persisted with the Bindable attribute.

2. Override the Render event to call the SaveViewState method.

3. Override the LoadViewState event. <Correct>

4. Override the SaveViewState event. <Correct>

5. Make the properties that need to be persisted public.

Explanation:Child controls automatically store their state in ViewState. However, if you want to persist information that is not normally stored in child view state, you will need to override the SaveViewState event and add the values to the viewstate collection. To read the values back from viewstate, you need to override the LoadViewState event.

Public properties are not automatically persisted.

The Bindable attribute is used to link properties to data. It does not facilitate persisting data.

The Render event handles outputting the control's HTML. While it is common to override the Render event for a server control, you would never call the SaveViewState method from the Render event. ASP.NET calls the SaveViewState method automatically as part of the page lifecycle.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement server controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 2

Composite Web Control ExampleMSDN LibraryLink: http://msdn.microsoft.com/library/3257x3ea.aspx

Page 15: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 14 (515P_2.4_03)

______________________________________________________________________________________________________________________________________________

You are developing a custom server control that contains a text box, a label, and a button. You need to choose the most appropriate base class for the control.

Which class should you choose?

1. Control

2. TextBox

3. Content

4. CompositeControl <Correct>

Explanation:The CompositeControl class implements the basic functionality required by web controls that contain child controls. Composite controls are the most efficient way to create server controls that contain multiple child objects.

While possible, using the Control, Content, or TextBox classes instead of CompositeControl would make it more time-consuming to add multiple child controls. CompositeControl is the more appropriate selection given no other specialized control requirements.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement server controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 2

Composite Web Control ExampleMSDN LibraryLink: http://msdn.microsoft.com/library/3257x3ea.aspx

CompositeControl ClassMSDN LibraryLink: http://msdn.microsoft.com/library/system.web.ui.webcontrols.compositecontrol.aspx

Page 16: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 15 (515P_2.4_04)

______________________________________________________________________________________________________________________________________________

You are creating a custom server control that defines a property named Text and derives from the WebControl class. When the control is rendered, the Text property is displayed on a web form. You need to ensure that developers using the control can define the Text property, and that the Text property stays constant even if the web form is submitted by a user multiple times. Developers should not need to write code to persist the state.

Which implementation meets the requirements while allowing developers to reliably change the Text property?

1. In the Set property method, write the value to ViewState. In the Get property method, read the value from ViewState.<Correct>

2. Classes that derive from WebControl automatically store property values in ViewState.

3. In the constructor for the control, write the value to ViewState. In the RenderContents method for the control, read the value from ViewState.

4. Instruct developers to manually store the Text property in ViewState.

Explanation:The best way to persist properties is to use the Set and Get property methods to store and retrieve the value in ViewState.

Classes that derive from WebControl do not automatically store property values in ViewState. You must manually provide the code to store values in ViewState.

Persisting ViewState is a function provided by ASP.NET and is not typically replaced by developers due to the complexity of the operation. Additionally, the question requires that you not require the other developers to write code to properly implement your control.

You should store and retrieve the value in ViewState by using the property methods, not the constructor and the RenderContents methods. Using the property methods allows developers to access the property.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement server controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 2

Walkthrough: Developing and Using a Custom Web Server ControlMSDN LibraryLink: http://msdn.microsoft.com/library/yhzc935f.aspx

Page 17: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 16 (515P_2.4_05)

______________________________________________________________________________________________________________________________________________

You are creating a custom web server control that derives from the WebControl base class.

In which method should you draw the HTML that displays the visible component of the control?

1. OnInit

2. AddAttributesToRender

3. The derived class constructor

4. RenderContents <Correct>

Explanation:The proper place to draw HTML is in the RenderContents method.

You can use the other methods to define properties; however, all drawing should take place in the RenderContents method.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement server controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 2

Walkthrough: Developing and Using a Custom Web Server ControlMSDN LibraryLink: http://msdn.microsoft.com/library/yhzc935f.aspx

Page 18: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 17 (515P_2.4_06)

______________________________________________________________________________________________________________________________________________

You need to use a custom server control declaratively in a web form. The control is located in the My.Controls namespace.

Which Web.config file enables you to declare the control with the myControls tag prefix?

1. <?xml version="1.0"?><configuration>

<system.web><add tagName="myControls"

namespace="My.Controls"/></system.web>

</configuration>

2. <?xml version="1.0"?><configuration>

<system.web><add tagPrefix="myControls"

namespace="My.Controls"/></system.web>

</configuration>

3. <?xml version="1.0"?><configuration>

<system.web><pages>

<controls><add tagName="myControls"

namespace="My.Controls"></add>

</controls></pages>

</system.web></configuration>

4. <?xml version="1.0"?><configuration>

<system.web><pages>

<controls><add tagPrefix="myControls"

namespace="My.Controls"></add>

</controls></pages>

</system.web></configuration>

<Correct>

Explanation:Before you can declare custom controls, you must define a tag prefix. You can do this by using either page directives or the Web.config file. If you use the Web.config file, add the prefix in the configuration\system.web\pages\controls section. For each prefix, use the <add> element with the tagPrefix and Namespace attributes.

The tagName attribute is for use with user controls, not custom server controls.

Page 19: 70-515 chapter7

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement server controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 2

controls Element for pages (ASP.NET Settings Schema)MSDN LibraryLink: http://msdn.microsoft.com/library/ms164640.aspx

Walkthrough: Developing and Using a Custom Web Server ControlMSDN LibraryLink: http://msdn.microsoft.com/library/yhzc935f.aspx

Page 20: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 18 (515P_2.4_07)

______________________________________________________________________________________________________________________________________________

You need to use a custom server control declaratively in a web form. The control is located in the My.Controls namespace in the myControls.dll assembly.

Which page directive enables you to declare the control with the myControls tag prefix?

1. <%@ Register TagPrefix="myControls" Assembly="myControls.dll"%>

2. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" TagPrefix="myControls" TagNamespace="My.Controls"%>

3. <%@ Register TagPrefix="myControls" Namespace="My.Controls" %> <Correct>

4. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" addPrefix="myControls" addNamespace="My.Controls"%>

Explanation:To register a custom server control declaratively in a web form, use the Register page directive and specify the TagPrefix and Namespace attributes.

You cannot add custom server controls in the Page directive.

Although you can specify an assembly in the Register directive, you would also need to specify the namespace. In addition, you should not specify a file extension when specifying an assembly.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement server controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 2

Walkthrough: Developing and Using a Custom Web Server ControlMSDN LibraryLink: http://msdn.microsoft.com/library/yhzc935f.aspx

@ RegisterMSDN LibraryLink: http://msdn.microsoft.com/library/c76dd5k1.aspx

Page 21: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 19 (515P_2.4_08)

______________________________________________________________________________________________________________________________________________

You create two classes of a custom server control: myControl, which derives from CompositeControl, and myControlDesigner, which derives from CompositeControlDesigner. In Microsoft Visual Studio 2010, you want to provide support for using the control in the designer. You need to associate the myControl class with the myControlDesigner class.

Which code segment should you use?

1. [Designer(typeof(myControl))]public class myControlDesigner: CompositeControlDesigner

2. [Designer(myControlDesigner)]public class myControl: CompositeControl

3. [Designer(myControl)]public class myControlDesigner: CompositeControlDesigner

4. [Designer(typeof(myControlDesigner))]public class myControl: CompositeControl <Correct>

Explanation:To associate a custom class with a designer, add the Designer metadata to the control by passing the Designer class type to the Designer attribute.

You must pass the type by using GetType or typeof, not the class itself.

You should not associate the Designer attribute with the designer class. Instead, add the attribute to the Control class.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement server controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 2

Walkthrough: Creating a Basic Control Designer for a Web Server ControlMSDN LibraryLink: http://msdn.microsoft.com/library/12yydcke.aspx

Page 22: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 20 (515P_2.4_09)

______________________________________________________________________________________________________________________________________________

You are creating a composite server control that includes a label, a text box, and a button. You need to allow developers who implement the control to examine and update the label text after the control has been created.

What is the appropriate way to do that?

1. Create a hidden control in the form and then pass the hidden control as a parameter to the composite control's constructor. In your composite control, copy the hidden control's value to the Text property of the Label control.

2. Create a Sub (in Visual Basic) or a void method (in C#) that accepts the label text as a parameter.

3. Create a property in the composite control. Use the Get method to retrieve the child control's property and use the Set method to define the child control's property. <Correct>

4. Directly set the child control's properties by accessing <Composite_Control>.Controls.<Label_Name>.Text.

Explanation:The proper way to allow developers to define properties for child controls is to define custom properties for your composite control. Then, copy the child control's properties to and from the custom control's properties.

You cannot access child controls through the Controls property.

Although you could create a method that accepts the Label text as a parameter, this is the function of a property. Additionally, a Sub (in Visual Basic) or a void method (in C#) would not allow a developer to examine the label text's current value.

Although you could use the hidden control method, this is the function of a property. Additionally, because the Label control can only be defined in the constructor, developers would not be able to edit it after they created the control.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement server controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 2

Composite Web Control ExampleMSDN LibraryLink: http://msdn.microsoft.com/library/3257x3ea.aspx

Page 23: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 21 (515P_2.3_03)

______________________________________________________________________________________________________________________________________________

Which of the following is NOT a true statement about user controls?

1. User controls can run as standalone files. <Correct>

2. User controls have .ascx file extensions.

3. User controls do not include <body> HTML elements.

4. User controls contain @ Control directives.

Explanation:User controls are very similar to ASP.NET webpages; however, they cannot run as standalone files, they have .ascx extensions instead of .aspx extensions, they contain @ Control directives rather than @ Page directives, and they cannot include <html>, <body>, or <form> elements.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement user controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 1

ASP.NET User Controls OverviewMSDN LibraryLink: http://msdn.microsoft.com/library/fb3w5b53.aspx

Page 24: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 22 (515P_2.3_04)

______________________________________________________________________________________________________________________________________________

You create a user control named MyShape that displays shapes when added to a web form. You define a property named Shape in the user control. You need to add the user control to a web form.

Which method should you use to specify the value of the Shape property?

1. <uc1:MyShape id="MyShape" Runat="server" Set="Shape, circle" />

2. <uc1:MyShape id="MyShape" Runat="server" Shape="circle" /> <Correct>

3. <%@ Register Src="MyShape.ascx" TagName="MyShape" TagPrefix="uc1" Shape="circle" %>

4. [Shape("circle")]

Explanation:To set a user control property within an .aspx file, define the property within the UserControl element by using the syntax Propety_Name="value".

The syntax of the other answers is incorrect.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement user controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 1

Walkthrough: Creating Reusable Elements with ASP.NET User ControlsMSDN LibraryLink: http://msdn.microsoft.com/library/3457w616.aspx

Page 25: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 23 (515P_2.3_05)

______________________________________________________________________________________________________________________________________________

In a user control, you need to define properties that developers can read from and write to in order to adjust the behavior of the user control.

What should you do? (Each correct answer presents a complete solution. Choose two.)

1. Define private properties.

2. Accept values in the class constructor and return values in member methods.

3. Define properties with Get and Set property methods. <Correct>

4. Define public properties. <Correct>

Explanation:You can define properties for a user control just like any other class, either by defining public properties or by creating properties with Get and Set accessors.

Like any class, other classes will not be able to access private properties.

User controls are not typically accessed with a constructor.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement user controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 1

How to: Create ASP.NET User ControlsMSDN LibraryLink: http://msdn.microsoft.com/library/wt3k2fyw.aspx

Page 26: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 24 (515P_2.3_06)

______________________________________________________________________________________________________________________________________________

You create a user control. You need to choose the most efficient method of maintaining a property through multiple postbacks of the parent web form.

Which method should you choose?

1. In the parent web form, store the property to ViewState. In the parent web form's Page_Load method, read the value from ViewState if the request is a postback and use it to redefine the property.

2. In the user control, store the property to the Session object. In the control's Page_Load method, read the value from the Session object if the request is a postback and use it to redefine the property.

3. In the parent web form, store the property to the Session object. In the parent web form's Page_Load method, read the value from the Session object if the request is a postback and use it to redefine the property.

4. In the user control, store the property to ViewState. In the control's Page_Load method, read the value from ViewState if the request is a postback and use it to redefine the property. <Correct>

Explanation:User controls are re-initialized with each postback. Therefore, the value needs to be stored and retrieved when the page is loaded. The most convenient way to do this is to access ViewState from the Page_Load method of the user control.

Although you could store and retrieve the data from the parent web form (either in the ViewState or Session object), this would require you to implement the logic in every page that uses the control. It is more efficient to add the logic to the user control itself.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement user controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 1

How to: Create ASP.NET User ControlsMSDN LibraryLink: http://msdn.microsoft.com/library/wt3k2fyw.aspx

Page 27: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 25 (515P_2.3_07)

______________________________________________________________________________________________________________________________________________

Which tasks must you perform to convert a single-file ASP.NET webpage into a user control? (Each correct answer presents part of the solution. Choose five.)

1. Remove runat="server" from any server control declarations.

2. Change the @ Page directive to @ Control. <Correct>

3. Change the Language attribute in the @ Control directive from C# to UserControl.

4. Change the file extension from .aspx to .ascx. <Correct>

5. Append uc_ to the file name.

6. Remove all attributes of the @ Control directive except Language, AutoEventWireup (if present), CodeFile, and Inherits.<Correct>

7. Include a className attribute in the @ Control directive. <Correct>

8. Remove the <html>, <body>, and <form> elements from the page. <Correct>

Explanation:To convert a single-file ASP.NET webpage into a user control, follow these steps:

1. Rename the control so the file name extension is .ascx.2. Remove the <html>, <body>, and <form> elements from the page.3. Change the @ Page directive to an @ Control directive.4. Remove all attributes of the @ Control directive except Language, AutoEventWireup (if present), CodeFile, and Inherits.5. Include a className attribute in the @ Control directive. This allows the user control to be strongly typed when it is added to a page.

User controls can be in any .NET language and do not require a specialized language.

You can use the same syntax for server controls in user controls as you do for standard web forms.

Although you do need to change the file extension, you do not need to add a prefix to a user control file name.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement user controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 1

How to: Convert Web Forms Pages into ASP.NET User ControlsMSDN LibraryLink: http://msdn.microsoft.com/library/2x6sx01c.aspx

Page 28: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 26 (515P_2.3_08)

______________________________________________________________________________________________________________________________________________

You need to programmatically reference a user control at run time.

Which of the following must be true? (Each correct answer presents part of the solution. Choose two.)

1. The ASP.NET webpage in which the control will be created contains an @ Reference directive. <Correct>

2. The ASP.NET webpage is implemented in a single page rather than by using code-behind.

3. The @ Control directive in the user control contains a ClassName attribute. <Correct>

4. The user control is implemented in a single page rather than by using code-behind.

Explanation:To programmatically reference a user control at run time, the @ Control directive in the user control must contain a ClassName attribute, and the ASP.NET webpage in which the control will be created must contain an @ Reference directive. Then you will be able to programmatically create an instance of the control and add it to a container.

Both the user control and the ASP.NET webpage can be implemented in a single page or by using code-behind.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement user controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 1

How to: Create Instances of ASP.NET User Controls ProgrammaticallyMSDN LibraryLink: http://msdn.microsoft.com/library/c0az2h86.aspx

Page 29: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 27 (515P_2.3_09)

______________________________________________________________________________________________________________________________________________

You need to programmatically load and display a user control from an ASP.NET webpage. A PlaceHolder object named PlaceHolder1 exists.

Which code segment should you use?

1. <%@ Page Language="C#" %><%@ Reference Control="~/Controls/MyControl.ascx" %><script runat="server">private ASP.MyControl MyControl1;protected void Page_Load(object sender, EventArgs e){

MyControl1 = (ASP.MyControl)LoadControl("~/Controls/MyControl.ascx");PlaceHolder1.Controls.Add(MyControl1);

} <Correct>

2. <%@ Page Language="C#" %><%@ Reference Control="~/Controls/MyControl.ascx" %><script runat="server">private ASP.MyControl MyControl1;protected void Page_Load(object sender, EventArgs e){

MyControl1 = (ASP.MyControl)LoadControl("~/Controls/MyControl.ascx");MyControl1.Controls.Add(PlaceHolder1);

}

3. <%@ Page Language="C#" %><%@ Reference Control="~/Controls/MyControl.ascx" %><script runat="server">private ASP.MyControl MyControl1;protected void Page_Load(object sender, EventArgs e){

MyControl1 = LoadControl("~/Controls/MyControl.ascx", ASP.MyControl);MyControl1.Controls.Add(PlaceHolder1);

}

4. <%@ Page Language="C#" %><%@ Reference Control="~/Controls/MyControl.ascx" %><script runat="server">private ASP.MyControl MyControl1;protected void Page_Load(object sender, EventArgs e){

MyControl1 = LoadControl("~/Controls/MyControl.ascx", ASP.MyControl);PlaceHolder1.Controls.Add(MyControl1);

}

Explanation:To load and display a user control programmatically, first ensure that the @ Control directive in the user control contains a ClassName attribute. Then add an @ Reference directive to the ASP.NET webpage. To create an instance of the control, pass the LoadControl the path to the .ascx file and cast it as the appropriate type. Then, add it to the container (in this example, PlaceHolder1).

To use LoadControl to create an object, you must cast it as the user control type. You cannot pass both the file name and the type to the LoadControl method.

Page 30: 70-515 chapter7

Adding a PlaceHolder object to a user control would not cause the user control to render on the parent ASP.NET webpage.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Implement user controls

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 1

How to: Create Instances of ASP.NET User Controls ProgrammaticallyMSDN LibraryLink: http://msdn.microsoft.com/library/c0az2h86.aspx

Page 31: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 28 (515P_2.2_01)

______________________________________________________________________________________________________________________________________________

You are developing an application that uses web parts. You want to enable users to switch among Browse, Design, and Catalog modes.

Which task must you perform to enable this functionality? (Each correct answer presents part of the solution. Choose two.)

1. Add a LayoutEditorPart control.

2. Add a CatalogZone control. <Correct>

3. Add a ConnectionsZone control.

4. Add an AppearanceEditorPart control.

5. Programmatically set the WebPartManager.DisplayMode property. <Correct>

Explanation:To enable users to change the web part mode, you must create a control (such as a DropDownList) to programmatically define the WebPartManager.DisplayMode property. This enables the Browse and Design modes. You must also add a CatalogZone control to enable the Catalog mode. Additionally, you must set up personalization.

The ConnectionsZone control provides a user interface that enables users to establish their own connections, and is not required for this scenario.

The AppearanceEditorPart and LayoutEditorPart controls are required only for Edit mode.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Create page layout

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 5 - Lesson 3

Walkthrough: Changing Display Modes on a Web Parts PageMSDN LibraryLink: http://msdn.microsoft.com/library/bw5tctbb.aspx

ASP.NET Web Parts ControlsMSDN LibraryLink: http://msdn.microsoft.com/library/e0s9t4ck.aspx

Page 32: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 29 (515P_2.2_02)

______________________________________________________________________________________________________________________________________________

You intend to connect two web parts so that one web part displays data based on user input specified in the other web part. You will programmatically configure the connection.

Which tasks must you perform to enable two web parts to share data? (Each correct answer presents part of the solution. Choose two.)

1. Add an EditorZone control to the parent webpage.

2. In the web part retrieving the data, add a method that retrieves the data to be shared and specify the ConnectionProvider attribute for the method.

3. In the web part retrieving the data, add a method that retrieves the data to be shared and specify the ConnectionConsumer attribute for the method. <Correct>

4. Add a ConnectionsZone control to the parent webpage.

5. In the web part sharing the data, add a method that exposes the data to be shared and specify the ConnectionConsumer attribute for the method.

6. In the web part sharing the data, add a method that exposes the data to be shared and specify the ConnectionProvider attribute for the method. <Correct>

Explanation:To enable two web parts to share data, add the ConnectionProvider attribute to a method in the web part sharing the data, and add the ConnectionConsumer attribute to a method in the web part retrieving the data.

You do not need a ConnectionsZone control because it is necessary only if the user will be configuring connections.

You do not need an EditorZone control because it is useful only if you want users to edit the appearance of controls.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Create page layout

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 5 - Lesson 3

Web Parts Connections OverviewMSDN LibraryLink: http://msdn.microsoft.com/library/ms178187.aspx

ASP.NET Web Parts ControlsMSDN LibraryLink: http://msdn.microsoft.com/library/e0s9t4ck.aspx

Page 33: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 30 (515P_2.2_03)

______________________________________________________________________________________________________________________________________________

Another developer has created a connection provider web part that exposes a list of stock tickers that the user chooses to monitor. You would like to retrieve the list so that you can display a graph based on stock data. The following is the provider method declaration:

[ConnectionProvider("Stock symbol provider", "StockProvider")]public string GetStockSymbols(){

// Method logicreturn Symbols;

}

Which method declaration should you use to retrieve data from the web part?

1. [ConnectionConsumer("Stock symbol provider", "StockConsumer")]public string GetStockSymbols(){

// Method logicreturn Symbols;

}

2. [ConnectionProvider("Stock symbol provider", "StockConsumer")]public string GetStockSymbols(){

// Method logicreturn Symbols;

}

3. [ConnectionProvider("Stock symbol provider", "StockConsumer")]public void GetStockSymbols(){

// Method logic}

4. [ConnectionConsumer("Stock symbol provider", "StockConsumer")]public void GetStockSymbols(){

// Method logic}

<Correct>

Explanation:To receive data from a web part connection provider, create a method that accepts as a parameter the same data type the provider returns. The method should not return a value. Then add the ConnectionConsumer attribute to the method.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Create page layout

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 5 - Lesson 3

Page 34: 70-515 chapter7

Web Parts Connections OverviewMSDN LibraryLink: http://msdn.microsoft.com/library/ms178187.aspx

ASP.NET Web Parts ControlsMSDN LibraryLink: http://msdn.microsoft.com/library/e0s9t4ck.aspx

Page 35: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 31 (515P_2.2_04)

______________________________________________________________________________________________________________________________________________

You are creating an ASP.NET webpage that uses web parts. You need to configure a static connection between a web part named CollectPostalCode that collects the user's postal code and a web part named CalculateShipping that provides shipping costs based on the user's postal code.

Which code segment should you use to connect the web parts?

1. <asp:WebPartManager ID="WebPartManager1" runat="server"><asp:StaticConnections

ID="conn1"ProviderID="CollectPostalCode"ProviderConnectionPointID="PostalCodeProvider"ConsumerID="CalculateShipping"ConsumerConnectionPointID="PostalCodeConsumer"

/></asp:WebPartManager>

2. <asp:WebPartManager ID="WebPartManager1" runat="server"><StaticConnections>

<asp:WebPartConnection><ID="conn1"><ProviderID="CollectPostalCode"><ProviderConnectionPointID="PostalCodeProvider"><ConsumerID="CalculateShipping"><ConsumerConnectionPointID="PostalCodeConsumer">

</asp:WebPartConnection></StaticConnections>

</asp:WebPartManager>

3. <asp:WebPartManager ID="WebPartManager1" runat="server"><StaticConnections>

<asp:WebPartConnectionID="conn1"ProviderID="CollectPostalCode"ProviderConnectionPointID="PostalCodeProvider"ConsumerID="CalculateShipping"ConsumerConnectionPointID="PostalCodeConsumer"

/></StaticConnections>

</asp:WebPartManager> <Correct>

4. <asp:WebPartManager ID="WebPartManager1" runat="server"><StaticConnections

ID="conn1"ProviderID="CollectPostalCode"ProviderConnectionPointID="PostalCodeProvider"ConsumerID="CalculateShipping"ConsumerConnectionPointID="PostalCodeConsumer"

/></asp:WebPartManager>

Explanation:To declare a static connection, within the WebPartManager control source code, add a <StaticConnections> element that includes a WebPartConnection control to declare the connection between the provider and consumer. The WebPartConnection control must have an ID attribute, an attribute to identify the provider control (ProviderID), an attribute to identify the provider method (ProviderConnectionPointID), an attribute to identify the consumer control (ConsumerID), and an attribute to identify the consumer method (ConsumerConnectionPointID).

Page 36: 70-515 chapter7

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Create page layout

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 5 - Lesson 3

Web Parts Connections OverviewMSDN LibraryLink: http://msdn.microsoft.com/library/ms178187.aspx

ASP.NET Web Parts ControlsMSDN LibraryLink: http://msdn.microsoft.com/library/e0s9t4ck.aspx

Page 37: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 32 (515P_2.2_05)

______________________________________________________________________________________________________________________________________________

You are creating an ASP.NET website that uses web parts. You need to choose the most efficient method of allowing website administrators to edit web parts on a page so that edits are visible to all users.

Which method should you choose?

1. Grant website administrators privileges to modify the source code, and allow website administrators to change the default settings.

2. Add a ConnectionsZone control to the page.

3. Add an <allow verbs="enterSharedScope"> element to the <system.web><authorization> section of the Web.config file.<Correct>

4. Set the SharedScope attribute of the WebPartsManager control to true.

Explanation:To enable shared personalization, within the <system.web> section of the configuration file, add an <authorization> section, and within that, add an <allow> element to specify which user or users have access to shared personalization scope.

The ConnectionsZone control enables users to manually establish connections, but does not enable shared personalization.

You cannot configure the WebPartsManager control to enable shared personalization.

While you could grant administrators the rights to modify the source code, most administrators do not have a developer skill set. Therefore, they would likely cause problems by editing the source code.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Create page layout

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 5 - Lesson 3

ASP.NET Web Parts ControlsMSDN LibraryLink: http://msdn.microsoft.com/library/e0s9t4ck.aspx

authorization Element for personalization for webParts (ASP.NET Settings Schema)MSDN LibraryLink: http://msdn.microsoft.com/library/ms228321.aspx

Page 38: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 33 (515P_2.5_01)

______________________________________________________________________________________________________________________________________________

You are creating a custom server control that derives from the Label control and displays the text stored in the Text property when the control is rendered. The text might include less than (<) or greater than (>) symbols. You want to ensure that those symbols are displayed in the browser and not rendered as HTML.

Which implementation of RenderContents should you use?

1. protected override void RenderContents(HtmlTextWriter writer){

writer.WriteEncodedText(Text);}

<Correct>

2. protected override void RenderContents(){

Response.Write(Text);}

3. protected override void RenderContents(){

Trace.Write(Text);}

4. protected override void RenderContents(HtmlTextWriter writer){

writer.WriteLine(Text);}

Explanation:To render the contents of a property in a custom control, use the HtmlTextWriter object that is passed to the RenderContents method and call the WriteEncodedText method. This properly renders the text, including converting the < symbol to &lt and the > symbol to &gt.

You could call HtmlTextWriter.WriteLine; however, that would pass the property's contents directly to the browser without encoding. Therefore, the < and > symbols would be treated as HTML.

You cannot access the Response or Trace objects from within a custom server control.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Manipulate user interface controls from code-behind

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 7 - Lesson 1

Walkthrough: Developing and Using a Custom Web Server ControlMSDN LibraryLink: http://msdn.microsoft.com/library/yhzc935f.aspx

Page 39: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 34 (515P_2.5_02)

______________________________________________________________________________________________________________________________________________

You are creating an ASP.NET webpage that uses the Login control to collect user credentials. The Login1 control is functioning properly, but the background color defined in the .css file is not taking effect. You examine the HTML source code of the rendered page, shown in the exhibit.

Which method should you use to allow the styles defined by the .css file to control the appearance of the wizard as expected?

1. Set the Login1.RenderOuterTable property to False. <Correct>

2. Remove the <table> definition containing the style element from the .aspx page.

3. Set the Login1.TextLayout property to True.

4. Set the Login1.RenderOuterTable property to True.

Explanation:ASP.NET 4.0 adds a new property to some controls: RenderOuterTable. By default, RenderOuterTable is set to True, which causes the control to behave exactly as it did in earlier versions of ASP.NET. If you set this property to False, ASP.NET removes the outer <table> element from the control's rendering, which is used only to apply inline styles. Removing this outer table makes it easier to define the appearance of a control using style sheets.

The <table> definition does not appear in the .aspx page; it is created only when ASP.NET renders the control.

The TextLayout property defines whether text is aligned with the left or top of the control. It does not define the style of the control.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Manipulate user interface controls from code-behind

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 4 - Lesson 1

ASP.NET 4 and Visual Studio 2010 Web Development OverviewMicrosoft ASP.NETLink: http://www.asp.net/learn/whitepapers/aspnet4

Login.RenderOuterTable PropertyMSDN LibraryLink: http://msdn.microsoft.com/library/system.web.ui.webcontrols.login.renderoutertable.aspx

Page 40: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 35 (515P_2.5_03)

______________________________________________________________________________________________________________________________________________

You are upgrading an ASP.NET 3.5 application to ASP.NET 4.0. You use the automated tools built into Microsoft Visual Studio 2010 to perform the upgrade process, and the application seems to work correctly.

While examining the rendered HTML to verify compatibility with the latest standards, you notice some HTML that was not present in your natively developed ASP.NET 4.0 applications. Specifically, Table and Image controls have a border="0" property, even though the border property is not defined. You add the same controls to a native ASP.NET 4.0 application, and the border property does not appear in the rendered HTML.

Which method should you use to remove the border property from the upgraded application?

1. Set the RenderOuterTable property of the Table and Image controls to False.

2. Replace the application's outdated browser definition files with those included with ASP.NET 4.0.

3. Remove <pages controlRenderingCompatibilityVersion="3.5" /> from the Web.config file. <Correct>

4. Set the RenderOuterTable property of the Table and Image controls to True.

Explanation:If you use Visual Studio 2010 to upgrade an application to ASP.NET 4.0, Visual Studio sets the Pages.controlRenderingCompatibilityVersion to 3.5. This causes ASP.NET to use the older rendering engine. If you want to take advantage of ASP.NET 4.0 rendering improvements (including the unnecessary border="0" property), set the controlRenderingCompatibilityVersion property to 4.0. Alternatively, you can simply remove it, because it defaults to 4.0.

Some controls, such as the Login control, render an outer table for inline styles. ASP.NET 4.0 adds the RenderOuterTable property to these controls to allow you to disable this outer table. However, this is not related to the unnecessary border property for Table and Image controls.

Browser definition files define capabilities of different browsers, and can impact how controls are rendered. However, the border property described in this scenario is not controlled by the browser definition file.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Manipulate user interface controls from code-behind

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 4 - Lesson 1

ASP.NET 4 and Visual Studio 2010 Web Development OverviewMicrosoft ASP.NETLink: http://www.asp.net/learn/whitepapers/aspnet4

ASP.NET 4 Breaking ChangesMicrosoft ASP.NETLink: http://www.asp.net/%28S%28ywiyuluxr3qb2dfva1z5lgeg%29%29/learn/whitepapers/aspnet4/breaking-changes#0.1__Toc256770141

Page 41: 70-515 chapter7

Web Applications Development with Microsoft .NET Framework 4 - C#

Question Number (ID) : 36 (515P_2.5_04)

______________________________________________________________________________________________________________________________________________

You create a web form that includes three buttons. You configure the Click event for each button to invoke the following event handler.

private void Button_Click(object sender, System.EventArgs e){}

You need to add code to the event handler to set the text of a label named Label1 to the identifier of the clicked button.

Which code segment should you add?

1. Button b = (Button) sender;Label1.Text = b.ID; <Correct>

2. Button b = (Button) e;Label1.Text = b.ID;

3. Label1.Text = e.ToString();

4. Label1.Text = sender.ToString();

Explanation:The sender argument gives the control that invoked the event. Cast to a Button to examine the ID property.

The ToString method of the Button control will not give the ID.

The EventArgs argument does not give the control that invoked the event.

Objective:Developing and Using Web Forms Controls

Sub Objective(s):Manipulate user interface controls from code-behind

References:

MCTS Self-Paced Training Kit (Exam 70-515): Web Applications Development with Microsoft .NET Framework 4Chapter 4 - Lesson 1

How to: Connect Multiple Events to a Single Event Handler in ASP.NET Web PagesMSDN LibraryLink: http://msdn.microsoft.com/library/ycbsc785.aspx