Exam Prep Questions

Question 1

You are developing a Web form to display weather information. On the initial requests to the Web form, you need to do some initialization that will change the appearance of the form and assign values to some controls. However, this initialization should not be repeated again when the user submits the Web form. How should you write the code to accomplish this? (Select two.)

  • A. Write the code inside the Page_Init() event handler.

  • B. Write the code inside the Page_Load() event handler.

  • C. Execute the initialization code only when the Page.IsPostBack property is true .

  • D. Execute the initialization code only when the Page.IsPostBack property is false .

A1:

The correct answers are B and D. The code for the initialization of controls should be placed inside the Page_Load() event handler. If you want to execute the initialization code only when the page is first requested and do not want to run that code again at the time of the page postback, you must execute the code when the IsPostBack property of the Page class is false . Answer A is incorrect because during the Init event, server controls are not certain to be created and are not ready for access. Answer C is incorrect because, if you execute the code when the IsPostBack property of the Page class is true , the initialization code will be executed each time the page is submitted.

Question 2

You have used ASP.NET to develop an inventory management system for your organization, and associates can access this application from the company's intranet. When analyzing users' feedback on the applications, you found that users complain that they receive an annoying flash when they submit forms. They also complain that the data entry form does not always remember the active controls and, because of this, users have to press the Tab key several times before they can focus again on the desired control. This makes the data entry inconvenient and time-consuming . On analyzing further usage data, you found that all the users in your company use Internet Explorer 5.0 or above to access your application. What should you do to eliminate the problems reported by the users?

  • A. Set the SmartNavigation attribute of the Page directive to true .

  • B. Set the AutoEventWireup attribute of the Page directive to true .

  • C. Set the EnableViewState attribute of the Page directive to true .

  • D. Set the ClientTarget attribute of the Page directive to "ie5" .

A2:

The correct answer is A. When all users are using Internet Explorer version 5.0 or later, you can set the SmartNavigation attribute to true . This eliminates the flash and causes Internet Explorer to focus active control. Answer B is incorrect because the AutoEventWireup attribute is useful only for deciding whether the event handlers (such as Page_Init() and Page_Load() )for the page-level events will be automatically called. Answer C is incorrect because the EnableViewState attribute is used to enable or disable ViewState for a page; ViewState is only a state management technique and does not affect how the page is displayed. Answer D is incorrect because in this case, although the page is rendered for Internet Explorer version 5.0, the ClientTarget property will not eliminate the reported problem.

Question 3

You are developing an ASP.NET Web site for a popular Web development magazine. You want to keep track of how many times each page of your Web application is accessed. This data will help your company to analyze the application's usage patterns and develop appropriate Web content. You want to write minimum code to achieve this task; which of the following techniques will you use?

  • A. Use the Page_Load() event handler to increment the usage counter of the page.

  • B. Use the Application_BeginRequest() event handler to increment the usage counter of the page.

  • C. Use the Session_Start() event handler to increment the usage counter of the page.

  • D. Use the Application_Start() event handler to increment the usage counter of the page.

A3:

The correct answer is B. Answers C and D do not work with each page request, so only options A and B are viable choices. Between these two choices, you should choose to write the code in the Application_BeginRequest() event handler of the global.asax file because, if you use the Page_Load() event handler, you'll have to write code in each and every ASPX page in the application.

Question 4

Your ASP.NET page contains a page-level variable of ArrayList type. You want to preserve the value of this variable across page postbacks, but you do not need this variable in any other page in the application. Which of the following state management techniques provides the best way to achieve this?

  • A. Query strings

  • B. Cookies

  • C. Session

  • D. View state

A4:

The correct answer is D. In the given case, the variable is required on only a single page; therefore, it is most suitable to store its values in view state. Answers A and B are incorrect because client-side state management techniques such as cookies and query strings do not allow you to store structured data. Answer C is incorrect because storing values in the session involves consumption of server resources.

Question 5

You are developing a Web application for an online bank. Your application enables users to access their account information and transactions right from their desktops. When a user logs on to your application, you want to show the username and current balance on all the pages of the application until the user logs off. You also want your application to be safe from malicious users. Which of the following state management techniques should you use? (Select the best answer.)

  • A. Cookies

  • B. View state

  • C. View state with encryption

  • D. Session

A5:

The correct answer is D. Session data is stored at the server side and cannot be easily tampered with. Answer A is incorrect because cookies can be easily accessed and used by malicious users. Answer B is incorrect because view state information can be easily decoded. Answer C is incorrect because, although view state with encryption provides a high level of encryption, it is available only on the same page, and in the given scenario, you want the name and current balance to be displayed on all the pages.

Question 6

