To Exam Info

Final Review Questions

  1. Define these items:
     
    1. namespace: A logical folder that contains classes, namespaces, and other C# objects. To avoid having to include the namespace in a C# class name, use an import statement
      <%@ Import Namespace=System.IO %>
      
    2. div: A section on an HTML page to which styles can be attached including absolute positioning.
       
    3. float: Allows items like images to float on the page and have a paragraph of text flow around them.
       
    4. clear: When float is used, clear finishes any images and/or paragraph text and lets the page composition resume without the float property.
       
    5. CSS class: Defines a style with a user defined name that starts with a dot. To apply the style to an HTML element, use a class= attribute.
       
    6. CssClass: Property of a control that allows a CSS class to be attached.
       
    7. Web safe color: A color that is guarenteed to be properly rendered by all browsers. A web safe color uses only these hex color components for r, g, and b: 00, 33, 66, 99, CC, FF.
       
    8. Redirect: Response.Redirect changes the current webpage to a new URL. Response.Redirect must be the first item written to the page with Response to work.
       
    9. PostBackUrl: A property of a button or other control. When the control is clicked, the current page is changed to this new URL.
       
    10. IsPostBack: Page.IsPostBack is true if the page is being refreshed due to a postback event (the page is sent back to the server) rather than the first time that the page is loaded.
       
    11. AutoPostBack: If AutoPostBack is set to true for a control, then when an event for the control occurs, the page is sent back to the server. A Button control always causes postback when it is clicked so it does not even have an AutoPostBack property.
       
    12. DataSource: The property of a databound control that allows it to automatically be populated from a datasource like a DataSet or ArrayList object.
       
    13. Peek: Checks the next byte in the input buffer, to see if there is more to be read, or if the StreamReader is at the end of file.
       
    14. Format String: Is passed to the string.Format method (see Example 49) to control how output is formatted. Always use a fixed width font like CourierNew or Lucida Console in pre tags to display output from string.Format.
       
    15. TextChanged: The default event for a TextBox control. It fires when its Text is changed and then the mouse is clicked outside of the control. Set AutoPostBack to true for this to work.
       
    16. SelectedIndexChanged: Default event for the DropDownList, RadioButtonList, and CheckBoxList controls. It occurs when the selected item is changed. Set AutoPostBack to true for this to work. Set AutoPostBack to true for this to work.
       
    17. Hex Color Code: A color code like this: #996633. 99 represents red, 66 represents green, and 33 represents blue. Set AutoPostBack to true for this to work.
       
    18. OleDbConnection: Establishes the primary connection to the database. The ConnectionString contains the location of the database and the provider: Microsoft.Jet.OLEDB.4.0
       
    19. OleDbCommand: Contains the SELECT command.
       
    20. OleDbDataAdapter Uses the Connection and Command objects to create a DataSet object.
       
    21. DataSet: An in-memory representation of the table or tables produced by the DataAdapter object. The DataSet object represents the data in XML format. OleDbDataAdapter
       
    22. SELECT, INSERT, UPDATE, INSERT: SQL statements for manipulating the data in one or more tables.
       
    23. join: Use a SELECT statement to combine two or more tables.
       
    24. Cookie: A way to write data to the user's harddrive to be read back in a later session.
       
    25. Master Page: A page with content that can be applied to two or more content pages. The master page itself cannot be viewed in a browser.
       
    26. Content Page: A page that contains content to be displayed on a master page.
       
    27. One-way hash: An encryption algorithm that encodes a piece of text like a password. The hash of the password is then compared to the hashes in the password file. If there is a match for that username, the login is successful.
       
    28. SHA: A popular family of hashing algorithms. This family includes SHA0 (not very secure), SHA1, SHA2. Some variations of SHA2 are SHA224, SHA256, SHA384, and SHA512.
       
    29. Base-64: A system for encoding binary data that is more efficient that hex (it uses 33% less bytes to encode the same data). Here are the 64 digits that are used:
      ABCDEFGHIJKLMNOPQRSTUVWXYZ
      abcdefghijklmnopqrstuvwxyz
      0123456789
      +/
      
  2. What do these color codes represent? Ans:
  3. Convert the color codes in Problem 2 into rgb color codes.
    Ans: rgb(255,255,0)  rgb(255,128,0)  rgb(255,0,128)  rgb(144,0,0)  rgb(0,128,128)  rgb(96,64,0)
     
  4. Create pastel colors from these colors. Ans:
    Hint: Shrink the distance of each component (r, g, and b) from 255 by the same factor.

  5.  
  6. Convert the hex data D5 F1 03 into base-64. Ans: 1fED.
     
  7. Convert the base-64 data t+5Y into hex. Ans: B7EE54.
     
  8. How is base-64 used in .Net?
    Ans: For showing encrypted data and the VIEWSTATE hidden field data that is sent back to the server when a postback occurs. Base-64 is also used for encoding image or sound data in a .Net resource files. Here is an XML resource file. This file contains the image happy.jpg in base-64.
     
  9. List the four types of comments that are available in ASP.Net. Ans:
    1. <%-- Server-side comment --%>
    2. <!-- Client-side comment -->
    3. // C#-style comment
    4. /* CSS or C-style comment */

  10. Write C# code to test the classes Color and ArrayList.
    Ans: See the UML Examples Page.
     
  11. Use Visual Studio to
     

  12. Write ASP.Net code to
     
    1. Create a table with these items:
       
      Bulls Lakers Knicks
      Pistons Rockets Trailblazers

      Recall that the indices of the rows and tables are zero based.
       
      Ans: Here are two solutions to Part A: tables1.htm and tables2.htm.
       
    2. Copy the item in row 0, column 1 into the textbox txtTeam.
       
    3. Use a for loop to copy the items in row 1 into the dropdownlist ddlTeams.
       
    4. Use a double for loop to copy the items in the table into the literal control litDisplay.
      Ans:
      public void Page_Load(object source, EventArgs e)
      {
          txtTeam.Text = table1.Rows[0].Cells[1].Text;
          
          for (int i = 0; i <= 2; i++)
          {
              ddlTeams.Items.Add(table1.Rows[1].Cells[i].Text);
          }
      
          for (int i = 0; i <= 1; i++)
          {
              for (int j = 0; j <= 2; j++)
              {
                  litDisplay.Text += 
                      table1.Rows[i].Cells[j].Text +  ;
              }
              litDisplay.Text += <br />;
          }
      }
      
  13. Consider the Persons table in the persons.mdb database. Here is a project that creates a DataSet object: Persons Example. Write C# code that will
     
    1. Copy row 2 into the textboxes txtName, txtGender, and txtAge.
       
    2. Copy the item in row 3, column 1 into the following:
       
        TextBox Control   Literal Control   Append to a DropDownList Control
      Ans:
          DataRow r = ds.Tables[0].Rows[3];
          txtName.Text = r.ItemArray[0].ToString();
          txtGender.Text = r.ItemArray[1].ToString();
          txtAge.Text = r.ItemArray[2].ToString();
          string s = ds.Tables[0].Rows[3].ItemArray[1].ToString();
          Label1.Text = s;
          Session[gender] = s;
          HttpCookie cook = new HttpCookie(mycookie);
          cook[gender] = s;
          DateTime d = DateTime.Now;
          d.AddDays(1);
          cook.Expires = d;
          Response.Cookies.Add(cook); 
      
  14. Create an HTML form with textboxes for name, gender, and age. This form is to be submitted to the .aspx page receiver.aspx that appends the textbox information to the Persons database. Here is a form to get you started: persons.htm.
     
    Ans: Change the input tag for the submit button to type submit. Also add to the form tag, an action attribute with the postback URL and method=get. Here is the postback Page_Load event handler:
    public void Page_Load(object source, EventArgs e)
    {
        FileStream fs = new FileStream(c:/Database/persons.txt, 
            FileMode.Append, FileAccess.Write);
        StreamWriter sw = new StreamWriter(fs);
        string name = Request.Params[txtName];
        string gender = Request.Params[txtGender];
        string age = Request.Params[txtAge];
        sw.Write(name + , + gender + , + age + \r\n);
        sw.Close();
    }
    

     
  15. Find the mistakes in the following ASP.Net code:
    <@ Find the mistakes @>
    <%@ Page Language=VB  %>
    <%@ Using Namespace=System.IO %>
    
    <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN 
        http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
    
    <script >
    public button1Click(int source, eventergs e)
    {
        OleDbConnection c = new Connection();
        c.ConnectionString = Provider=Microsoft Jet OLEDB 4.0; +
            Data Source=c:ectweb2\Database\persons.mdb;
        var sql = INSERT INTO Persons VALUES  + 
                (' + T1.Text + ', ' + T2.Text + ,  + 
                integer.parseInt(t3.Text) + );;
        OleDbCommand conn = new Command(sql, comm);
        comm.ExecuteQuery();
    
        // See previous problem for code to populate the controls.
    }
    </script>
    
    <htm xmlsn=http://www.w3.org/1999/xhtml >
    <head runat=server>
        <title=Find Mistakes />
        <link href=styles.css ref=stylesheet type=css\txt />
    </head>
    
    <body>
        <form id=form1 runat=server>
        <div>
            <p><asp:Button ID=Button1 runat=server 
                    Text=Button CssClass=.orange 
                    Click=Button1_Click</p>
            
            <p><asp:TextBox ID=T1 runat=server 
                    CssClass=.orange />  
            <asp:Label ID=Label1 runat=server 
                    CssClass=.orange Text=Name /></p>
            
            <p><asp:TextBox ID=T2 runat=server 
                    CssClass=.orange />  
            <asp:Label ID=Label2 runat=server 
                    CssClass=.orange Text=Gender />
            
            <p><asp:TextBox ID=T3 
                   CssClass=.orange />
             <asp:Label ID=Label3 
                   CssClass=.orange Caption=Age /></p>    
        </form>
    </htm>
    
    Here is the corrected code:
    <%--  Find the mistakes --%>
    
    <%@ Page Language=C#  %>
    <%@ Import Namespace=System.Data %>
    <%@ Import Namespace=System.Data.OleDb %>
    
    <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN 
        http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
    
    <script runat=server>
    public void Button1_Click(object source, EventArgs e)
    {
        OleDbConnection c = new OleDbConnection();
        c.ConnectionString = Provider=Microsoft.Jet.OLEDB.4.0; +
            Data Source=c:\\Database\\persons.mdb;
        string sql = INSERT INTO Persons VALUES  + 
                (' + T1.Text + ', ' + T2.Text + ,  + 
                int.Parse(T3.Text) + );;
        OleDbCommand comm = new OleDbCommand(sql, c);
        comm.ExecuteNonQuery();
    }
    </script>
    
    <html xmlsn=http://www.w3.org/1999/xhtml>
    <head id=Head1 runat=server>
        <title>Find Mistakes</title>
        <link href=styles.css ref=stylesheet type=text/css />
    </head>
    
    <body>
        <form id=form1 runat=server>
        <div>
            <p><asp:Button ID=Button1 runat=server 
                    Text=Button CssClass=orange 
                    Click=Button1_Click /> </p>
            
            <p><asp:TextBox ID=T1 runat=server 
                    CssClass=orange />  
            <asp:Label ID=Label1 runat=server 
                    CssClass=orange Text=Name /></p>
            
            <p><asp:TextBox ID=T2 runat=server 
                    CssClass=orange />  
            <asp:Label ID=Label2 runat=server 
                    CssClass=orange Text=Gender /></p>
            
            <p><asp:TextBox ID=T3 runat=server
                   CssClass=orange /></p>
                   
             <p><asp:Label ID=Label3 runat=server
                   CssClass=orange Text=Age /></p>    
        </form>
    </html>