TS: Web Applications Development with Microsoft .NET Framework 4

QUESTION NO: 1

You are creating an ASP.NET Web site. The site has a master page named Custom.master. The code-behind file for Custom.master contains the following code segment.

C:\Documents and Settings\usernwz1\Desktop\1.JPG

You create a new ASP.NET page and specify Custom.master as its master page.

You add a Label control named lblRegion to the new page.

You need to display the value of the master page's Region property in lblRegion.

What should you do?

A. Add the following code segment to the Page_Load method of the page code-behind file.

Dim custom As Custom = Me.Parent

lblRegion.Text = custom.Region

B. Add the following code segment to the Page_Load method of the page code-behind file.

Dim custom As Custom = Me.Master

lblRegion.Text = custom.Region

C. Add the following code segment to the Page_Load method of the Custom.Master.vb code-behind file.

Dim lblRegion As Label = Page.FindControl("lblRegion")

lblRegion.Text = Me.Region

D. Add the following code segment to the Page_Load method of the Custom.Master.vb code-behind file.

Dim lblRegion As Label = Master.FindControl("lblRegion")

lblRegion.Text = Me.Region

Answer: B

Explanation:

http://www.test4pass.com/70-515-exam.html

http://pdf.it-pruefungen.de/70-515.pdf

http://www.slideshare.net/bhupey/latest-70-515-exam-braindumps

....

QUESTION NO: 2

You have created an ASP.NET server control named ShoppingCart for use by other developers. Some developers report that the ShoppingCart control does not function properly with ViewState disabled. You want to ensure that all instances of the ShoppingCart control work even if ViewState is disabled. What should you do?

A. Require developers to set EnableViewStateMac to true.

B. Store state in ControlState instead of ViewState.

C. Serialize the state into an Application state entry called "MyControl".

D. Require developers to change the session state mode to SQLServer.

Answer: B

QUESTION NO: 3

You are implementing an ASP.NET Web site that will be accessed by an international audience. The site contains global and local resources for display elements that must be translated into the language that is selected by the user. You need to ensure that the Label control named lblCompany displays text in the users selected language from the global resource file. Which control markup should you use?

A. <asp:Label ID="lblCompany" runat="server"

meta:resourcekey="lblCompany" />

B. <asp:Label ID="lblCompany" runat="server"

Text="meta:lblCompany.Text" />

C. <asp:Label ID="lblCompany" runat="server"

Text="<%$ Resources:lblCompanyText %>" />

D. <asp:Label ID="lblCompany" runat="server"

Text="<%$ Resources:WebResources, lblCompanyText %>" />

Answer: D

QUESTION NO: 4

You are developing an ASP.NET Web page that contains input controls, validation controls, and a button named btnSubmit.

The page has the following code-behind. (Line numbers are included for reference only.)

01 Public Class _Default

02 Inherits System.Web.UI.Page

03

04 Protected Sub SaveToDatabase()

05

06 End Sub

07

08 Protected Sub btnSubmit_Click(ByVal sender As Object,

09 ByVal e As EventArgs) Handles btnSubmit.Click

10

11 End Sub

12

13 End Class

You need to ensure that all data that is submitted passes validation before the data is saved in a database. What should you do?

A. Add the following method override.

Protected Overrides Sub OnInit(ByVal e As EventArgs)

MyBase.OnInit(e)

If (Page.IsValid) Then Me.SaveToDatabase()

End Sub

B. Add the following method override.

Protected Overrides Sub OnLoad(ByVal e As EventArgs)

MyBase.OnLoad(e)

If (Page.IsValid) Then Me.SaveToDatabase()

End Sub

C. Add the following method override.

Protected Overrides Sub OnPreRender(ByVal e As EventArgs)

MyBase.OnPreRender(e)

If (Page.IsValid) Then Me.SaveToDatabase()

End Sub

D. Add the following code segment at line 10.

If (Page.IsValid) Then Me.SaveToDatabase()

Answer: D

QUESTION NO: 5

You are implementing an ASP.NET application that uses data-bound GridView controls in multiple pages. You add JavaScript code to periodically update specific types of data items in these GridView controls. You need to ensure that the JavaScript code can locate the HTML elements created for each row in these GridView controls, without needing to be changed if the controls are moved from one page to another. What should you do?

A. Replace the GridView control with a ListView control.

B. Set the ClientIDMode attribute to Predictable in the web.config file.

C. Set the ClientIDRowSuffix attribute of each unique GridView control to a different value.

D. Set the @ OutputCache directives VaryByControl attribute to the ID of the GridView control.

Answer: C

QUESTION NO: 6

You are developing an ASP.NET Web application. You create a master page. The master page requires a region where you can add page-specific content by using the ASP.NET page designer. You need to add a control to the master page to define the region.

Which control should you add?

A. Content

B. ContentPlaceHolder

C. PlaceHolder

D. Substitution

Answer: B

Explanation:

