Exam Prep Questions

Question 1

You are developing a Web form to display weather information. When a user requests the Web form, the form needs to do some initializations that will change the appearance of the form and assign values to some controls. Where should you put the code?

  • A. In the InitializeComponent() method

  • B. In the event handler for the Load event of the page

  • C. In the event handler for the Init event of the page

  • D. In the event handler for the PreRender event of the page

A1:

Answer B is correct. The most appropriate place to put these types of initialization is the Load event handler. Answer A is incorrect because the InitializeComponent() method is for the use of Visual Studio .NET, and you should not modify it on your own. Answer C is incorrect because the properties of the control are available only after the page has been initialized . Answer D is incorrect because, at this stage, the page is about to be rendered and any changes to the control's properties will not have a visible effect.

Question 2

You are developing a Web form using Visual Studio .NET and have placed the initialization code in the Page_Load() method of the form. You then attached this method to the Load event of the Web form. When you execute the program, you notice that the Page_Load() method is executing twice instead of just once. What should you do to correct this problem?

  • A. Set AutoEventWireup to true in the Page directive of the Web form.

  • B. Set AutoEventWireup to false in the Page directive of the Web form.

  • C. Set SmartNavigation to true in the Page directive of the Web form.

  • D. Set SmartNavigation to false in the Page directive of the Web form.

A2:

Answer B is correct. You should set AutoEventWireup to false . Answer A is incorrect because, when AutoEventWireup is set to true , ASP.NET automatically registers the Page_Load() method as an event handler for the Load event of the Page class. When you use Visual Studio .NET to attach Page_Load() with the Load event, Page_Load() is registered twice for the Load event. For this reason, Page_Load() is executing twice in your programs. Answers C and D are incorrect because the SmartNavigation property of the Page class is used for other purposes, such as eliminating the flash caused by navigation and persisting the scroll position when moving from page to page during a page postback operation.

Question 3

One of your colleagues is designing a Changed event for a Web page. She complains to you that her code behaves abnormally, running fine some of the time and generating errors at other times. Part of her event handling code is as listed here (line numbers are for reference purpose only):

 01: public delegate void ChangedEventHandler( 02:   object sender, ChangedEventArgs args); 03: public event ChangedEventHandler Changed; 04: protected virtual void OnChanged( 05:    ChangedEventArgs e) 06: { 07:        Changed(this, e); 08:} 

Which of the following suggestions will solve her problem?

  • A. Replace line 7 with the following code:

     if (ChangedEventHandler != null)     ChangedEventHandler(this, e); 
  • B. Replace line 7 with the following code:

     if (ChangedEventHandler != null)     Changed(this, e); 
  • C. Replace line 7 with the following code:

     if (Changed != null)     ChangedEventHandler(this, e); 
  • D. Replace line 7 with the following code:

     if (Changed != null)     Changed(this, e); 
A3:

Answer D is correct. When the OnChange() method is called, it notifies all the registered objects about the Changed event. The method should first check whether the event object Changed is null . If it is null , it means that no objects have registered themselves with the event. Therefore, raising events this time will cause an error. Answers A, B, and C are incorrect because you should use Changed instead of ChangedEventHandler in the if statement. ChangedEventHandler is a delegate that defines the type of event, rather than the event itself.

Question 4

Your colleague is designing an event-driven Web page that the material management group of your company will use. She needs to handle an event named LowInventory in the Web page and change the color of the text to red whenever a LowInventory event is raised. She has written the following code in an ASP.NET Web form to attach an event handler with the LowInventory event:

 protected override void OnInit(EventArgs e) {     this.LowInventory += new         EventHandler(Inventory_LowInventory); } 

When she executes the page, she notes that although the LowInventory event is handled properly, other events that were previously raised by the page have stopped occurring. Which of the following options would you recommend to her to resolve this problem?

  • A. Change the method definition to

     protected override void OnLoad(EventArgs e) {     this.LowInventory += new         EventHandler(Inventory_LowInventory); } 
  • B. Change the method definition to

     protected override void OnLoad(EventArgs e) {     this.LowInventory += new         EventHandler(Inventory_LowInventory);     base.OnInit(e); } 
  • C. Change the method definition to

     protected override void OnInit(EventArgs e) {     this.LowInventory += new         EventHandler(Inventory_LowInventory);     base.OnInit(e); } 
  • D. Change the method definition to

     protected override void OnInit(EventArgs e) {     this.LowInventory += new         EventHandler(Inventory_LowInventory);     base.OnLoad(e); } 
A4:

Answer C is correct. When you override methods of a base class, you should call the base class version of the same method. Otherwise, you will lose the functionality offered by the method of the base class. Answers A and B are incorrect because the OnInit() method ”instead of the OnLoad() method ”is appropriate for attaching a delegate for event handling. Answer D is incorrect because you should call the OnInit() method of the base class.

Question 5

