Exam 70-562 : Microsoft .NET Framework 3.5, ASP.NET Application Development – 17

Question: You work as a Web Developer at Company.com. You are in the process of creating a Web application that uses Microsoft ASP.NET 3.5. The following markup is added to the page:

<asp:TextBox ID="priceTextBox" runat="server"/>
<asp:RequiredFieldValidator ID="requiredValidator" runat="server" ErrorMessage="You must specify a price." ControlToValidate="priceTextBox"/>
<asp:CompareValidator ID="numberValidator" runat="server" Operator="DataTypeCheck" Type="Double" ErrorMessage="The value must be a number." ControlToValidate="priceTextBox"/>
<asp:CustomValidator ID="precisionValidator" runat="server" ServerValidate="ValidatePrecision" ErrorMessage="The price must contain two decimal digits or less." ControlToValidate="priceTextBox"/> 

You have to make sure that the values entered into the priceTextBox control contain three decimal places or less. To accomplish this you decide to implement the ValidatePrecision event handler. Identify the code segment you should use?

  1. You should consider using the code segment:
    protected void ValidatePrecision(object sender, ServerValidateEventArgs e)
    {
    string[] decimalSides = e.Value.TrimEnd(‘0’).Split(‘.’);
    int decimalPrecision = 0;
    if (decimalSides.Length == 2)
    {
    decimalPrecision = decimalSides[1].Length;
    }
    if (decimalPrecision <= 2)
    {
    e.IsValid = true;
    }
    }
  2. You should consider using the code segment:
    protected void ValidatePrecision(object sender, ServerValidateEventArgs e)
    {
    string[] decimalSides = e.Value.TrimEnd(‘0’).Split(‘.’);
    int decimalPrecision = 0;
    if (decimalSides.Length == 2)
    {
    decimalPrecision = decimalSides[1].Length;
    }
    if (decimalPrecision <= 2)
    {
    Page.IsValid = true;
    }
    }
  3. You should consider using the code segment:
    protected void ValidatePrecision(object sender, ServerValidateEventArgs e)
    {
    string[] decimalSides = e.Value.TrimEnd(‘0’).Split(‘.’);
    int decimalPrecision = 0;
    if (decimalSides.Length == 2)
    {
    decimalPrecision = decimalSides[1].Length;
    }
    e.IsValid = decimalPrecision <= 2;
    }
  4. You should consider using the code segment:
    protected void ValidatePrecision(object sender, ServerValidateEventArgs e)
    {
    if (e.Value <= 2)
    {
    Page.IsValid = e.IsValid;
    }
    }
  5. You should consider using the code segment:
    protected void ValidatePrecision(object sender, ServerValidateEventArgs e)
    {
    if (e.Value <= 3)
    {
    Page.IsValid = e.IsValid;
    }
    }

Correct Answer: 5


Question: You work as an application developer at Company.com. You make use of .NET Framework 3.5 to create an ASP.NET application. Your application contains an XMLfile named exams.xml. The exams.xml file includes the code segment below:

<Exams>
<Exam ID="1" Name="Exam1" Year="2007">
<Desc Value="Exam desc"/>
</Exam>
<Exam ID="2" Name="Exam2" Year="2008">
<Desc Value="Exam desc"/>
</Exam>
<Exam ID="3" Name="Exam3" Year="2009">
<Desc Value="Exam desc"/>
</Exam>
</Exams>

Your application also contains a Web page named DisplayExams.aspx. You want the content of the XML file to be displayed in a TreeView control named tv1 on DisplayExams.aspx. DisplayExams.aspx contains the subsequent code:

<form runat="server">
<asp:xmldatasource id="xds1" datafile="exams.xml" runat="server" />
<!-- add code here -->
</form> 

You thus need to add code to complete the Web page. What should you do?

  1. You should consider adding the code below:
    <asp:TreeView ID=”tv1″ runat=”server”>
    <DataBindings>
    <asp:TreeNodeBinding DataMember=”Exams” Text=”Desc” />
    </DataBindings>
    </asp:TreeView>
  2. You should consider adding the code below:
    <asp:TreeView ID=”tv1″ runat=”server” DataSourceID=”xds1″>
    <DataBindings>
    <asp:TreeNodeBinding DataMember=”Exam” Text=”Title” />
    </DataBindings>
    </asp:TreeView>
  3. You should consider adding the code below:
    <asp:TreeView ID=”tv1″ runat=”server” DataSourceID=”xds1″>
    <DataBindings>
    <asp:TreeNodeBinding DataMember=”Exam” Text=”Title” />
    </DataBindings>
    </asp:TreeView>
  4. You should consider adding the code below:
    <asp:TreeView ID=”tv1″ runat=”server”>
    <DataBindings>
    <asp:TreeNodeBinding DataMember=”Exams” Text=”Desc” />
    </DataBindings>
    </asp:TreeView>