http://www.scribd.com/selftestengine/d/58942161-MICROSOFT-70-515CSHARP

http://content.yudu.com/Library/A1sxix/BeITCertifiedMicroso/resources/3.htm

http://freedownload.is/pdf/sample-exam-70-515-pdf-questions-790464.html

QUESTION NO: 7

You create an ASP.NET page named TestPage.aspx that contains validation controls.

You need to verify that all input values submitted by the user have been validated by testing the Page.IsValid property.

Which page event should you add an event handler to?

A. Init

B. Load

C. PreInit

D. PreLoad

Answer: B

QUESTION NO: 8

You are developing an ASP.NET Web application.

Application data is stored in a Microsoft SQL Server 2008 database. You configure a connection string named cnnContoso. The application must cache the data that is returned from the database by using this connection string.

You need to ensure that the application checks the database every 10 seconds.

What should you do?

A. Add the following configuration to the <system.web> section of the web.config file.

<caching>

<outputCacheSettings>

<outputCacheProfiles>

<add name="cnnContoso"

duration="10" />

</outputCacheProfiles>

</outputCacheSettings>

</caching>

B. Add the following configuration to the <system.web> section of the web.config file.

<caching>

<sqlCacheDependency enabled="true" pollTime="10000">

<databases>

<add name="ContosoDatabase"

connectionStringName="cnnContoso" />

</databases>

</sqlCacheDependency>

</caching>

C. Add the following @ Page directive to pages that query the database.

<%@ OutputCache Duration="10"

VaryByParam="cnnContoso" %>

D. Add the following @ Page directive to pages that query the database.

<%@ OutputCache Duration="10000"

VaryByParam="cnnContoso" %>

Answer: B

QUESTION NO: 9

You are troubleshooting an ASP.NET Web application. System administrators have recently expanded your web farm from one to two servers. Users are periodically reporting an error message about invalid view state.

You need to fix the problem.

What should you do?

A. Set viewStateEncryptionMode to Auto in web.config on both servers.

B. Set the machineKey in machine.config to the same value on both servers.

C. Change the session state mode to SQLServer on both servers and ensure both servers use the same connection string.

D. Override the SavePageStateToPersistenceMedium and LoadPageStateFromPersistenceMedium methods in the page base class to serialize the view state to a local web server file.

Answer: B

QUESTION NO: 10

You are implementing an ASP.NET application that includes a page named TestPage.aspx. TestPage.aspx uses a master page named

TestMaster.master.

You add the following code to the TestPage.aspx code-behind file to read a TestMaster.master public property named CityName.

Protected Sub Page_Load(ByVal sender As Object,

ByVal e As System.EventArgs) Handles Me.Load

Dim s As String = Master.CityName

End Sub

You need to ensure that TestPage.aspx can access the CityName property. What should you do?

A. Add the following directive to TestPage.aspx.

<%@ MasterType VirtualPath="~/TestMaster.master" %>

B. Add the following directive to TestPage.aspx.

<%@ PreviousPageType VirtualPath="~/TestMaster.master" %>

C. Set the Strict attribute in the @ Master directive of the TestMaster.master page to true.

D. Set the Explicit attribute in the @ Master directive of the TestMaster.master page to true.

Answer: A

QUESTION NO: 11

You create a new ASP.NET MVC 2 Web application. The following default routes are created in the Global.asax.vb file. (Line numbers are included for reference only.)

01 Shared Sub RegisterRoutes(ByVal routes As RouteCollection)

02

03 routes.IgnoreRoute("{resource}.axd/{*pathInfo}")

04

05 routes.MapRoute(

"Default",

"{controller}/{action}/{id}",

New With {.controller = "Home", .action = "Index", .id = ""}

)

06 End Sub

You implement a controller named HomeController that includes methods with the following signatures.

Function Index() As ActionResult

Function Details(ByVal id As Integer) As ActionResult

Function DetailsByUsername(

ByVal username As String) As ActionResult

You need to add a route to meet the following requirements.

• The details for a user must be displayed when a user name is entered as the path by invoking the DetailsByUsername action.

• User names can contain alphanumeric characters and underscores, and can be between 3 and 20 characters long.

What should you do?

A. Replace line 05 with the following code segment.

routes.MapRoute("Default", "{controller}/{action}/{id}", New With {.controller = "Home", .action = "DetailsByUsername",.id = ""})

B. Replace line 05 with the following code segment.

routes.MapRoute( "Default", "{controller}/{action}/{username}", New With {.controller = "Home", .action = "DetailsByUsername", .username = ""},New With {.username = "\w{3,20}"})

C. At line 04, add the following code segment.

routes.MapRoute("Details by Username","{username}", New With {.controller = "Home", .action = "DetailsByUsername"}, New With {.username = "\w{3,20}"} )

D. At line 04, add the following code segment.

routes.MapRoute( "Details by Username", "{id}", New With {.controller = "Home", .action = "DetailsByUsername"},New With {.id = "\w{3,20}"} )

