Question: You are developing an ASP.NET templated server control. You need to ensure that a new ID namespace is created within the page control hierarchy when the control is added to a page. Which interface should you implement on the control?
- IDataItemContainer
- INamingContainer
- IDataKeysControl
- IExtenderControl
Correct Answer: 2
Question: 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 page s code-behind file includes the following code segment. (Line numbers are included for reference only.)
01protected void gvModels_RowDataBound(object sender,GridViewRowEventArgs e)
02{
03if (e.Row.RowType == DataControlRowType.DataRow)
04{
05CarModel cm = (CarModel)e.Row.DataItem;
06
07img.ImageUrl = String.Format(“images/{0}.jpg”,cm.ID);
08&
09}
10}
You need to get a reference to the Image named img. Which code segment should you add at line 06?
- Image img = (Image)Page.FindControl(“img”);
- Image img = (Image)e.Row.FindControl(“img”);
- Image img = (Image)gvModels.FindControl(“img”);
- Image img = (Image)Page.Form.FindControl(“img”);
Correct Answer: 2
Question: 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?
- <%: Model.FirstName %>
- <%= Model.FirstName %>
- <% Response.Write(Model.FirstName); %>
- <% Response.Write(HttpUtility.HtmlDecode(Model.FirstName)); %>
Correct Answer: 1
Question: 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 GridView s 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?
- AutoID
- Static
- Inherit
- Predictable
Correct Answer: 4
Question: You are developing an ASP.NET Web page. The page includes a DropDownList control. You need to call a client-side function when the user changes the value of the control. Which event should you handle?
- Click
- SelectedIndexChanged
- Change
- Select
Correct Answer: C