Quws.docx
-
Upload
nelson-martinez -
Category
Documents
-
view
217 -
download
0
Transcript of Quws.docx
-
8/10/2019 Quws.docx
1/9
Q:5
Client-side state management
This maintains information on the client's machine using Cookies, View State, and Query Strings.
Cookies.A cookie is a small text file on the client machine either in the client's file system or memory of
client browser session. Cookies are not good for sensitive data. Moreover, Cookies can bedisabled on the browser. Thus, you can't rely on cookies for state management.
Hidden Fields- Hidden Fields are similar to a text box but does not get displayed on theUI. However you can see the value of hidden fields when you view page source in thebrowser. Using Hidden Fields, you can pass information from one page to another pagewithout the end user's knowledge, primarily for internal processing.
View StateEach page and each control on the page has View State property. This property allows automatic
retention of page and controls state between each trip to server. This means control value ismaintained between page postbacks. Viewstate is implemented using _VIEWSTATE, a hidden
form field which gets created automatically on each page. You can't transmit data to other page
using view state.
Querystring
Querystring can maintain limited state information. Data can be passed from one page to another
with the URL but you can send limited size of data with the URL. Most browsers allow a limit of255 characters on URL length.
-
8/10/2019 Quws.docx
2/9
Server-side state managementThis kind of mechanism retains state in the server.
Application StateThe data stored in an application object can be shared by all the sessions of the application. The
application object stores data in the key value pair.
Session StateSession state stores session-specific information and the information is visible within the sessiononly. ASP.NET creates unique sessionId for each session of the application. SessionIDs are
maintained either by an HTTP cookie or a modified URL, as set in the application's
configuration settings. By default, SessionID values are stored in a cookie.
Cache- The Cache object is an instance of the System.Web.Caching.Cache class. Cache is
stored on the server side and is more scalable in nature, as ASP.NET removes objects if the
memory becomes scarce. This also makes it unreliable in some cases. Cache objects can
have expiration polices set on them and is shared across users.
Profile- Profile data is stored in the SQL Server database by default. This database
structure is preset, so if you want any custom user details to be stored, you will need to
create a custom database and write a custom provider for it. Profiles are designed to store
information permanently.
Context.Items- The HttpContext object is provided by the Page.Context property. The
HttpContext.Items collection can be used to temporarilystore data across postback. View
state and session state can be used for a similar effect, but they assume longer-term
storage. Context can be used for storing data for one request only.
Q.8
validation controls?
Validation is important part of any web application. User's input must always be validated before sending
across different layers of the application.
Validation controls are used to:
Implement presentation logic.
To validate user input data.
Data format, data type and data range is used for validation.
There are six types of validation controls in ASP.NET
1. RequiredFieldValidation Control
2. CompareValidator Control
3. RangeValidator Control
4. RegularExpressionValidator Control
-
8/10/2019 Quws.docx
3/9
5. CustomValidator Control
6. ValidationSummary
RequiredFieldValidation Control
The RequiredFieldValidator control is simple validation control, which checks to see if the data is enteredfor the input control. You can have a RequiredFieldValidator control for each form element on which you
wish to enforce Mandatory Field rule.
CompareValidator Control
The CompareValidator control allows you to make comparison to compare data entered in an inputcontrol with a constant value or a value in a different control.
It can most commonly be used when you need to confirm password entered by the user at the
registration time. The data is always case sensitive.
RangeValidator Control
The RangeValidator Server Control is another validator control, which checks to see if a control value is
within a valid range. The attributes that are necessary to this control are: MaximumValue, MinimumValue,
and Type.
RegularExpressionValidator Control
A regular expression is a powerful pattern matching language that can be used to identify simple and
complex characters sequence that would otherwise require writing code to perform.
Using RegularExpressionValidator server control, you can check a user's input based on a pattern that you
define using a regular expression.
-
8/10/2019 Quws.docx
4/9
-
8/10/2019 Quws.docx
5/9
Q.2
Preprocessor directives are commands that are interpreted by the compiler and affect the output or
behavior of the build process. But the C# compiler does not have a separate preprocessor, like C andC++ you cannot use these directives to create macros. Preprocessing directives are top lines in our
program that start with '#'. The '#' is followed by an identifier that is the directive name.
Classification of C# language preprocessor directives are as follows.
Conditional compilation: We can include and exclude parts of the program based on the
conditions.
#if #else
#elif #endif #define #undef
Errors , Warnings , Line & pragma: The directive #error initiates the preprocessor to rise error,
#warninglike #error directive but it prompts warning to the user and continues with the process,
#linecan be used to hide sections of code from the debugger. The #pragma directive can either
suppress or restore specific compiler warnings.
#warning
#error #line #pragma
Region: If you want to indicate a certain block of source code with a name, you can indicate it with a
name and keep the entire block between #region and #endregion. So the C# code file is neatly
organized as blocks, and that can be expanded or collapsed visually.
#region #endregion
Q.7
ASP.Net server controls are the primary controls used in ASP.Net. These controls again could be grouped into thefollowing categories:
Validation controls- these are used to validate user input and work by running client-side script
-
8/10/2019 Quws.docx
6/9
Data source controls- these controls provides data binding to different data sources
Data view controls- these are various lists and tables, which can bind to data from data sources for display
Personalization controls- these are used for personalization of a page according to the user's preference,based on user information
Rich controls - these implements special features, for example, AdRotator control, FileUpload control,Calendar control etc.
The basic syntax for using server controls is:
However, visual studio has the following features, which helps in error free coding:
Dragging and dropping of controls in design view
IntelliSense feature that displays and auto-completes the properties
The properties window to set the property values directly
Example: Let us look at a particular server control - a tree view control. A Tree view control comes under navigation
controls. Other Navigation controls are: Menu control and SiteMapPath control.
Add a tree view control on the page. Select Edit Nodes... from the tasks. Edit each of the nodes using theTree view node editor:
Once you have created the nodes, it looks like the following in design view:
-
8/10/2019 Quws.docx
7/9
The AutoFormat... task allows you to format the tree view:
Add a label control and a text box control on the page and name them lblmessage and txtmessage
respectively.
Write few lines of code to ensure that when a particular node is selected, the label control displays the nodetext and the text box displays all child nodes under it, if any. The code behind file should look like this:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq; using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
-
8/10/2019 Quws.docx
8/9
-
8/10/2019 Quws.docx
9/9