Answer: C

QUESTION NO: 12

You are implementing an ASP.NET MVC 2 Web application that contains several folders.

The Views/Shared/DisplayTemplates folder contains a templated helper named Score.ascx that performs custom formatting of integer values.

The Models folder contains a class named Player with the following definition.

Public Class Player

Public Property Name As String

Public Property LastScore As Integer

Public Property HighScore As Integer

End Class

You need to ensure that the custom formatting is applied to LastScore values when the HtmlHelper.DisplayForModel method is called for any view in the application that has a model of type Player.

What should you do?

A. Rename Score.ascx to LastScore.ascx.

B. Move Score.ascx from the Views/Shared/DisplayTemplates folder to the Views/Player/DisplayTemplates folder.

C. Add the following attribute to the LastScore property.

<UIHint("Score")>

D. Add the following attribute to the LastScore property.

<Display(Name:="LastScore", ShortName:="Score")>

Answer: C

QUESTION NO: 13

You are implementing an ASP.NET MVC 2 application. In the Areas folder, you add a subfolder named Product to create a single project area.

You add files named ProductController.vb and Index.aspx to the appropriate subfolders.

You then add a file named Route.vb to the Product folder that contains the following code. (Line numbers are included for reference only.)

01 Public Class Route

Inherits AreaRegistration

02

03 Public Overrides ReadOnly Property AreaName As String

04 Get

05 Return "product"

06 End Get

07 End Property

08

09 Public Overrides Sub RegisterArea(

ByVal context As AreaRegistrationContext)

10

11 context.MapRoute("product_default",

"product/{controller}/{action}/{id}",

New With {.controller = "Product", .action = "Index",

.id = ""})

12

13 End Sub

End Class

When you load the URL http://<applicationname>/product, you discover that the correct page is not returned. You need to ensure that the correct page is returned.

What should you do?

A. Replace line 11 with the following code segment.

context.MapRoute("product_default",

"{area}/{controller}/{action}/{id}",

New With {.area = "product", .controller = "Product",

.action = "Index", .id = ""})

B. Replace line 11 with the following code segment.

context.MapRoute("product_default",

"{area}",

New With {.controller = "Product", .action = "Index", .id = ""})

C. Add the following code segment at line 12.

AreaRegistration.RegisterAllAreas()

D. Add the following code segment to the RegisterRoutes method in the Global.asax.vb file.

AreaRegistration.RegisterAllAreas()

Answer: D

QUESTION NO: 14

You are implementing an ASP.NET MVC 2 Web application that contains the following class.

Public Class DepartmentController

Inherits Controller

Shared departments As List(Of Department) =

New List(Of Department)

Function Index() As ActionResult

Return View(departments)

End Function

Function Details(ByVal id As Integer) As ActionResult

Return View(departments.Find(Function(x) x.ID = id))

End Function

Function ListEmployees(ByVal d As Department) As ActionResult

Dim employees As List(Of Employee) = GetEmployees(d)

Return View (employees)

End Function

End Class

You create a strongly typed view that displays details for a Department instance. You want the view to also include a listing of department employees.

You need to write a code segment that will call the ListEmployees action method and output the results in place.

Which code segment should you use?

A. <%= Html.Action("ListEmployees", Model) %>

B. <%= Html.ActionLink("ListEmployees", "Department",

"DepartmentController") %>

C. <% Html.RenderPartial("ListEmployees", Model) %>

D. <%= Html.DisplayForModel("ListEmployees") %>

Answer: A

Explanation:

Html.Action(string, object) invokes a child action method and returns the result as an HTML string.

ChildActionExtensions.Action Method