You are developing a library of useful classes that you plan to sell over the Internet to other developers. In one of the classes, CommercePage , you have a method named Render() . You want users of the library to be able to change the definition of the Render() method from a class that derives from CommercePage to one that does not. You also do not want to make the Render() method visible to those classes that do not derive from CommercePage . Which of the following modifiers should be applied to the Render() method while defining it in the CommercePage class? (Select two.)

  • A. public

  • B. protected

  • C. virtual

  • D. override

A5:

Answers B and C are correct. If you want the derived classes to override a method of base class, that method should be declared with protected and virtual modifiers in the base class. Answer A is incorrect because the public modifier increases the visibility of a method to all the classes and not just the derived classes. Answer D is incorrect because override is used only in the derived class and not in the base class.

Question 6

You want to implement your Web page using the code-behind technique. You place the UI in a file named WeatherPage.aspx and the business logic in another file named WeatherPage.aspx.cs . The WeatherPage.aspx.cs file contains the definition of a class that derives from the Page class. You want to link the UI file with the code-behind file, but you do not want to compile the business logic before you deploy it on the Web server. Which of the following attributes will you use for the Page directive in the WeatherPage.aspx file? (Select two.)

  • A. The Src attribute

  • B. The Inherits attribute

  • C. The Codebehind attribute

  • D. The ClassName attribute

A6:

Answers A and B are correct. Because you do not want to precompile the business logic file before you deploy it to the Web server, you need to specify both the Inherits and Src attributes with the Page directive of the WeatherPage.aspx file. Answer C is incorrect because the Codebehind attribute is ignored by ASP.NET. Answer D is incorrect because the ClassName attribute is used to specify the class name for the page that will automatically be dynamically compiled when the page is requested .

Question 7

You are designing a Web application that contains several Web forms. One of the Web forms, Catalog.aspx , displays catalogs to the users and performs several actions based on user input. You have extensively used event handling to make Catalog.aspx responsive to the user. When Catalog.aspx is loaded, you need to invoke a method named PerformInitializations() . Which statement should you use in the Web form to achieve this?

  • A. this.Init = EventHandler(PerformInitializations);

  • B. this.Init = new EventHandler(PerformInitializations);

  • C. this.Load = new EventHandler(PerformInitializations);

  • D. this.Load += new EventHandler(PerformInitializations);

A7:

Answer D is correct. You want to invoke PerformInitializations() when the Web form is loaded, so you must attach to the Load event of the Web form. You also want the Web form to be responsive to any previously registered event, so you should use the += operator to register this event handler. Answers A and B are incorrect because the Init event occurs before the Load event. Answer C is incorrect because using the = operator is destructive in the sense that it deletes all the previously attached event handlers to the Load event.

Question 8

You want to display values of C# expressions in an ASPX page. Which of the following types of code blocks would you use to enclose the expression in an ASPX file?

  • A. <script runat ="server">...</script>

  • B. <script>...</script>

  • C. <%=...%>

  • D. <form>...</form>

A8:

Answer C is correct. Only two of the given choices execute code on the server side: the <script runat="server">...</script> block and the <%=...%> block. Therefore, you should display the values of C# expressions in the <%=...%> block because the statement included in this block is executed while the page is rendered. Answer A is incorrect because code written in this block is compiled using a language compiler and writing an expression by itself will possibly raise a compilation error. Answers B and D are incorrect because these statements are executed on the client side instead of the Web server.

Question 9

You have developed a timesheet entry application that will be used by all employees in your company. You have used ASP.NET to develop this application and have deployed it on the company's Web server. What should all the employees of the company install on their computers before accessing the timesheet entry application?

  • A. .NET Framework Redistributable

  • B. .NET Framework SDK

  • C. Visual Studio .NET

  • D. A Web browser

A9:

Answer D is correct. Users accessing an ASP.NET Web application need only to have a Web browser on their computers. Answer A is incorrect because the .NET Framework Redistributable is required only on the Web server that executes the server-side ASP.NET code. Answers B and C are incorrect because these tools are required only on the developer machine ”not on the deployment server or the user's machine.

Question 10

You have created a Web page that users will use to register with the Web site. Inside the event handler for the Load event of the Page , you want to access the data entered by the users on the Web page. Which of the following properties of the Page class can give you access to this data?

  • A. ClientTarget

  • B. Request

  • C. Response

  • D. Trace

A10:

Answer B is correct. The Request property contains information about the current HTTP request, which contains all the data entered by the users on a Web page. Answer A is incorrect because the ClientTarget property is used to detect the browser capabilities. Answer C is incorrect because the Response property contains the response of the Web server with respect to the current Web request. Answer D is incorrect because the Trace property is used to display the execution details of a Web page.



MCAD Developing and Implementing Web Applications with Visual C#. NET and Visual Studio. NET (Exam [... ]am 2)
MCAD Developing and Implementing Web Applications with Visual C#. NET and Visual Studio. NET (Exam [... ]am 2)
ISBN: 789729016
EAN: N/A
Year: 2005
Pages: 191

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net