You have developed and deployed a Web application for an online bank. This application enables users to access their account information and transactions right from their desktops. Because the application deals with financial data, you have enabled encryption for the view state of all the pages. The bank business has rapidly increased, and the management has decided to upgrade the single Web server to a Web farm of Web servers. When you were testing the application for the Web farm, sometimes the application worked fine but other times it generated a view state error. What should you do to resolve this problem?

  • A. Use the same validation key for all the Web servers in the Web farm.

  • B. Use different validation keys for all the Web servers in the Web farm.

  • C. Set the EnableViewStateMac attribute to true for all the pages in the application.

  • D. Set the EnableViewStateMac attribute to false for all the pages in the application.

A6:

The correct answer is A. If the validation keys don't match, an error will occur when the user is directed to a different server in the Web farm. Answer B is incorrect because, when you use view state encryption in a Web farm, you must use the same validation key for all the Web servers. Answer C is incorrect because the given scenario specifies that the encryption is already enabled on all the pages. Answer D is incorrect because setting the EnableViewStateMac attribute to false turns off the view state encryption and is not a desirable solution.

Question 7

You have recently developed and deployed a Web application for a large automotive parts supplier. This application is used by users from the United States, Europe, and Asia. You have received complaints from several users that the Web pages take a very long time to download. You did some research and found that an HTML element named __VIEWSTATE in your pages is storing a large amount of data and is responsible for the bigger page sizes. Your manager recommended that you disable view state wherever it is unnecessary in the application. In which of the following cases would you want to disable view state in your application? (Select all that apply.)

  • A. Those pages that do not postback

  • B. Those pages that postback

  • C. Those controls that are not dynamically changed

  • D. Those controls that are dynamically changed

  • E. Those controls that are modified at every page load

  • F. Those controls that are not modified at every page load

A7:

The correct answers are A, C, and E. If the pages don't post back to themselves , they are not making use of view state; in that case, you should disable view state for the whole page. For all other pages, the controls that are not dynamically changed need not have their view states enabled. Also, the controls whose values are modified on every page load need not store their values in view state. Answers B, D, and F are incorrect because these cases require view state to be enabled in order to work.

Question 8

In a Web page of your application, you allow users to select a product and its quantity. When the user has made her selection, you want to transfer the user to another page named ShoppingCart.aspx with the ProductId and the Quantity as the query string parameters to the ASPX page. You want to write minimum code to accomplish this objective. Which of the following options should you select?

  • A. A HyperLink control

  • B. The Response.Redirect() method

  • C. The Server.Transfer() method

  • D. The Server.Execute() method

A8:

The correct answer is B. The Response.Redirect() method redirects the client to a new URL that might include query string parameters. Answer A is incorrect because, although the Hyperlink control supports query strings, the redirection needs to be performed within the code. Answers C and D are incorrect because you cannot use query strings with the Server.Transfer() and Server.Execute() methods .

Question 9

You are developing an online bill payment system using ASP.NET. When a user logs on to the application by entering her username and password, you want to programmatically redirect the user to a page named accountdetails.aspx in the same Web application. You want an application that responds quickly to your users. Which of the following methods would you use to accomplish this?

  • A. A HyperLink control

  • B. The Response.Redirect() method

  • C. The Server.Transfer() method

  • D. The Server.Execute() method

A9:

The correct answer is C. You should use the Server.Transfer() method to redirect users to another ASPX page on the same Web server. Answer A is incorrect because the HyperLink control requires additional action from the user. Answer B is incorrect because the Response.Redirect() method involves an additional round trip and is not a good option when you want the application to be faster. Answer D is incorrect because the Server.Execute() method is more like a procedure call and, after executing the specified page, the control comes back to the calling page.

Question 10

You are using a DataGrid control in an ASP.NET page ( ShowData.aspx ) of your Web application. You want to invoke another ASP.NET page ( GetData.aspx ) that returns the data to be displayed in the DataGrid control. You are using the Server.Execute() method to invoke GetData.aspx from the ShowData.aspx page. When you run the application, you get an Invalid View state error. Which of the following options would you choose to resolve this error?

  • A. Use the Server.Transfer() method instead of the Server.Execute() method.

  • B. Set the EnableViewStateMac attribute to false in the Page directive of GetData.aspx .

  • C. Set the EnableViewStateMac attribute to false in the Page directive of ShowData.aspx .

  • D. Set the EnableViewState attribute to false in the Page directive of GetData.aspx .

A10:

The correct answer is B. You get an error while executing the Server.Execute() method because the view state of the ShowData.aspx page is passed to the GetData.aspx page along with the form and query string collections, causing the ASP.NET machine authentication check to fail. You need to set the EnableViewStateMac attribute of the Page directive in the GetData.aspx page to false to resolve this error. Answer A is incorrect because you do not want to transfer the control to the GetData.aspx page. Answer C is incorrect because the view state of the ShowData.aspx page is mixing up the GetData.aspx page and not vice versa. Answer D is incorrect because disabling view state affects the functionality of Web server controls such as DataGrid .



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