(http://msdn.microsoft.com/en-s/library/system.web.mvc.html.childactionextensions.action.aspx)

Html.DisplayForModel() Method returns HTML markup for each property in the model.

Html.DisplayForModel(string, object) Method returns HTML markup for each property in the model, using the specified template and additional view data.

RenderPartialExtensions.RenderPartial Method

(http://msdn.microsoft.com/en-us/library/system.web.mvc.html.renderpartialextensions.renderpartial.aspx)

The ActionLink method renders an element that links to an action method.

LinkExtensions.ActionLink Method

(http://msdn.microsoft.com/en-us/library/system.web.mvc.html.linkextensions.actionlink.aspx)

QUESTION NO: 15

You are developing an ASP.NET MVC 2 Web application.

A page makes an AJAX request and expects a list of company names in the following format.

["Adventure Works","Contoso"]

You need to write an action method that returns the response in the correct format.

Which type should you return from the action method?

A. AjaxHelper

B. XDocument

C. JsonResult

D. DataContractJsonSerializer

Answer: C

QUESTION NO: 16

You are developing an ASP.NET MVC 2 Web application. The application contains a controller named HomeController, which has an action named Index. The application also contains a separate area named Blog. A view within the Blog area must contain an ActionLink that will link to the Index action of the HomeController. You need to ensure that the ActionLink in the Blog area links to the Index action of the HomeController. Which ActionLink should you use?

A. Html.ActionLink("Home", "Index", "Home")

B. Html.ActionLink("Home", "Index", "Home", New With {.area = ""}, Nothing)

C. Html.ActionLink("Home", "Index", "Home", New With {.area = "Blog"}, Nothing)

D. Html.ActionLink("Home", "Index", "Home", New With {.area = "Home"}, Nothing)

Answer: B

QUESTION NO: 17

You are implementing an ASP. NET MVC 2 Web application.

You add a controller named CompanyController.

You need to modify the application to handle the URL path /company/info.

Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)

A. Add the following method to the CompanyController class.

Function Info () As ActionResult

Return View()

End Function

B. Add the following method to the CompanyController class.

Function Company_Info() As ActionResult

Return View()

End Function

C. Right-click the Views folder, and select View from the Add submenu to create the view for the action.

D. Right-click inside the action method in the CompanyController class, and select Add View to create a view for the action.

Answer: A, D

Explanation:

CHAPTER 14 Creating Websites with ASP.NET MVC 2

Lesson 2: Creating Models, Views, and Controllers

Creating Controllers, Creating Views (page 851-857)

QUESTION NO: 18

You are creating an ASP.NET Web site. You create a HTTP module named CustomModule, and you register the module in the web.config file. The CustomModule class contains the following code.

C:\Documents and Settings\usernwz1\Desktop\1.JPG

You need to add code to CustomModule to append the footer content to each processed ASP.NET page.

Which code segment should you use?

A. Public Sub New(ByVal app As HttpApplication)

AddHandler app.EndRequest, AddressOf app_EndRequest

End Sub

Sub app_EndRequest(ByVal sender As Object, ByVal e As EventArgs)

Dim app As HttpApplication = TryCast(sender, HttpApplication)

app.Response.Write(footerContent)

End Sub

B. Public Sub Init(ByVal app As HttpApplication) _ Implements IHttpModule.Init

AddHandler app.EndRequest, AddressOf app_EndRequest

End Sub

Sub app_EndRequest(ByVal sender As Object, ByVal e As EventArgs)

Dim app As HttpApplication = New HttpApplication()

app.Response.Write(footerContent)

End Sub

C. Public Sub New()

Dim app As HttpApplication = New HttpApplication()

AddHandler app.EndRequest, AddressOf app_EndRequest

End Sub

Sub app_EndRequest(ByVal sender As Object, ByVal e As EventArgs)

Dim app As HttpApplication = TryCast(sender, HttpApplication)

app.Response.Write(footerContent)

End Sub

D. Public Sub Init(ByVal app As HttpApplication) _ Implements IHttpModule.Init

AddHandler app.EndRequest, AddressOf app_EndRequest

End Sub

Sub app_EndRequest(ByVal sender As Object, ByVal e As EventArgs)

Dim app As HttpApplication = TryCast(sender, HttpApplication)

app.Response.Write(footerContent)

End Sub

Answer: D

QUESTION NO: 19

You are implementing an ASP.NET Web site. The root directory of the site contains a page named Error.aspx. You need to display the Error.aspx page if an unhandled error occurs on any page within the site. You also must ensure that the original URL in the browser is not changed.

What should you do?

A. Add the following configuration to the web.config file.

<system.web>

<customErrors mode="On">

<error statusCode="500" redirect="~/Error.aspx" />

</customErrors>

</system.web>

B. Add the following configuration to the web.config file.

<system.web>

<customErrors redirectMode="ResponseRewrite"

mode="On" defaultRedirect="~/Error.aspx" />

</system.web>

C. Add the following code segment to the Global.asax file.

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)

Response.Redirect("~/Error.aspx")

End Sub

D. Add the following code segment to the Global.asax file.

Protected Sub Page_Load(ByVal sender As Object,

ByVal e As System.EventArgs) Handles Me.Load

Server.Transfer("~/Error.aspx")

End Sub

Answer: B

QUESTION NO: 20

You are implementing an ASP.NET Web application. Users will authenticate to the application with an ID.

The application will allow new users to register for an account. The application will generate an ID for the user based on the users full name.

You need to implement this registration functionality.

Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)

A. Configure the SqlMembershipProvider in the web.config file.

B. Configure the SqlProfileProvider in the web.config file.

C. Create an ASP.NET page that contains a default CreateUserWizard control to create a new user account.

D. Create an ASP.NET page that contains a custom form that collects the user information and then uses the Membership.CreateUser method to create a new user account.

Answer: A, D

Explanation:

CHAPTER 13 Implementing User Profiles, Authentication, and Authorization

Lesson 1: Working with User Profiles

SqlMembershipProvider Class (http://msdn.microsoft.com/en-us/library/system.web.security.

sqlmembershipprovider.aspx)

QUESTION NO: 21

You deploy an ASP.NET application to an IIS server.

