Web Programming with ASP.Net & MVC 5
According to Microsoft, the __________________ expression is "an anonymous function that you can use to create delegates or expression tree types."
Lambda By using lambda expressions, you can write local functions that can be passed as arguments or returned as the value of function calls. Lambda expressions are particularly helpful for writing LINQ query expressions.
Why do we use responsive design and CSS styles to manage our layout and styles?
-CSS media Queries are time consuming -Bootstrap classes are methods to hide/show objects, based on the object width (such as the browser window) -It's easier to update the website when changes need to be made All the statements are true.
Which is the proper way to create a style rule, which will allow you to format the text color for a variety of HTML elements such as paragraphs, and lists?
.pink { color: pint; } .pink { color: pink; } The class is used to define a style for one or more elements within a web page or web site. #pink can only be used on one element, where the ID is set to pink. The color.pink would not work because color is not an HTML element. The p style rule cannot be used because it only formats the paragraph. The DIV style rule cannot be used because the # indicates that it can only be applied to a single element where the ID = "div". If the option was without the #, then it would represent the DIV element, and that might be plausible because the DIV tag allows you to nest other kinds of elements.
Which is a proper way to create a comment in HTML?
<!-- Comment --> <!- - Comment - -> is used for client side comments. // is used for single line server side comments and /* Comment */ for multi-line comments. You can use /// which is XML-based comments to describe the code you are writing. <% %> is used to insert server code into the markup of the web page.
Lambda expressions use the ___________ operator, with input parameters on the left side, and the expression on the right side.
=> The correct answer is =>. To create a lambda expression, you specify input parameters (if any) on the left side of the lambda operator =>, and you put the expression or statement block on the other side. For example, the lambda expression x => x * x specifies a parameter that's named x and returns the value of xsquared." - Ref: MSDN, http://msdn.microsoft.com/en-us/library/bb397687.aspx
Your boss wants to know if you can appraise web programs to ensure that they use proper coding conventions. List five coding conventions that professional web developers should follow.
Answers may vary. Identify and fix all syntax errors. Visual Studio uses IntelliSense to help you identify syntax errors. Follow industry standards such as the HTML standards as defined by the W3 Consortium. Use indentation to help identify proper nesting of markup codes. Use self-describing documentation such as using descriptive terms for field names, style rules and other items. Provide documentation within the markup pages including the title, meta tags (description and keywords) as well as comments including the programmer name, date and program information. Make sure to use correct case sensitivity with markup elements, attributes, variables and other programming elements.
Your boss has asked you to analyze a web program, Your job requires that you can analyze programs, in order to test, debug, and improve them. Specifically, your boss has asked you to 'fix' the current employee web-based database system. When a new employee is added to the database, the employee ID is not yet known. The web page won't add the employee to the database. Describe your approach to identifying the problem and suggest a potential solution.
Answers may vary. One reason might be that the initial able uses the employee ID as the primary field. This field must be unique across each record. One solution is to use a validation control to make sure the field is not empty. Another possibility is to assign a different field, like a recordNumber, as the primary field. Then the employee ID can be inserted.
Your boss wants to know if you can construct web programming solutions from given problem description. The directions your boss gave you was to create an online shopping cart which can implement credit card transactions and manage the product inventory and delivery systems. You decided to use ASP.NET Web Forms to build the application. Explain why you would choose ASP Web Forms over creating the application in just HTML and CSS. Provide at least five reasons based on the readings, lessons and classroom discussions.
Answers may vary. Some of the responses might include, ASP provides the ability to maintain state, to connect the user across page requests. Web pages maintain state within the web page using ViewState. The ASP application can be used to maintain session data, across page requests. ASP.NET provides for the use of a variety of new controls such as the Calendar, which can be configured using significantly less code. Multiple themes can be easily configured for ASP applications that can change dynamically based on criteria the programmer defines. Web forms provide validation controls which make it easy to validate form data. ASP.NET uses the .NET Framework which uses the same languages like C# and classes in the .NET Framework.
Your boss would like to have different styles associated with different sections of your web site. What folder should you place the images and style sheets in your website to be able to quickly configure the styles across these sections?
App_Themes folder App_Themes is a special folder which stores subfolders, each called a theme. The name of the theme is the name of the folder. Within the theme folder, you can store your style sheets. So, you can create a theme called Green by simply creating a folder called Green and storing it in the App_Themes directory. App_Data is used for the code files such as classes. The Images folder is used for storing images.
The three A's in testing in order are:
Arrange, Act, Assert @Arrange method will set up the conditions for the test such as define member object with a value, create a repository parameter, add a member with passing member information, contact AdminController with repository parameter, change login names or whatever the logic is, etc. The Act state will attempt the operation such as change the login parameter and actually performing the test. Assert is what do you want to test. For example to see if the results are equal. If they are, it's true, then submit changes. It will verify the result that the one required was correctly identified.
The ____ property of the GridView should be set to false, to indicate that you want to customize the data bound to the GridView columns.
AutoGenerateColumns AutoGenerateColumns is used to indicate if you want to customize the columns. DataKeyNames is set to the ID column that is the primary key field. The DataSourceID just indicates which data source control. The Parameter is to used to pass information to the SQL commands.
Which method is used to update data from the form to the database using the EditItemTemplate in a TemplateField?
Bind The data binding is Eval, which means it's only one-way for showing data. When you use the textbox, to edit the Reorder Level use Bind. So, that field uses Bind, which is two-way binding. It means that this field can be updated in the UpdateCommand.
In exception handling, the __________ section displays the error captured when the code is executed.
Catch The Try section contains the commands to execute and the Catch section contains the code that is run when the error is captured, which may display the error messages.The Try-Catch-Finally block is very important because you want to make sure that if an error occurs; you catch it gracefully and inform the web administrator right away via email or other automated notification. You can use this block around the database section, or specific commands. You can catch different types of errors and send custom error messages.
What is the name of the control in the Master page used to identify where to place content from the Content pages.
ContentPlaceHolder You specify where the web form called the content page with custom content, the content region. The content region is defined by a control called the ContentPlaceHolder. Then, on the content page, you can only modify the content on those locations. ContentPlaceHolder is the control on the master pate. The ContentPlaceHolderID connects the two files.
Which property is used to point to the content region in the master page?
ContentPlaceHolderID The ContentPlaceHolderID is used to point to the content region in the master page. Content is the control on the control pages. ContentPlaceHolder is the control on the master pate. The ContentPlaceHolderID connects the two files.
Which attribute is used by all validation controls?
ControlToValidate and ErrorMessage For each of these controls, you need to identify the ControlToValidate and the ErrorMessage that you want displayed. The isValid property is useful if you want to capture the event and include some custom code. Usually, if the form is valid, it's processed by the server. You have to specify the MinimumValue and MaximumValue for the RangeValidator control. CompareValidator compares value to another control or value (which can include a date or other data types); using ControlToCompare or ValueToCompare. You can specify the Operator.
In a Model View Controller application which object intercepts and handles the page request?
Controller The Controller manages the page requests. That is why there can be multiple views assigned to one controller. The View is simply the application that the user interacts with.
What is the helper method named Html.EditorForModel, in the Razor engine, used for?
Creates the editing interface by inspecting the model Creates the editing interface by inspecting the model so that users can edit the data in the web page.
Which tag is used to identify the version of HTML supported in the web page?
DOCTYPE DOCTYPE. Enctype is used in the form to identify how to send the form data. The Meta tag is used to identify name and key pairs of data that is often used by search engines. The Title is used to identify a name for the page that is displayed in the browser title bar and in the favorites and history lists in the browser. HTML is the root tag in the web page.
Which property of the GridView Control allows you to specify the field name in the database which is then used to be bound to the column?
DataField Set AutoGenerateColumns="false" for only the fields listed in the Columns collection will be displayed. Each column in the GridView table is bound to a field in the database which is identified with the DataField property. So, the column is a BoundField. There are other types of fields too. You can configure the HeaderText to use some HTML tags. CommandField column is another type of data column. You can use one of the built-in commands. You can use a button or hyperlink for the Select command. Notice the DataKeyNames is the field name for the column that contains the value selected when the user clicks on the Select button. That value can be passed to another query.
Your boss wants to display all of the government holidays on a company calendar on the home page. Which event handler is used to modify the date in the calendar control?
DayRender You can insert content into the calendar for any day using the DayRender event handler. The DayRender is run for each day when the calendar is created. So, you can easily intercept the event handler and write custom code to insert content, including images into the table cell that stores the day information.
The three applications in the sample project in your solution are:
Domains, WebUI, UnitTests
Which command method will allow you to execute INSERT, UPDATE and DELETE SQL commands?
ExecuteNonQuery If you use ExecuteReader as shown above, you return a data reader object to display data - so you can only pass a SELECT query using the ExecuteReader method. ExecuteNonQuery will allow you to execute INSERT, UPDATE and DELETE SQL commands. The book does not use ExecuteScalar in many examples, but this is useful for stored procedures, which return a single value such as the count for the number of records returned.
The trace feature can only be turned on in the web.config file. @The trace feature can be turned on at the web.config file or inside a file by setting Trace="true" in the Page directive.
False
If you write the code @{ Layout = "null";} the code use the default start-up layout file.
False False. Set to null in the code view, if no view layout is needed. This will overrides start file.
True or False. When creating a SQL statement, use pound symbol quotes (#) for enclosing strings.
False False. When creating a SQL statement, use single quotes (') for enclosing strings.
All tables must have a primary key field.
False False. While this is recommended, it is not required.
ASP uses Application Cookies to maintain a unique session identifier across page requests.
False There are no such things as application cookies. The Session ID cannot identify the user, but it can track the session and the activity across a single session, across page requests. Other information such as IP address or user name or other unique information would be able to be collected and saved to connect the user with past sessions.
True or False. If you use a blank space in the field name in the database or a table name you can enclose the names in quotes when you create the SQL commands.
False You should use square brackets around field and table names that have a blank space, or use an alias in the SQL command, with the AS keyword.
The Form tag has a Method _______ attribute that sends the form data appended to the URL as a QueryString.
Get GET. In the Form element, you would use the action attribute to identify the web server program that would be used to retrieve and process the data in the form. The Method attribute is used to identify how to send the data. The two methods are GET and POST. Both send the data as clear text. However, GET sends the form data as a set of name and value pairs appended to the URL, as a QueryString. This QueryString is viewable by the user and can be a security risk if other users have access to the computer.
Which Razor Helper methods will create the hyperlink?
Html.ActionLink() The answer is Html.ActionLink() such as @Html.ActionLink("About this Website", "About")
Which tag is used to insert the individual items in a drop-down list or regular list box where the user can select an item?
Option Option. Select is the name of the HTML tag. The attribute is Option. Text and Value are attributes of the Option tag, used to identify the text to display and the value to pass when the list item is selected. The Option tag is nested within the Select tag.
Which property of the GridView control will limit the page to 10 records per table displayed on one web page at a time?
PageSize You can further customize the paging to allow a specific number of records per page, with the PageSize property. PageButtonCount property is used to limit the number of pages displayed. This is useful if you have a large number of records. You can also change the page navigation bar to use < > signs or words such as first, last, next and previous or page numbers with PagerSettings-Mode property. You can add the navigation bar to the top and bottom if you want with the PagerSettings-Position property. You can also change the text displayed, or modify it as an image. As you can see, some of the properties are set in the GridView globally and others in the PagerSettings.
Which server side code will retrieve the page that the user was at before they came to my web site?
Request.ServerVariables["HTTP_REFERER"] When you use the server variables, you can retrieve information that is passed in the http header. The HTTP_REFERER contains the complete address of where the user clicked, which led them to your page. The Response.Redirect is used to send you to another page and the page must be in quotes. The Void method is not a server side programming command, nor the href property.
Which validation control is primarily used to require a user to enter at least one character in the textbox?
RequiredFieldValidator The RequiredFieldValidator control checks to see that there is at least one character in the field. The RangeValidator control checks to see if the value is between a range (which can be numeric, alphabetical or date); You have to specify the MinimumValue and MaximumValue. The CompareValidator control compares value to another control or value (which can include a date or other data types); using ControlToCompare or ValueToCompare. You can specify the Operator, in other words, if they want to check if they are equal or one is greater than the other, etc. The RegularExpressionValidator control compares to the regular expression defined with the ValidationExpression. The CustomValidator control creates your own function to validate the contents can specify the format, such as a bulleted list. The ValidationSummary control allows you to display the errors in one central location.
Which keyword in C# is used to indicate that no value is returned from a method.
Return Notice the keyword Sub is used for VB and Void for C#. Void means that no value is returned. The Function keyword in VB will return a value from the function to the code that called the function.
Which sql query is used to retrieve the lastname and firstname from a table called employees for only employees who live in the state of Texas?
SELECT lastname, firstname FROM employees WHERE state = "Texas" SELECT lastname, firstname FROM employees WHERE state = "Texas". You would not use <> because that means not equal to. You don't use * because that retrieves all fields and is inefficient. There is no IN ORDER keyword or WHEN keyword. There is an ORDER BY to sort the results.
In the connection string, what does |DataDirectory| mean?
Shortcut that looks for the data file in the App_Data folder The |DataDirectory| is a shortcut that looks for the data file in the App_Data folder. The Name is the name that you will store the connection string property. The Provider Name is the name of the class that is used to connect with the database.
Which navigation control is often called a breadcrumb trail because it allows you to navigate back to the previous items, and is commonly used on web sites?
SiteMapPath The SiteMapPath control is often called a breadcrumb trail because it allows you to navigate back to the previous items, and is commonly used on web sites. It's easy to implement because it will always look for the web.sitemap file in the root folder of the web site so you do not need to set the DataSourceID.
In the browser the life cycle for asynchronous postbacks are managed by the _______________ class located within the Microsoft AJAX Library?
Sys.Webforms.PageRequestmanager In the browser the life cycle for asynchronous postbacks are managed by the Sys.WebForms.PageRequestManager class located within the Microsoft AJAX Library. The other classes are part of the .NET class library.
Which window is used to run the application tests?
Test Explorer Test Explorer. You save the tests in the UnitTests project in the Solution Explorer with the other files. The Server Explorer contains the data connections and allows you to access your database within Visual Studio.
What is the Mock Repository used for?
Testing purposes
Which data type would be best for a field that uses social security numbers?
There are no calculations with the number so use text.
Dependency Injection is used to implement the interface without implementing the object directly.
True The Dependency injection passes implementation of the required interfaces to the class constructor. At runtime, the interface is created and passed to the PasswordResetHelper constructor during instantiation. No compile time dependency is required. Dependency is managed at runtime. The Inversion of Control (IOC) This is use to instantiate the concrete implementation of interfaces without creating dependencies elsewhere.
Primary key values must contain a unique value and cannot contain a NULL value.
True True. All records must have a unique value in the primary key field, which cannot be null.
Relational database management systems use primary and foreign key fields to create one to many relationships between tables.
True True. Primary key fields are unique values to identify the record in the first table. In the related table the corresponding values are found in the foreign key field.
Ninject is an example of Dependency Injection software.
True True. The other examples include Microsoft Unity from CodePlex.
The MVC 5 Framework supports jQuery Mobile and allows using a content delivery network (CDN) to locate the jQuery files. Therefore there is no need for NuGet Packages for using jQuery in your MVC 5 applications.
True When you are creating a Mobile Layout, the MVC Framework supports display modes, to create different views delivered based on the client request. The application will automatically identify mobile clients. There is no List.Mobile.cshtml, and so the List.cshtml file is processed instead. By using jQuery Mobile, and a content delivery network (CDN) there is no need for NuGet Packages.
A strongly typed view will assign a model to the view, such as @model Razor.Models.Product.
True When you create a view, a list is retrieved list from the controllers of what models are available. The controllers know about the views and models because the controllers process the request for the views. The list of models that can be bound is also displayed in the dropdown list box. You can choose to bind the view to a specific model, like the Products model.
Which type of testing isolates classes and tests them individually, but not cross-class testing?
Unit Testing Unit Testing. Integration testing tests across classes and regression testing tests how the user interacts with the application.
The _____ is used to define the area where the content can be updated asynchronously?
UpdatePanel The ScriptManager and ToolkitScriptManager helps manage the process but the UpdatePanel defines the area.
The _________ control is used to indicate the current state of the communication for a web page with AJAX enabled.
UpdateProgress The UpdateProgress control is used to indicate the current state of the communication. The ContentTemplate is the area you will update and the UpdatePanel also helps define this area. ProgressTemplate is what to display during this time.
When you are working with a Model View Controller application, which object is a file that ends in .aspx?
View The View is simply the application that the user interacts with. The views are ASP files that end in .aspx but they can use the master-content page model that you saw in ASP WebForms. At the end of the day, Models and Controllers are classes, which are C# files that help separate business logic and data and the files end in .cs.
The _____ can help make asynchronous programming calls to the web server when an event is triggered in the browser.
XMLHTTPRequest XMLHTTPRequest Object that can help make asynchronous programming calls to the web server when an event is triggered in the browser.
What is the name of the default view file to start up, which is the set the layout to basic layout that can then be used each time a web page is requested?
_LayoutView.cshtml _ViewStart.cshtml. The default view file to start up, which is the set the layout to basic layout that can then be used each time is _LayoutView.cshtml. Files beginning with _ in the Views folders are notreturned to the user. They are used to create the view.
What JavaScript function is called when an event on the client browser has been raised that needs to be processed by the server?
_doPostBack The page will send the request to the server to reprocess the page when an event on the client browser has been raised that will call a JavaScript function called _doPostBack. So, clicking on a button will cause the __doPostBack function to execute and submit the page back to the web server. You do not need multiple form elements for this reason.
What is the data type for 245.99 that will be used to represent the price of a product?
decimal currency. You would not use string because that's for alphabet and numeric values that are not in calculations. In SQL Server databases it's usually called char or text. Integers are whole numbers without decimal values. Decimals can be represented as currency in databases but in SQL Server, it's called money. There is no fraction data type. Reference: http://msdn.microsoft.com/en-us/library/ms187752.aspx
If the Controller is named MyController, and the ActionResult is named MyPage, and the Model is named MyModel, and the ViewResult of the MyController is named MyHome, what should the user be typing into the URL of the browser?
http://localhost:2909/MyHome If anyone calls the view that is managed by the MyController class from the browser, MyController, will return a view. The ViewResult object is displayed on the browser which in this case is MyHome. So they should type in Home. Again, you can have multiple views, but it's the one that the controller returns that counts here. The ActionResult didn't send back a view, the ViewResult does that.
It is important to understand the difference between HTML and ASP.Net controls. The two properties of the control which must be configured for all web server controls are _____ and _____.
id, runat Notice that server controls have 2 requirements. They have an ID attribute (not name, it must be the ID attribute) and they have the runat="server" set. That tells the Asp.Net engine that the control is a server control so it knows to process it. HTML or controls without runat set, are not processed, just returned to the browser with the output from the rest of the program. The process of converting server controls to HTML is called rendering. . The Runat property is required to be set in all ASP.NET server controls. The Runat property is used to tell the ASP engine to recognize the control. In addition to the Runat property, you need to set the ID property for any Server control. Technically, if none is assigned, the server will assign one. However, if you don't assign it, you will have problems programming against the control during design time. So, always assign an ID to any server control! By default, if you drag and drop the control from the Toolbox, the ID and Runat properties are already set for you.
What database task is not available with the GridView by default?
inserting a new record
To set the custom errors to only be displayed then you are logged in locally, what property below should you set?
mode="RemoteOnly" The mode property in the customErrors node sets where the error pages are displayed. When it is set to RemoteOnly, it's available only to non-local users. A defaultRedirect property is used to assign to a generic error page. The error child nodes can be configured for each specific statusCode and assigned a specific error page with the redirect property.
Which is the correct way to retrieve the stored connection string?
string CS = webConfigurationManager.ConnectionStrings["Northwind"].ConnectionString; string CS =WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString; You need to make sure to use the WebConfigurationManager.ConnectionStrings to retrieve the collection of connection strings. In the web page code, you can access the connection string. This code creates the connection object and passes the connection string from the web configuration file. You still need the webConfigurationManager to retrieve the connection string.
What is the name of the file that stores configuration about the web site?
web.config web.config. The SiteMap is a file called web.sitemap and is used for the navigation information on the web site. The web.config can be stored at the root level and in nested folders within the web application and contains the configuration of the web site.
The ___ is a shortcut that looks for the data file in the App_Data folder and is used in the web.config file.
|DataDirectory| The |DataDirectory| is a shortcut that looks for the data file in the App_Data folder. MapPath just maps the relative path to the real physical path. DataFile just indicates where the datasource should locate the file.
Where are shared layouts for views stored by default?
~/Views/Shared/ Some layouts are shared, and stored in the Views/Shared folder.