Correct Answer: 3


Question: You work as an application developer at Company.com. You are in the process of creating anASP.NET application using .NET Framework 3.5. You application contains a chat forum that allows users to post comments that can be viewed by other users. You then decide to add a SqlDataSource control to the application. This SqlDataSource is named Data1. You want the user’s IP address to be captured with their comment. Your write the following code:

Private Sub AddPost()
Dim _addr As String
' add code here
Data1.InsertParameters("IPAddress").DefaultValue = _addr
' ...
Data1.Insert()
End Sub 

You thus need to determine the appropriate code you need to add. What should you do?

  1. Your best choice would b to add the code fragment:
    _addr = Request.ServerVariables(“REMOTE_ADDR”).ToString()
  2. Your best choice would b to add the code fragment:
    _addr = Session(“REMOTE_ADDR”).ToString()
  3. Your best choice would b to add the code fragment:
    _addr = Application(“REMOTE_ADDR”).ToString()
  4. Your best choice would b to add the code fragment
    _addr = Server(“REMOTE_ADDR”).ToString()

Correct Answer: 1


Question: You work as a Web Application Developer at Company.com. You are in the process of creating an ASP.NET application using .NET Framework 3.5. Your application contains a Web page named Default.aspx. You insert an XmlDataSource control on the Default.aspx Web page. The XmlDataSource control is named ds1 and is bound to the following XML document:

<?xml version="1.0" encoding="utf-8" ?>
<users>
<user ID="1" Name="Kara Lang" />
<user ID="2" Name="Rory Allen"/>
...
</users> 

The code-behind file for the Default.aspx Web page contains the following cod:

protected void ckList1_Click(object sender, BulletedListEventArgs e) {
//...
} 

A BulletedList control named ckList1 needs to be added to the Default.aspx page and must be bound to the ds1 datasource. What code should you add?

  1. You should consider using the subsequent code-segment:
    <asp:BulletedList ID=”ckList1″ runat=”server” DisplayMode=”LinkButton” DataSourceID=”ds1″ DataTextField=”Name” DataValueField=”ID” onclick=”ckList1_Click”>
    </asp:BulletedList>
  2. You should consider using the subsequent code-segment:
    <asp:BulletedList ID=” ckList1″ runat=”server” DisplayMode=”HyperLink” DataSourceID=”ds1″ DataTextField=”ID” DataValueField=”Name” onclick=”ckList1_Click”>
    </asp:BulletedList>
  3. You should consider using the subsequent code-segment:
    <asp:BulletedList ID=” ckList1″ runat=”server” DisplayMode=”LinkButton” DataSource=”ds1″ DataTextField=”Name” DataValueField=”Name” onclick=”ckList1_Click”>
    </asp:BulletedList>
  4. You should consider using the subsequent code-segment:
    <asp:BulletedList ID=” ckList1″ runat=”server” DisplayMode=”HyperLink” DataSourceID=”ds1″ DataTextField=”Name” DataMember=”ID” onclick=”ckList1_Click”>
    </asp:BulletedList>

Correct Answer: 1


Question: You work as an application developer at Company.com. One of the Company.com policies states that Microsoft .NET Framework 3.5 needs to be used to create a Microsoft ASP.NET application. You write the following code for the purpose of adding a custom parameter in the SqlDataSource control:

<asp:SqlDataSource ID="ds1" runat="server" InsertCommand="INSERT INTO [Orders] ([ProdID], [Price], [PostedDate]) VALUES (@Orders, @Prod, @PostedDate)">
<InsertParameters>
<asp:Parameter Name="ProdID" />
<asp:Parameter Name="Price" />
<custom:DayParameter?Name="PostedDate" />
</InsertParameters>
</asp:SqlDataSource> 

You then use the subsequent code to create a custom parameter class.

public class DayParameter : Parameter {
} 

Management wants you to make sure that the custom parameter will return the current date and time. You should thus determine the appropriate code you need to add to the DayParameter class to accomplish this. What should you do?

  1. This can be accomplished using:
    protected override void LoadViewState(object savedState)
    {
    ((StateBag)savedState).Add(“Value”, DateTime.Now);
    }
  2. This can be accomplished using:
    protected DayParameter() : base(“Value”, TypeCode.DateTime,
    DateTime.Now.ToString())
    {
    }
  3. This can be accomplished using:
    protected override Parameter Clone()
    {
    Parameter pm = new DayParameter();
    pm.DefaultValue = DateTime.Now;
    return pm;
    }
  4. This can be accomplished using:
    protected override object Evaluate(HttpContext context, Control control)
    {
    return DateTime.Now;
    }

Correct Answer: 4

Tagged . Bookmark the permalink.

Leave a Reply