You need to log health-monitoring events with severity level of error to the Windows application event log.

What should you do?

A. Run the aspnet_regiis.exe command.

B. Select the Treat all warnings as errors option in the project properties and recompile.

C. Add the following rule to the healthMonitoring section of the web.config file.

<rules><add name="Failures"eventName="Failure Audits"provider="EventLogProvider" />

</rules>

D. Add the following rule to the healthMonitoring section of the web.config file.

<rules><add name="Errors"eventName="All Errors"provider="EventLogProvider" />

</rules>

Answer: D

QUESTION NO: 22

You are creating an ASP.NET Web site. The site is configured to use Membership and Role management providers.

You need to check whether the currently logged-on user is a member of a role named Administrators.

Which code segment should you use?

A. Dim isMember As Boolean =

Roles.GetUsersInRole ("Administrators").Any()

B. Dim isMember As Boolean =

Membership.ValidateUser ( User.Identity.Name , "Administrators")

C. Dim isMember As Boolean =

Roles.GetRolesForUser ("Administrators").Any ()

A. Dim isMember As Boolean = User.IsInRole ("Administrators")

Answer: D

QUESTION NO: 23

You are creating an ASP.NET Web application. The application must call a WCF service by using a WCF routing service. You need to ensure that the application can invoke the target service by using the router endpoint.

What should you do?

A. Add a service reference to the router service. In the client binding configuration, specify the address of the router service.

B. Add a service reference to the target service. In the client binding configuration, specify the address of the target service.

C. Add a service reference to the router service. In the client binding configuration, specify the address of the target service.

D. Add a service reference to the target service. In the client binding configuration, specify the address of the router service.

Answer: D

QUESTION NO: 24

You are deploying an ASP.NET Web application to a remote server.

You need to choose a deployment method that will ensure that all IIS settings, in addition to the Web content, will deploy to the remote server.

Which deployment method should you choose?

A. the XCOPY command-line tool

B. the Copy Web Site tool

C. the Web Deployment tool

D. the Publish Web Site utility

Answer: C

QUESTION NO: 25

You use the ASP.NET Web Application template to create an application in a new Visual Studio solution. The project uses types that are defined in a class library project. Source code for the class library is frequently modified. You need to ensure that classes in the Web application project always reference the most recent version of the class library types. What should you do?

A. Add the class library project to the solution. Modify the class library project to add a reference to the Web application project.

B. Add the class library project to the solution. Modify the Web application project to add a reference to the class library project.

C. Add a post-build step to the Web application project that copies the most recent version of the class library assembly to the bin folder of the Web application.

D. Add a post-build step to the class library project that copies the most recent version of the class library assembly to the App_Code folder of the Web application. In the <compilation /> section of the web.config file, add an <assembly /> entry that specifies the location of the class library assembly.

Answer: B

QUESTION NO: 26

You are developing an ASP.NET Web page.

The page contains the following markup.

<asp:GridView ID="gvModels" runat="server"

onrowdatabound="gvModels_RowDataBound"

AutoGenerateColumns="false">

<Columns>

<asp:BoundField DataField="Name" HeaderText="Model" />

<asp:TemplateField>

<ItemTemplate>

<asp:Image ID="img" runat="server" />

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

The pages code-behind file includes the following code segment. (Line numbers are included for reference only.)

01 Private Sub gvModels_RowDataBound(ByVal sender As Object, _

02 ByVal e As GridViewRowEventArgs) _

03 Handles gvModels.RowDataBound

04 If (e.Row.RowType = DataControlRowType.DataRow) Then

05 Dim cm As CarModel =

06 DirectCast(e.Row.DataItem, CarModel)

07

08 img.ImageUrl =

09 String.Format("images/{0}.jpg", cm.ID)

10

11 End If

12 End Sub

You need to get a reference to the Image named img.

Which code segment should you add at line 07?

A. Dim img As Image =

DirectCast(Page.FindControl("img"), Image)

B. Dim img As Image =

DirectCast(e.Row.FindControl("img"), Image)

C. Dim img As Image =

DirectCast(gvModels.FindControl("img"), Image)

D. Dim img As Image =

DirectCast(Page.Form.FindControl("img"), Image)

Answer: B

QUESTION NO: 27

You use the following declaration to add a Web user control named TestUserControl.ascx to an ASP.NET page named TestPage.aspx.

<uc:TestUserControl ID="testControl" runat="server"/>

You add the following code to the code-behind file of TestPage.aspx.

Private Sub TestMethod()

End Sub

You define the following delegate.

Public Delegate Sub MyEventHandler()

You need to add an event of type MyEventHandler named MyEvent to TestUserControl.ascx and attach the pages TestMethod method to the event.

Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)

A. Add the following line of code to TestUserControl.ascx.vb.

Public Event MyEvent As MyEventHandler

B. Add the following line of code to TestUserControl.ascx.vb.

Public MyEvent As MyEventHandler

