Web Developer Framework 4.0 Sample Questions – 11

Question: You are implementing an ASP.NET page. You add and configure the following ObjectDataSource. <asp:ObjectDataSource SelectMethod=”GetProductByProductId”ID=”odc” runat=”server” TypeName=”ProductDAL”><SelectParameters><asp:Parameter Name=”productId” Type=”Int32″ /></SelectParameters> </asp:ObjectDataSource> The page will be called with a query string field named pid. You need to configure the ObjectDataSource control to pass the value of the pid field to GetProductsByProductId method. What should you do?

  1. Replace the asp:Parameter with the following declaration. <asp:QueryStringParameter DefaultValue=”pid” Name=”productId”Type=”Int32″ />
  2. Replace the asp:Parameter with the following declaration. <asp:QueryStringParameter QueryStringField=”pid” Name=”productId”Type=”Int32″ />
  3. Add the following event handler to the Selecting event of the ObjectDataSource control. protected void odc_Selecting(object sender,ObjectDataSourceSelectingEventArgs e) {e.InputParameters[“p id “] = Request.QueryString[“p roductId “]; }
  4. Add the following code segment to the page s code-behind. protected void Page_Load(object sender, EventArgs e) {odc.SelectParameters.Add(“productId”, Request.QueryString[“p i d”]); }

Correct Answer: 2


Question: You are implementing an ASP.NET Web application that retrieves data from a Microsoft SQL Server database. You add a page that includes the following data source control. <asp:SqlDataSource id=”sqlds” runat=”server”ConnectionString=”<%$ ConnectionStrings:MyDB %>”SelectCommand=”SELECT * FROM Companies” /> The page is accessed frequently, but the data in the database rarely changes. You need to cache the retrieved data so that the database is not queried each time the Web page is accessed. What should you do?

  1. Add the following attributes to the SqlDataSource control. DataSourceMode=”DataSet” EnableCaching=”True” CacheDuration=”120″
  2. Add the following attributes to the SqlDataSource control. DataSourceMode=”DataReader” EnableCaching=”True” CacheDuration=”120″
  3. Add the following configuration to the <system.web/> section of the web.config file. <caching><sqlCacheDependency enabled=”true”><databases><add name=”MyDBCache”connectionStringName=”MyDB”pollTime=”120″ /></databases></sqlCacheDependency> </caching>
  4. Add the following configuration to the <system.web/> section of the web.config file. <caching><sqlCacheDependency enabled=”true” pollTime=”120″><databases><add name=”MyDBCache”connectionStringName=”MyDB” /></databases></sqlCacheDependency> </caching>

Correct Answer: 1


Question: You are implementing an ASP.NET page. Client-side script requires data. Your application includes a class named Person with a Name property of type string. The code-behind file of the page includes the following code segment. public string JsonValue; List<Person> people = GetPeopleList(); JavaScriptSerializer json = new JavaScriptSerializer(); You need to use the JavaScriptSerializer class to serialize only the value of the Name property of each item in the people list. Which code segment should you use?

  1. JsonValue = json.Serialize(people.Select(p => p.Name)); var names = from person in peopleselect person;
  2. JsonValue = “{” + json.Serialize(names) + “}”;
  3. JsonValue = json.Serialize(people.SelectMany( p => p.Name.AsEnumerable())); var names = from person in peopleselect person;
  4. JsonValue = json.Serialize(names);

Correct Answer: 1


Question: You are implementing an ASP.NET application that uses LINQ to Entities to access and update the database. The application includes the following method to update a detached entity of type Person. private NorthwindContext _entities; public void UpdatePerson(Person personToEdit) { } You need to implement the UpdatePerson method to update the database row that corresponds to the personToEdit object. Which code segment should you use?

  1. _entities.People.Attach(personToEdit); _entities.ObjectStateManager.ChangeObjectState(personToEdit,EntityState.Modified); _entities.SaveChanges();
  2. _entities.ObjectStateManager.ChangeObjectState(personToEdit,EntityState.Added); _entities.SaveChanges();
  3. _entities.People.ApplyCurrentValues(personToEdit); _entities.SaveChanges();
  4. _entities.People.Attach(new Person() { Id = personToEdit.Id }); _entities.ObjectStateManager.ChangeObjectState(personToEdit,EntityState.Modified); _entities.SaveChanges();

Correct Answer: 1


Question: You are implementing an ASP.NET Web site. The Web site contains a Web service named ProductService . The code-behind file for the ProductService class contains the following code segment. public class ProductService :System.Web.Services.WebService {public List<Product> GetProducts( int categoryID ){return GetProductsFromDatabase(categoryID);} } You need to ensure that the GetProducts method can be called by using AJAX. Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)

  1. Apply the WebService attribute to the ProductService class.
  2. Apply the ScriptService attribute to the ProductService class.
  3. Apply the WebMethod attribute to the GetProducts method.
  4. Apply the ScriptMethod attribute to the GetProducts method.

Correct Answer: 2 & 3

Tagged . Bookmark the permalink.

Leave a Reply