C. Replace the TestUserControl.ascx reference in TestPage.aspx with the following declaration.

<uc:TestUserControl ID="testControl" runat="server"

OnMyEvent="TestMethod"/>

D. D. Replace the TestUserControl.ascx reference in TestPage.aspx with the following declaration.

<uc:TestUserControl ID="testControl" runat="server"

MyEvent="TestMethod"/>

Answer: A, C

Explanation:

CHAPTER 7 Creating Custom Web Controls

Lesson 1: Creating User Controls

Defining User Control Events (page 333-337)

QUESTION NO: 28

You are implementing an ASP.NET page that includes a text box.

You need to validate values that are typed by users to ensure that only numeric values are submitted.

Which control markup should you use?

A. <asp:TextBox ID="txt1" runat="server"

CausesValidation="true"

ValidationGroup="Numeric" />

B. <asp:TextBox ID="txt1" runat="server"

EnableClientScript="true"

ValidationGroup="Numeric" />

C. <asp:TextBox ID="txt1" runat="server" />

<asp:RegularExpressionValidator ID="val1"

runat="server"

ControlToValidate="txt1"

ValidationExpression="[0-9]*"

ErrorMessage="Invalid input value" />

D. <asp:TextBox ID="txt1" runat="server" />

<asp:RegularExpressionValidator ID="val1"

EnableClientScript="true"

ControlToValidate="txt1"

ValidationExpression="[0-9]*"

ErrorMessage="Invalid input value" />

Answer: C

Explanation:

JavaScript executes as users enter and leave the focus of the controls on your page. Client-side validation is turned on by default. You can turn it off for specific validation controls by setting the EnableClientScript property to false.

CHAPTER 5 Input Validation and Site Navigation

Lesson 1: Performing Input Validation

Client-Side Validation (page 231)

QUESTION NO: 29

You are implementing an ASP.NET Web site that uses a custom server control named Task. Task is defined as shown in the following list:

  • Class name: Task

  • Namespace: DevControls

  • Assembly: TestServerControl.dll

  • Base class: System.Web.UI.WebControls.WebControl

You copy TestServerControl.dll to the Web sites Bin folder.

You need to allow the Task control to be declaratively used on site pages that do not contain an explicit @ Register directive.

Which configuration should you add to the web.config file?

A. <appSettings>

<add key="Dev:Task"

value="DevControls, DevControls.Task"/>

</appSettings>

B. <compilation targetFramework="4.0" explicit="false">

<assemblies>

<add assembly="TestServerControl" />

</assemblies>

</compilation>

C. <pages>

<controls>

<add assembly="TestServerControl" namespace="DevControls"

tagPrefix="Dev"/>

</controls>

</pages>

D. <pages>

<tagMapping>

<add tagType="System.Web.UI.WebControls.WebControl"

mappedTagType="DevControls.Task"/>

</tagMapping>

</pages>

Answer: C

Explanation:

CHAPTER 7 Creating Custom Web Controls

Lesson 2: Creating Custom Web Server Controls

Registering Your Controls in Web.config (page 378-379)

QUESTION NO: 30

You are implementing an ASP.NET Web page.

You need to add a text box that allows only values between 1 and 10, inclusive, to be submitted.

Which two code segments should you use? (Each correct answer presents part of the solution. Choose two.)

A. <script type="text/javascript">

function validate_value(obj, args) {

return

(args.Value >= 1 && args.Value <= 10);

}

</script>

B. <script type="text/javascript">

function validate_value(obj, args) {

args.IsValid =

(args.Value >= 1 && args.Value <= 10);

}

</script>

C. <asp:TextBox ID="txt1" runat="server" />

<asp:CustomValidator ID="val1" runat="server"

ControlToValidate="txt1"

ClientValidationFunction="validate_value"

ErrorMessage="Value invalid" />

D. <asp:TextBox ID="txt1" runat="server" onChange="validate_value(this, args)" />

Answer: B, C

Explanation:

CHAPTER 5 Input Validation and Site Navigation

Lesson 1: Performing Input Validation

The CustomValidator Control

QUESTION NO: 31

You are implementing a Web page that allows users to upload files to a Web server. The page includes a form that has a Submit button.

You need to reject files larger than 1 MB.

What should you do?

A. Add an HTML input type= file control. Add an onSubmit handler to the form to check the file size and cancel the form submission if the file size is too large.

B. Add an HTML input type= file control. Add an onChange handler to the input control to check the file size and cancel the upload if the file size is too large.

C. Add an ASP.NET FileUpload control and configure it to run on the server. Add a server-side OnClick handler to the form's Submit button to save the file only if the file size is allowed.

D. Add an ASP.NET FileUpload control and configure it to run on the server. Add a server-side OnDataBinding handler that saves the file only if the file size is allowed.

Answer: C

QUESTION NO: 32

You are developing an ASP.NET Web page.

You add the following markup to the page.

<asp:FileUpload id="FileUpload1" runat="server" />

<asp:Button id="btnUpload" Text="Upload selected file"

OnClick="btnUpload_Click" runat="server" />

<asp:Label id="lblFeedback" runat="server" />

You add the following code segment to the code-behind. (Line numbers are included for reference only.)

01 Protected Sub btnUpload_Click(ByVal sender As Object,

02 ByVal e As EventArgs) Handles btnUpload.Click

03 If () Then

04 Dim saveName As String =

05 Path.Combine("c:\uploadedfiles\",

06 FileUpload1.FileName)

07

08 lblFeedback.Text = "File successfully uploaded."

09 Else

10 lblFeedback.Text = "File upload failed."

11 End If

12

13 End Sub

You need to save the uploaded file and display a message to the user that indicates that the upload either succeeded or failed.

Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)

A. Replace line 03 with the following code segment.

If (FileUpload1.HasFile) Then

B. Replace line 03 with the following code segment.

If (FileUpload1.FileContent.Length > 0) Then

C. Insert the following code segment at line 07.

FileUpload1.SaveAs(saveName)

D. Insert the following code segment at line 07.

FileUpload1.FileContent.CopyTo(

New FileStream(saveName, FileMode.Open))

Answer: A, C

Explanation:

CHAPTER 4 Using Server Controls

Lesson 2: Exploring Specialized Server Controls

The FileUpload Control (page 202-204)

QUESTION NO: 33

You create a Web page named TestPage.aspx and a user control named TestUserControl. ascx. TestPage.aspx uses TestUserControl.ascx as shown in the following line of code.

<uc:TestUserControl ID="testControl" runat="server"/>

On TestUserControl.ascx, you need to add a read-only member named CityName to return the value "New York". You also must add code to TestPage.aspx to read this value.

Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)

A. Add the following line of code to the TestUserControl.ascx.vb code-behind file.

Public ReadOnly Property CityName As String

Get

Return "New York"

End Get

End Property

B. Add the following line of code to the TestUserControl.ascx.vb code-behind file.

Protected ReadOnly CityName As String = "New York"

C. Add the following code segment to the TestPage.aspx.vb code-behind file.

Protected Sub Page_Load(ByVal sender As Object,

ByVal e As System.EventArgs) Handles Me.Load

Dim s As String = testControl.CityName

End Sub

D. Add the following code segment to the TestPage.aspx.vb code-behind file.

Protected Sub Page_Load(ByVal sender As Object,

ByVal e As System.EventArgs) Handles Me.Load

Dim s As String = testControl.Attributes("CityName")

End Sub

Answer: A, C

Explanation:

CHAPTER 7 Creating Custom Web Controls

Lesson 1: Creating User Controls

Defining Properties in User Controls (page 337-339)

QUESTION NO: 34

You are developing an ASP.NET MVC 2 application. A view contains a form that allows users to submit their first name.

You need to display the value that is submitted, and you must ensure that your code avoids cross-site scripting.

Which code segment should you use?

A. <%: Model.FirstName%>

B. <%= Model.FirstName %>

C. <% Response.Write(Model.FirstName)%>

D. <% Response.Write(HttpUtility.HtmlDecode( Model.FirstName))%>

Answer: A

Explanation:

CHAPTER 14 Creating Websites with ASP.NET MVC 2

Lesson 2: Creating Models, Views, and Controllers

Creating Views - Creating Strongly Typed Views (page 859)

QUESTION NO: 35

You are implementing an ASP.NET AJAX page.

You add two UpdatePanel controls named pnlA and pnlB. pnlA contains an UpdatePanel control named pnlAInner in its content template.

You have the following requirements.

Update panels pnlA and pnlB must refresh their content only when controls that they contain cause a postback.

Update panel pnlAInner must refresh its content when controls in either pnlA or pnlB or pnlAInner cause a postback.

You need to configure the panels to meet the requirements.

What should you do?

A. Set the UpdateMode of pnlA and pnlB to Conditional.

Set the UpdateMode of pnlAInner to Always.

B. Set the UpdateMode of pnlA and pnlB to Conditional.

Set the UpdateMode of pnlAInner to Conditional, and add AsyncPostBackTrigger elements to its Triggers element for every control in pnlA.

C. Set the UpdateMode of pnlA and pnlB to Always.

Set the UpdateMode of pnlAInner to Conditional.

D. Set the UpdateMode of pnlA and pnlB to Always.

Set the UpdateMode of pnlAInner to Always, and add AsyncPostBackTrigger elements to its Triggers element for every control in pnlB.

Answer: A

QUESTION NO: 36

A Web service returns a list of system users in the following format.

<?xml version="1.0" ?>

<users>

<user id="first">

<name>Name of first user</name>

<email>first@contoso.com</email>

</user>

<user id="second">

<name>Name of second user</name>

<email>second@contoso.com</email>

</user>

</users>

You need to populate a drop-down menu with the IDs and names of the users from the Web service, in the order provided by the service.

Which code segment should you use?

A. $.ajax({

type: "GET",

url: serviceURL,

success: function(xml) {

$.each($(xml), function(i, item) {

$("<option>").attr("value", id)

.text(tx).appendTo("#dropdown");

});

}

});

B. $.ajax({

type: "GET",

url: serviceURL,

success: function(xml) {

$(xml).find("user").each(function() {

var id = $(this).id;

var tx = $(this).name.text;

$("<option>").attr("value", id)

.text(tx).appendTo("#dropdown");

});

}

});

C. $.ajax({

type: "GET",

url: serviceURL,

success: function(xml) {

$(xml).find("user").each(function() {

var id = $(this).attr("id");

var tx = $(this).find("name").text();

$("<option>").attr("value", id)

.text(tx).appendTo("#dropdown");

});

}

});

D. $.ajax({

type: "GET",

url: serviceURL,

success: function(xml) {

xml.find("user").each(function(node) {

var id = $(node).attr("id");

var tx = $(node).find("name").text();

$("<option>").attr("value", id)

.text(tx).appendTo("#dropdown");

});

}

});

Answer: C

Explanation:

.each() function

(http://api.jquery.com/each/)

CHAPTER 9 Working with Client-Side Scripting, AJAX, and jQuery

Lesson 3: Implementing jQuery

Implementing AJAX with jQuery

QUESTION NO: 37

You create a Web page that contains the following div.

<div id="target">

</div>

You have a JavaScript array named imageurls that contains a list of image URLs.

You need to write a JavaScript function that will insert images from the URLs into target.

Which code segment should you use?

A. $(imageurls).each(function(i,url){

$("<img/>", url).append("#target");

});

B. $(imageurls).each(function(i,url){

$("#target") += $("<img/>").attr("src", url);

});

C. $.each(imageurls, function(i,url){

$("<img/>").attr("src", url).appendTo("#target");

});

D. $.each(imageurls, function(i,url){

$("#target").append("<img/>").src = url;

});

Answer: C

Explanation:

.appendTo() Method

(http://api.jquery.com/appendTo/)

jQuery.each() Function

(http://api.jquery.com/jQuery.each/)

QUESTION NO: 38

You create a Web page that contains the following image element.

<img id="myImage" src="/image1.png" />

You need to write a JavaScript function that will dynamically change which image is displayed. The function must be compatible across different browsers.

Which code segment should you use?

A. function changeImage() {

myImage.src = "image2.png";

}

B. function changeImage() {

document.getElementById("myImage").src =

"image2.png";

}

C. function changeImage() {

getElementById("myImage").src =

"image2.png";

}

D. function changeImage() {

window.getElementById("myImage").src =

"image2.png";

}

Answer: B

QUESTION NO: 39

You are developing an ASP.NET Web page. You add a data-bound GridView control. The GridView contains a TemplateField that includes a DropDownList.

You set the GridViews ClientIDMode property to Static, and you set the ClientIDRowSuffix property to ProductID.

You need to be able to reference individual DropDownList controls from client-side script by using the ProductID.

What should you set the ClientIDMode property of the DropDownList to?

A. AutoID

B. Static

C. Inherit

D. Predictable

Answer: D

Explanation:

http://www.scribd.com/doc/63120741/35/Question-39

http://anandpandey.com/Certification/70-515/DisplayingandManipulatingData.aspx

http://mcpd.somee.com/515/515.htm

QUESTION NO: 40

You create a Web page that contains the following code. (Line numbers are included for reference only.)

01 <script>

02 function changeColor(c) {

03 document.getElementById("message").style.color=c;

04 }

05 </script>

06

07 <p id="message">Welcome!</p>

08 <ul id="color">

09 <li>Black</li>

10 <li>Red</li>

11 </ul>

You need to ensure that when the user clicks an item in the list, the text color of the Welcome! message will change.

Which declaration should you use?

A. <ul id="color">

<li onclick="changeColor(this.innerText);">Black</li>

<li onclick="changeColor(this.innerText);">Red</li>

</ul>

B. <ul id="color">

<li onclick="changeColor(this.style.color);">Black</li>

<li onclick="changeColor(this.style.color);">Red</li>

</ul>

C. <ul id="color">

<li><a onfocus="changeColor(this.innerText);">Red</a></li>

<li><a onfocus="changeColor(this.innerText);">Black</a></li>

</ul>

D. <ul id="color">

<li><a onfocus="changeColor(this.style.color);">Red</a></li>

<li><a onfocus="changeColor(this.style.color);">Black</a></li>

</ul>

Answer: A

Site Search:

Close

Close
Download Free Demo of VCE
Exam Simulator

Experience Avanset VCE Exam Simulator for yourself.


Simply submit your e-mail address below to get started with our interactive software demo of your free trial.


Enter Your Email Address

Free Demo Limits: In the demo version you will be able to access only first 5 questions from exam.