+ All Categories
Home > Documents > ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for...

ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for...

Date post: 06-Jul-2020
Category:
Upload: others
View: 5 times
Download: 0 times
Share this document with a friend
35
ASP.NET Questions and Answers 1] What is .NET? Explain the Categories of .NET? .NET Framework is a software framework developed by Microsoft that runs primarily on Microsoft Windows. It includes a large class library named Framework Class Library (FCL) and provides language interoperability across several programming languages. Programs written for .NET Framework execute in a software environment named Common Language Runtime (CLR), an application virtual machine that provides services such as security, memory management, and exception handling. FCL and CLR together constitute .NET Framework. Microsoft .NET consists of four major components: Common Language Specification (CLS) Framework Class Library (FCL) Common Language Runtime (CLR) Common Language Specification The CLS is a common platform that integrates code and components from multiple .NET programming languages. In other words, a .NET application can be written in multiple programming languages. .NET includes new object-oriented programming languages such as C#, Visual Basic .NET, J# (a Java clone) and Managed C++. Framework Class Library The FCL is a collection of over 7000 classes and data types that enable .NET applications to read and write files, access databases, process XML, display a graphical user interface, draw graphics, use Web services, etc. Common Language Runtime The CLR is the execution engine for .NET applications and serves as the interface between .NET applications and the operating system. The CLR provides many services such as: Loads and executes code Converts intermediate language to native machine code Manages memory and objects Enforces code and access security Handles exceptions Provides type-checking Categories of .NET Desktop Mobile ASP.NET Desktop Example of Desktop Application is AVG Antivirus Software. We expect Desktop Applications to have Internet Connectivity. Similarly, AVG Antivirus Software checks whether the system is connected to the internet. If yes, then it will download the latest signatures and remain up-to-date. Desktop Applications also allow plug-ins. Google toolbar is an example of it. This Google toolbar is attached to the Internet Explorer. It means that it is possible to integrate other plug-ins into an existing Software .Desktop Applications become functionally richer with time. Mobile While developing Mobile Applications, screen size should be considered. As the geometry of every mobile phone differs, so does the user interface for it. Mobile phones may have touch sensitive
Transcript
Page 1: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

ASP.NET Questions and Answers

1] What is .NET? Explain the Categories of .NET?.NET Framework is a software framework developed by Microsoft that runs primarily on

Microsoft Windows. It includes a large class library named Framework Class Library (FCL) and provides language interoperability across several programming languages. Programs written for .NET Framework execute in a software environment named Common Language Runtime (CLR), an application virtual machine that provides services such as security, memory management, and exception handling. FCL and CLR together constitute .NET Framework.

Microsoft .NET consists of four major components:

Common Language Specification (CLS) Framework Class Library (FCL) Common Language Runtime (CLR)

Common Language SpecificationThe CLS is a common platform that integrates code and components from multiple .NET

programming languages. In other words, a .NET application can be written in multiple programming languages. .NET includes new object-oriented programming languages such as C#, Visual Basic .NET, J# (a Java clone) and Managed C++.

Framework Class LibraryThe FCL is a collection of over 7000 classes and data types that enable .NET applications

to read and write files, access databases, process XML, display a graphical user interface, draw graphics, use Web services, etc.

Common Language RuntimeThe CLR is the execution engine for .NET applications and serves as the interface between

.NET applications and the operating system. The CLR provides many services such as:

Loads and executes code Converts intermediate language to native machine code Manages memory and objects Enforces code and access security Handles exceptions Provides type-checking

Categories of .NET Desktop Mobile ASP.NET

DesktopExample of Desktop Application is AVG Antivirus Software. We expect Desktop Applications to have Internet Connectivity. Similarly, AVG Antivirus Software checks whether the system is connected to the internet. If yes, then it will download the latest signatures and remain up-to-date. Desktop Applications also allow plug-ins. Google toolbar is an example of it. This Google toolbar isattached to the Internet Explorer. It means that it is possible to integrate other plug-ins into an existing Software .Desktop Applications become functionally richer with time.

MobileWhile developing Mobile Applications, screen size should be considered. As the geometry of everymobile phone differs, so does the user interface for it. Mobile phones may have touch sensitive

Page 2: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

screen or may use pointers, stick used to click on screen. For a mobile phone connectivity is intermittent. We have to account all of these possibilities while creating Applications for Mobile Devices.

ASP.NETHere we are able to create different web-portals. Example, Yahoo web-portal, where information about weather of different cities, calendar system, email system, are all in one place. Using ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website, is now faster because of .NET.

2] Difference between Web application and Desktop application.

Web ApplicationA Web application, or Web app, is a Web site that allows users to access and interact with software from any computer or device that is connected to the Internet. Users often interact with Web applications directly at the Web site, referred to as the host, through their Web browser. Some Web sites, however, require you download the software to your local computer or device. Web application hosts often store users’ data and information on their servers. Some Web applications provide users with an option of storing data locally on their own personal computer or mobile device. Many Web application hosts provide free access to their software, such as Google Docs. Others, such as Google Earth, offer part of their Web application free and charge for accessto a more comprehensive program. A web application can be accessed from any computer no matter where you are. This is due to the fact that a web application only exists online. If the connection is lost, you won’t be able to access a web program.

Desktop ApplicationsAny software or computer program that can be installed on Stand Alone Operating systems or personal computers can be referred to as Desktop Application. Users install desktop application on a single computer and use it to perform a specific task. In a networked environment, desktop applications can be used by more than single user. The journey of software application development started with Desktop applications. E.g. the most common examples for desktop applications are word processors and media player. Desktop applications have traditionally been limited by the hardware on which they are run. They must be developed for, and installed on a particular operating system, and may have strict hardware requirements that must be met to ensure that they function correctly. Updates to the applications must be applied by the user directly to their installation, and may require hardware upgrades or other changes in order to work.

3] Explain State Model.The Stateful and Stateless models of software application behavior define how a user’s web browser communicates with a web server. In the earliest years of the Web, sites tended to be Stateless. Pages were static, not varying from user to user. Later, websites included the stateful model, which delivered pages with information unique to each user. Stateful web applications are essential for modern e-commerce such as online retailers and banks, but require sophisticated programming to work effectively.

Stateless ModelIn the pure form of the stateless model, a client program makes a request to an application server,which sends data back to the client. The server treats all client connections equally and saves no information from prior requests or sessions. A website that serves up a simple static web page is agood example of the stateless model. The server receives requests for pages it hosts and sends the page data to requesting browsers

Page 3: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

Stateful ModelWhen an application operates in a stateful mode, the server keeps track of who users are and what they do from one screen to the next. Preserving the state of users’ actions is fundamental to having a meaningful, continuous session. It typically begins with a login with user ID and password, establishing a beginning state to the session. As a user navigates through the site, the state may change. The server maintains the state of the user’s information throughout the session until logout.

For example, when a user logs into a bank’s website, the server creates information about this session. The information may reside in the server’s memory, but it may also be stored in the browser. The server keeps track of your session by recording unique information about the session, such as a user’s IP address. In addition, the developer can create additional server-side variables used by the programs on the server. These variables remain intact as long as a session is active, vanishing upon logout or session expiration.

When running websites that use the stateless mode, a cloud server has a job that is relatively easy, serving up pages without the need to save the user’s data. A stateful site has additional memory overhead for each user, needed to store basic session data plus user responses and other data required by the application. A savvy operations staff keeps a close watch on server memory and CPU performance data, looking for bottlenecks that can affect a site’s responsiveness.

Ref: (link)

4] Explain Web Application Fundamentals. Web application has no user interface, as it is running in a server. Most of the Web Application development is done in an object-oriented manner. Web application is organized in terms of classes and different pages. Pages contain directives and HTML tags. The Client would send a request for a particular webpage. Directives within the pages and the classes work together, to generate a response. This response is in HTML. The response is then sent to the client. The response may contain text, image, videos, etc. The combination of all these steps, results in a response. For sending a response HTTP protocol is used. Browser interprets this response and renders the user interface.

5] Explain Web Application Development and Why locally? Development is done on a local machine Once the application is developed we deploy it on a remote machine, which has Web-

server There are different options available for Web Application development, like ASP.NET, PHP,

and JAVA. If ASP.NET is selected then we will require Internet Information System (IIS), if PHP is used

then Apache we server will be required, similarly if JAVA is used then servers like WebLogic, WebSphere or TomCat is needed.

Locally In Web Application development, it is important to Create, Build and Test locally. Deploy the

Application on a Web-server only on its successful completion. When trying to create an application, it is going to take more than one day. Hence, time is

required.

Page 4: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

An incomplete application cannot be exposed, to the users. We cannot do half-job and make it available to everybody in the world

Hence, do development and testing locally, and then deploy the application on a web-server

This will improve the speed and efficiency, when compared to remote development.

6] Web development model.Same as Question 4

7] Three things common to all WebsitesThree things common to all websites are as follows:

One of them is Location. Every single website will have some or the other, URL. Example, yahoo: www.yahoo.com , google: www.google.com. A unique way through which we are able to reach a particular website is Uniform Resource Locator (URL). Second is the Transfer Protocol, example, HTTP. When we send a request or get back a response there has to be some rules, which are to be followed. Every response has to be a HTTP response, i.e. the response has to be created according to HTTP protocol. Similarly, when we make a request for a particular page on a website,the request has to go in a standard form known as HTTP request. HTTP is Hyper Text Transfer Protocol. Request-Response model of a website works on this HTTP protocol. Third is Publishing.All the content that is published is in the form of HTML i.e. Hyper Text Markup Language. Information in present world is Complex. We should have some way of Identifying this Information and also to publish this information. Using HTML, documents containing spreadsheet, video, image, sound clip, etc. can be created. All of this, retrievable at the click of a button.

8] HTML important concepts.In the beginning there is a tag which identifies the type of document. Following that there would be, the name of the HTML standard being used, to create the html file. Then there would be HTMLtag, inside which another tag, <head>, is embedded. That is <head> tag would be inside <html> tag. The tags are always within angle brackets < >. Beginning of the tag and the End of the tag has to be clearly identified. For example, <html> and <head> are the opening tag and </html> and </head> are closing tags, respectively. The head section contains the title for every document. That is inside <head> tag, there is <title> tag. Following header would be <body> tag. Inside the <body> tag we write the content which we want to appear in the HTML page. Other points to remember:

HTML is a markup language, not a programming language. Extension of HTML document is .htm or .html When an HTML file is opened in a notepad, we will not be able to see the actual

Presentation. Only a Web-browser like Firefox or Chrome can render a HTML file. All HTML documents must have short Title. All Tags must be within <html> </html>

9] Differentiate between Dynamic webpage and Static webpage.

Page 5: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

10] HTML Tags

Page 6: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

Image Ref: (Click)

11] What is a Dynamic Webpage/Website? Give Examples of it.A dynamic website is a webpage that changes Information, data, based on the user. Information changes, depending on the user, the time of the day, the time zone, the viewer's native language, and other factors. It responds to the user's needs, and provides relevant information to meet them,by accessing information in a connected Database. This type of web page allows users to go beyond reading text and looking at graphics. It allows for an interactive experience, with the user being in control of the information he views. There are many types of dynamic web pages. Example of a dynamic web page:

Search Engine Email Websites Banking Websites where users can access their personal financial information Websites that base their information on location, such as a national weather page

12] Explain the process, how are contacts added from the webpage?There are three ways to store data. First is to, store data/contact information in text file.

Second is to, store data/contact information in XML format. Third is to, store the data/contact information in Database. We will select the Text File method for now.

The contact information i.e. name, telephone number and mobile number will be stored on separate line for each individual on the text file. Comma ( , ) will be used to spilt the fields from one-another. Example, on one line of the text file: Rajesh Diwan,2246347,9853103449 and on the next line of the text file: Mansoor Sheikh,45678902,9422145678. This way of organizing data is known as CSV format, i.e. Comma Separated Values.

Page 7: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

We will also create a class called FileContact. FileContact class will inherit data from Contact class. To read and write data, ASP.NET has two classes known as StreamReader and StreamWriter. StreamReader class reads from a file whereas StreamWriter class writes to a file. Stream is a sequence of bytes, which are either going into a file or coming from a file. System.IO namespace is required to use StreamWriter and StreamReader class.

To write the data to the text file in CSV fashion, WriteToFile ( ) method is created in the FileContact class. WriteToFile ( ) method contains a StreamWriter object. This object is used to call the method WriteLine ( ) and write name, telno and mobileno in string variables. These strings are separated by comma and concatenated. The resultant string would be written to text file.

To read the data/contact information from the text file, LoadFromFile ( ) method is created in the FileContact class. LoadFromFile ( ) method contains a StreamReader object. This object is used to call the method ReadLine ( ) and the resultant string is collected in the string variable line. It is important to check whether line is empty or not. Hence, by using the condition, if ( line !=null ) ,we get the result true if data is present or false for empty variable. Now, to split it across comma ( , ) we will call a function line.Split ( ‘,’ ). The string is then split-up into three different parts and then store into list array. List Array is array of string. Hence, list [0], list [1] and list [2] would containname, telno., and mobileno.

13] What is ContactList class?ContactList class is created in order to manage multiple contacts. ContactList class will contain a zero argument constructor, Search ( ) function, LoadFromFile ( ) function, SaveToFile ( ) function and a ArrayList object to store name, telephone number and mobile number. Namespaces like System and System.Collections will be required for this class. ArrayList object name will be m_list.m_path will be a protected string, used for storing the path to the file. LoadFromFile ( ) function willallow to load contacts from the file into the memory. StreamReader class object is created, path is passed to it, in order to read from file. To read from file we will create an infinite while loop i.e. while ( true ). Inside the loop FileContact class object is created, this object is used to call LoadFromFile ( ) method. Remember, there are two LoadFromFile ( ) methods, one in ContactList class and second in FileContact class. After checking i.e. if ( !con.LoadFromFile (sr) ) then break outside the loop else add the contact information to ArrayList using Add ( ) method i.e. m_list.Add (con ). Once the control is outside the while loop close the StreamReader i.e. sr.Close ( ).

14] What is ArrayList ? Explain.ArrayList myArrayList = new ArrayList();

Size varies as required Not type-safe Collection of elements of the same or various data types Reverse, Contains, Sort and a few other useful methods are available that we don't get with

Arrays Useful when you are not sure about the size of the collection or you may need to have more

than one data type in the collection Elements are accessed by zero-based index The data type of an ArrayList is an object type Values are assigned by calling the Add method as in the following:

ArrayList myArrayList = new ArrayList();

myArrayList.Add(2);

myArrayList.Add("OOPS");

foreach (object obj in myArrayList)

Page 8: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

{

Console.WriteLine("From arrayList " + obj.ToString());

}

Console.WriteLine("-------");

15] What is a website ? What are the features of a great website ?A website, or simply a site, is a collection of relevant web pages, including multimedia

content, typically identified with a common domain name, and published on a web server. A website may be accessible via a public Internet Protocol (IP) network, such as the Internet, or a private local area network (LAN), by referencing a uniform resource locator (URL) that identifies the site.

Websites have many functions and can be used in various fashions; a website can be a personal website, a commercial website for a company, a government website or a non-profit organization website. Websites are typically dedicated to a particular topic or purpose, ranging from entertainment, social networking to providing news and education. All publicly accessible websites collectively constitute the World Wide Web, while private websites, such as a company's website for its employees, are a part of an intranet.

Features of a great website:

FunctionalA website is designed to serve a purpose, usually to solve a problem. For example, a job board has a purpose where employers can post jobs and job seekers can find and apply for jobs.

EasinessA website should be easy to use and navigate. When users visit your website, do they find the information they are looking for, without struggling? Does your website provide easy navigation to jump from one page to another and go back?

Relevant ContentYou do not want to put content on a website that is not relevant to the users. You do not want to put car details on a job board. If your website is a job board, it should have content and tips relatedto being a good candidate such as how to create a professional resume and how to behave in an interview. You do not want to post about cars or sports on a job board.

ModernYou want to make sure your website is using current trends and technologies. You do not want to build a website that does not support today’s needs. For example, responsiveness and fluid web designs are the key requirements for modern websites. You do not want to create fixed page layouts for your website that doesn’t support mobile readability.

OptimizedYour website and its content should be optimized for different devices, browsers, data speed, search engines, and users. If your website is not optimized for mobile data users and their download speed, users may leave your website. If your website does not support common modernbrowsers, you may be missing out on some users. If your website is not optimized for popular smartphones and their sizes, users may not want to visit your website.

ResponsiveResponsive web design is a modern need. A responsive website changes its layout and options tofit the device and browser size. For example, a website may provide more options on a large PC monitor compared to on a mobile phone.

Page 9: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

Performance and SpeedDoes your website load fast enough to show visitors what they are looking for? Your website cannot be slow, when presenting content to its visitors. If your website takes more than two seconds to load, then it is too slow.

ReliableIs your website reliable? If I apply for a job, does your website send me on-time notifications and messages to keep me posted with the updates? Can I access your website whenever and wherever? Is your website up and running 24/7?

ScalableDo you have sufficient infrastructure to support your website and its visitors? A website should be able to scale to a number of potential visitors. Not only should the website's user interface be scalable but the back-end database, APIs, and services too should be able to scale.

SecureSecurity is a major concern to today’s web visitors. You need to make sure that your website follows industry standards and guidelines. For example, if you have user registration feature, you want to make sure that user passwords are encrypted and not displayed in plain text.

16] What is CSS ? Types ? Uses ? Priority ? Selectors ?CSS is described as following:

CSS stands for Cascading Style Sheets. CSS is used to define a display property of our HTML tag or element. CSS is powerful language that makes the website beautiful, attractive and user friendly.

The following are the advantages of CSS:

CSS saves time. We write a CSS code only once and use it again and again in our HTML projects.

Pages load faster. If we use CSS, it speeds up the web page loading time because we don'thave to write HTML attributes for every HTML tag.

Easy maintenance. If we want to change the design of our web page, it can be done by only making certain changes in CSS file.

Platform Independence. CSS is platform independent.

Three types of CSS:

Inline Style External Style Internal Style

Inline Style: Inline style is used for changing the property of particular elements or HTML tags.

Page 10: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

External Style: External style sheet is used for making the changes in the layout of the whole website, using a single or multiple style sheets.

Internal Style: Internal style sheet is used for applying the style on single page only. It may be used when we want to change the style of a particular HTML page.

Page 11: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

Priority Inline style (inside an HTML element) goes first. External and internal style sheets (in the head section) are applied afterwards. Browser default is taken if no style is defined.

Page 12: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

Example:

Page 13: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

CSS Syntax:In CSS, selecting the particular element follows the following rules:

Selecting the element Declaration of property

CSS Selectors:CSS selector is used for selecting the HTML element to change their style.

Types: element selector id selector class selector grouping selector

element selectorIn CSS, we use the name of element for selecting the particular element.

Page 14: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

id selectorFor selecting the element using the id attribute, the id should be unique for that particular element.

Page 15: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

class selectorIn CSS, by selecting the element using the class attribute, we can select multiple elements for styling.

grouping selectorIn CSS, we can select the multiple elements using the name of elements

Page 16: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

Ref: (Click)

17] What is XML? XML is an eXtensible Markup Language. In XML, we can create our own tags, whereas

when we are using HTML, we are restricted to using the standard tags that are made available as per the HTML standard.

In XML, the format in which we layout these tags, is a text format. It contains different tags the way HTML document has.

Only thing is that, we can decide the tag names. XML provides a very easy way to exchange data, between different modules of the

applications or, from one application to another. It’s a standard which has been created by World Wide Web Consortium. Hence it’s a

universally acceptable standard. Then we make use of readymade classes that are present in the .NET Framework Library

to read/write XML files. Eg. XMLReader and XMLWriter. It’s extremely easy to learn and use XML. Entire World has embraced XML to a great extent

whenever there is need to exchange data.

18] Explain the tags or elements in XML. Any XML document would usually begin with a XML declaration containing XML version

number and the character encoding that has been used in the XML document that follows i.e. <?xml version = "1.0" encoding = "utf-8" ?>.

This XML declaration is optional but if present then the 1st value within that declaration will have to be the version number of the XML. In this case it is 1.0.

Page 17: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

Encoding indicates what kind of format we are using for representing characters. Encoding is an attribute. Attribute is optional. If we need then we can mention as utf-8 or utf-16 whereutf stands for Unicode Transformation Format.

Basically it indicates whether each character in the document, is going to be represented using 8 bits or using 16-bits. Here we are using utf-8 indicating that every character in the document would be represented using 8-bits.

If XML declaration is present in the document then, it will have to be on the very 1st line, in that document.

We will begin with <contacts> and end it with </contacts>. Inside this we have another tag called <contact>. This <contacts> and <contact> in XML terminology is known as an element.

<contact> ends with </contact>. Inside the <contact> tag we have <name> tag which ends with </name>. Name may be: Raj Pawar.

Then we have his telephone number followed by mobile number. Since mobile number is optional, so we say <mobile></mobile>.

We can have one more <contact> tag within the same XML document which will also have name, telephone number and mobile number.

So Raj Pawar, Anil J Fernandez, etc, are the values. So <contacts> is the root element within which we add <contact> and inside that we have three elements <name>, <telephone> and <mobile>.

19] Explain XMLReader and XMLWriter.It is important to know about .NET namespace and classes provided by .NET Runtime

Library. .NET provides five namespace - System.Xml, System.Xml.Schema, System.Xml.Serialization, System.Xml.XPath, and System.Xml.Xsl to support XML classes. The System.Xml namespace contains major XML classes. This namespace contains many classes to read and write XML documents. These reader and writer classes are used to read and write XML documents. These classes are - XmlReader, XmlTextReader, XmlValidatingReader, XmlNodeReader, XmlWriter, and XmlTextWriter. As you can see there are four reader and two writer classes.

The XmlReader class is an abstract base class and contains methods and properties to read a document. The Read method reads a node in the stream. Besides reading functionality, this class also contains methods to navigate through a document nodes. Some of these methods are MoveToAttribute, MoveToFirstAttribute, MoveToContent, MoveToFirstContent, MoveToElement and MoveToNextAttribute. ReadString, ReadInnerXml, ReadOuterXml, and ReadStartElement are more read methods. This class also has a method Skip to skip current nodeand move to next one.

The XmlWrite class contains functionality to write data to XML documents. This class provides many write method to write XML document items. This class is base class for XmlTextWriter class

XmlTextWriter and XmlNodeWriter come from the XmlWriter class.

Page 18: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

20] What is Event Handler ?An event is an action or occurrence such as a mouse click, a key press, mouse movements, or any system-generated notification. A process communicates through events. For example, interrupts are system-generated events. When events occur, the application should be able to respond to it and manage it.

Events in ASP.NET raised at the client machine, and handled at the server machine. For example,a user clicks a button displayed in the browser. A Click event is raised. The browser handles this client-side event by posting it to the server.

The server has a subroutine describing what to do when the event is raised; it is called the event-handler. Therefore, when the event message is transmitted to the server, it checks whether the Click event has an associated event handler. If it has, the event handler is executed.

For example, when a user clicks a button the 'Click' event is generated. For handling events, thereare in-built attributes and event handlers. Event handler is coded to respond to an event, and take appropriate action on it.

21] Difference in Environment ?The different Environments in which we work are, Development Environment and Production Environment.

Development Environment means we are trying to do the development of the website on the local machine and Production Environment means, the website is created and deployed on theweb server. And then make request to that web server through the client machine. In the beginning, the server as well as the client, both are on the same machine, that is Development Environment. During development phase, it is important that the web server is present on the localmachine, so that debugging and testing becomes easier. For example, when we have listed the contacts or added new contacts, we do CTRL + F5. The moment we do CTRL + F5, ASP.NET application gets build, i.e. compilation and linking takes place and once this is over, automatically Visual Studio launches the Web Browser. Once this browser is launched, it sends a request to the startup page of the local web server. i.e. a request is made to the default page, that we have marked as the startup page. Whatever response comes that would be rendered in the browser.

But in the production environment, we do not do CTRL + F5 because CTRL + F5 is done onlocal machine. But the website is not on local machine. The website is deployed, remotely, on the web server i.e. the website is already running on the web server. Hence we start our browser and then from our machine i.e. the client machine, we send a request to the ContactsManage.aspx page or any other web-page that we wish, within the website, can be invoked. We would usually want to make a request to ContactsManage.aspx page. This is a, Request – Response model. That means, we send the request and then the response comes back from the web server, and that response is always in the form of HTML. This response is properly displayed within our browser.

22] Request – Response Model ?We always send a HTTP request from the client and a HTTP response comes back to us. HTTP stands for HyperText Transfer Protocol. HTTP protocol was invented by Tim Berners Lee. HTTP 1.0 had come into existence. The documentation of this protocol, on which our websites work, is available at www.w3c.org/protocols/RFC2616. RFC stands for Request For Comments. 2616 is a document number, which contains the details of HTTP 1.1 protocol. HTTP protocol is a text-based protocol, it means that, the request goes in the form of text and response also comes back in the form of text. This protocol talks about how a web server would communicate with a web client. How this communication happens is the HTTP protocol. When a request comes from the client, a connection needs to be established. Once the connection is established then we can request data from the server. When that request comes, the server responds to that request by returning

Page 19: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

suitable HTML content, and once that is over, the connection is immediately closed. That means, when we make the 2nd request, there is no trace of the 1st request. Because the moment response is send, the connection is closed. So we say that HTTP protocol proposes a stateless model, clearly indicating that there is no state for that particular client kept on the server, across two different requests. Once the request is made, before the client makes the 2nd request, everything about the 1st request is gone. This is a stateless implementation of the protocol.

23] What is Get/Post Request ? State the Difference between them ? When to use Which explain ?

When we make a request, for example, while listing we just make a request; we are not going to send any data to the server for that. As against that, if we are going to do addition, searching or deletion, we will have to pass data to the server. For example, while adding we will have to say that add this particular data to the existing contact list. That means, in addition, deletion and searching, data has to be passed to the server whereas, when we are listing, we are not sending any data to the server. So for listing we will make use of a HTTP Get request whereas, for addition, searching and deletion, we will make use of a Post request. These are two very commonly used HTTP requests.

GET request is always the very first request. Whenever we visit the HomePage of a Website that time, GET request is done. Typically in Form based applications, we may have small amount of data or large amount of data to be sent to the server. In the Contacts website there is small amount of data to be sent. So we can send this data using GET request but it can also be send using the POST request. Typically for sending data, the POST request is used. Also whenever we wish to carry out multiple interactions with the user on the web page, at that time POST requests are quite handy. That is the reason why Visual Studio uses POST request as the default request. Suppose we want to delete a particular contact from ContactsList.txt. To be able to do so, 1st we search for the contact and then we delete it. Hence, the webpage will have two buttons, one for searching a particular contact and 2nd for carrying out the deletion, if the search in the previous case was successful. Whenever such multiple interactions are required on the webpage that time a POST HTTP request is popularly used.

When we make the GET or POST request, the request is typed within the browser. For example, http://localhost:1827/Contacts/ContactsManage.aspx. This is known as a URL i.e. Uniform Resource Locator. When we mention this URL and hit the Enter key, this URL gets converted into a GET request or a POST request. Here we are saying GET/Contacts/ContactsManage.aspx HTTP/1.1 Host:localhost:1827. The URL that we mentioned that is not the one which is send to the server. The URL is first converted into either a GET request or a POST request. For listing out contacts, we said that there would be a GET request. So here we are saying GET/Contacts/ContactsManage.aspx. If we click on the Add button or the Search button or the Delete button, we will have to send data; that time the request that we make, i.e. the URL that we type in the browser will get converted into the POST request. All the request will go only to the web server, either local or remote. Web server checks the extension of the request that we have made. If it is ' .aspx ' extension, in that case our request is going to be passed on to the ASP.NET runtime for this request to get processed.

How is it differentiated whether it is going to be a GET request or a POST request. When we make the request, the aspx page has the method written in it. If its method = GET then a GET request is made. If its method = POST then a POST request is made.

24] What is URL ?In the URL http://localhost:1827/Contacts/ContactsManage.aspx, http:// stands for the

protocol that is being used for making the request. It can be ftp:// or file://. It all depends upon which protocol we are using. After http://, we are giving the name of the server. localhost means the local machine or development machine. In place of localhost there might be a name of the

Page 20: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

machine which is the remote machine where the websites is deployed. Then we have the port number which, in this case is 1827. Then we have /Contacts/ContactsManage.aspx which indicates the location of that webpage on the web server.

Whenever the URL is created, at the beginning we have http://. Http stands for Hyper Text Transfer Protocol. Following http://, we have localhost which is the name of the local machine. This is the unique name for the server machine because; ultimately localhost gets converted into the IP (Internet Protocol) address of the machine. Every machine on the Internet is identified usinga unique address which is the IP address of the machine. We also have to specify the port numberwhich in this case is 1827. Port number can be any number. It is not necessary for it, to be 1827. Server is not only going to receive request from our browser, it is also going to get request from other browsers used by other people. That means, server handles multiple connection requests. Using the port number, web application is identified. We have to indicate the web application through the port number because, there might be several applications hosted on the same web server. Different applications work on different port numbers. To identify one application from the other, the port number is used. Subsequent to that we have /Contacts/ContactsManage.aspx. It indicates the location of the page that we are requesting within the website. We are requesting for the page ContactsManage.aspx which is inside the Contacts directory. We had created C:\ASP.NET\Contacts, so Contacts become the root of the website. Then we have a webpage andthe code file i.e. ContactsManage.aspx and ContactsManage.aspx.cs. That means, the URL mainly consists of four parts:

The type of the protocol The name of the machine, where we are trying to make a request The port number The location of the file that, we are trying to make a request for.

25] What are Sessions ? Web is stateless, which means a new instance of a web page class is re-created each time the page is posted to the server. HTTP is a stateless protocol; it can't hold client information on a page. If the user inserts some information and move to the next page, that data will be lost and theuser would not be able to retrieve that information. We need to store information. Session providesa facility to store information on server memory. It can support any type of object, to store, along with our own custom objects. For every client, session data is stored separately, which means session data is stored on a per client basis. Have a look at the following diagram:

Advantages: It helps maintain user state and data all over the application. It is easy to implement and we can store any kind of object.

Page 21: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

Stores client data separately. Session is secure and transparent from the user.

Disadvantages: Performance overhead in case of large volumes of data/user, because session data is

stored in server memory. Overhead involved in serializing and de-serializing session data, because in the case of

StateServer and SQLServer session modes, we need to serialize the objects before storing them.

ALSO,

The HTTP protocol is stateless, which means that HTTP has no built-in way to keep track of a user as they navigate from one webpage to another. As a result, there are a number of other methods used to maintain state. These include session state, cookies, hidden form fields (known as viewstate in .NET), passing variables through the querystring, and form posts.

The biggest downside of session state is that state is maintained in the application pool of IIS on the webserver. This isn't an issue with one server, but it causes problems when scaling out to have multiple servers. The solution is to move to a state server, where session state is stored on a3rd party server. Storing session state in the application pool also means that data is lost if the server is rebooted.

26] Different types of Request ?Apart from the GET and POST request, we also have HEAD, OPTIONS, DELETE, PUT and TRACE requests. GET request’s job is to fetch a document from the website whereas POST is used for sending the data. HEAD is used to get only the header information and not the body of the response. When the response comes back, header as well as the content comes. If we want toget access, only to the header, then we have to make use of the HEAD request. Then there is a OPTIONS request. When we use OPTIONS request, we can come to know what different types ofrequests are being supported for a particular application. DELETE deletes a particular resource or a document from the given website whereas PUT puts a resource or a document on the given URL. TRACE is used to figure out the, request that we are sending to the server, if it is not going to the server, if it has passed through several proxy servers (i.e. gateways), because in that case our request is going to get modified before it finally lands with the web server or not, if we want to figure out that, then we make use of a TRACE request. It is kind of a loop back. TRACE request is useful in debugging if something is not working for the website. These many requests can really be made.

27] What is Page Header ? Meaning , and Different Elements ?The Beginning is started by writing within % and %. Whatever is written within <% and %> is useful for the server. Then we have a Page directive or Page headers. Within this Page header, we have different Page properties i.e. Language, AutoEventWireup, CodeFile and Inherits. These properties are written in the form of name, value pairs. So ContactsManage.aspx does have, this particular page directive. In this Page directive, the properties that we mentioned, are going to be used by ASP.NET runtime, commonly known as ASP.NET engine. Language="C#" indicates what language has been used in the code for this particular webpage. We can use only one language per page. We cannot use multiple languages in the, code behind page. Then we have AutoEventWireup="true", when we set it to true, automatically the Page events would be bound to the appropriate handlers. By setting it to true, the only limitation that occurs is the, name of the Page handlers become same. So wiring of the event and the handler or, connection of the event

Page 22: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

and the handler happens automatically when we have AutoEventWireup="true". Then we have to clearly indicate the code behind file. In our case the code behind file means ContactsManage.aspx.cs for the webpage ContactsManage.aspx. ContactsManage.aspx.cs contains a partial class. This is responsible for the event handling mechanism of ASP.NET webpage. ContactsManage.aspx.cs contains code for handling variety of events. There are many more attribute possible in Page header.

28] What is ArrayList Working ?The operations that we carried out are Listing, Addition, Searching, Deletion and Modification. All of these make use of the ArrayList. ArrayList is used to maintain the contact information in memory but whatever is present in memory is not enough, because ultimately any information, unless it is stored in a consistent and proper state on a disk, we would never be able to retrieve it back. So we got to persist the information present in the ArrayList onto the disk. In the websites that we created we did manage to write that information into the txt file or the xml file. Contacts website, had used ContactsList.txt to persist the information present in memory of the ArrayList onto the disk in the file ContactsList.txt. ArrayList is a collection of either a FileContact objects or XmlContact objects i.e. it is collection of references of these different objects. So in ArrayList, in each individual slot, reference of an object is stored. ArrayList is somewhat different than the array, but we can access its element using an index. ArrayList has a special property whereby it can increase in size or decrease in size as per the requirement which is not possible with a conventional array. In conventional array, we have to always mention the size of the array upfront and once this size is mentioned, there onwards, during course of execution of program, there is noquestion of increasing the size of the array or decreasing the size of the array. So expansion and shrinking is not possible in normal array, it’s possible in case of ArrayList which makes it special.

29] Various Operations on ArrayList ?

AdditionWhen we carried out addition of a new contact, we had three text boxes in which we could type the information, about name, telephone number and mobile number. Once that was typed, we hadto click on the Add button. When we clicked on the Add button, the ContactsManage class’s AddButton_Click( ) handler gets called. Once that is done the ContactList’s AddContact( ) functiongets called. AddContact( ) added a new contact to the ArrayList which gets appended to the existing contact in the ArrayList. After updating the ArrayList, then we manage to call the ContactList class’s SaveToFile( ) or SaveToXmlFile( ) function to save the data that is in the ArrayList now, in either the txt file or in the XML file.

SearchWe have typed out the name of the person to be searched in the 1st textbox, out of the three textboxes. As soon as we click on the Search button, the SearchButton_Click( ) of the ContactsManage class i.e. button handler gets called. The 1-argument constructor of the ContactList class is used .We have to pass the name of the txt file or XML file to this constructor. Itis used to load the contents of the txt or XML file into the memory and then populate the ArrayList. Once the ArrayList is populated with existing contact information, we call the ContactList class’s Search( ) function. This Search( ) function might either be successful or unsuccessful. Assuming that it is successful, the contact information that is searched will be displayed in a label.

DeleteUser decides to delete a particular contact, and then would click on the Delete button. The Delete button’s handler i.e. DeleteButton_Click( ) gets called. Information is retrieved from the Session, and a call to ContactList class’s DeleteContact( ) function is made. DeleteContact( ) function searches for the contact that was retrieved from the Session in the ArrayList. The searched contact is eliminated from the ArrayList. The updated ArrayList saved into the disk by calling eitherSaveToFile( ) or SaveToXmlFile( ) function.

Page 23: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

Modify

30] What are the Three tiers of Web-Application ?We have a Client machine, then Web Server machine and then a Database Server

machine. The client machine is supposed to interact only with the web server whereas the web server, whatever request it gets, it has to pass them on for either storing data or retrieving data from a database server. These different components of a web application would reside in different machines. So any web application is a distributed application. The moment an application becomes a distributed application, the way the application is build changes, the concern changes, the issues change. In a typical desktop application all the three part, the front end, the middle tier and the backend, all of them are usually on the same machine. Whereas in a distributed application, since different components of the application reside on physically different machines, hence architecturing such an application becomes more difficult. We can never bypass any of these tiers or any of these layers. The client can never communicate to a database server directly.Client will always have to first make a request to the web server. It is the web server which will communicate with the database server. Likewise database server can never send information directly to the client. It will be able to communicate with the web server; web server will extract the information from the data server and then pass that information to the client’s browser where it will get suitably rendered. In distributed application, number of users of that application are quite large.Means several requests are coming to the web server and the same web server, once it receives the request tries to pass on some of the request to database server to retrieve data or to store data into the web server. There can be multiple web servers which communicate with one database server. There might be multiple database servers as well. So in that sense it becomes many to many kind of relationship. Whenever we have multiple web servers that is known as web farm. Each layer would be able to communicate to only its immediately next layer. Client cannot directly communicate with database server and database server also cannot directly connect to the client. So communication between client and database server is really not feasible. All the requests always have to be routed through the web server only. Typically the client is Internet Explorer or Firefox whereas web server is IIS 6.0 or 7.0. If it is Windows XP then it is IIS 6.0. If it isWindows server 2003 Operating System then IIS 7.0 is used. Client is an entity through which we can access the functionality of web application. The database server can be SQL Server 2000 / 2005.

First is the presentation layer. This presentation tier is either an Internet Explorer or Firefox i.e. it is a web browser. Through this web browser, we just have an access to the functionality of the web application. The middle tier is commonly known as a business logic tier wherein on the web server there is the web application present. Web server could be Microsoft IIS server or an Apache server or a Tomcat server. Tomcat is the open source implementation of a web server. Most of the time, in building a web application is spent in building the business logic layer. That is where the focus of all the application developers is. For example, in the Java world, we not only have the web server, we have an application server. Application severs like WebSphere or WebLogic or even Tomcat, these are servers that are used in Java world. Those servers are not merely Web Servers where we make a request and get a response. Those application servers have web server as one of their components. There are many other components also present in application servers. For example, there is a component which allows to balance the load that comes on the web server. So to manage the business logic, lot of innovative ideas have come up. The third layer is the persistence layer or a backend layer or a data layer. This data layer makes use of a relational database i.e. RDBMS. There are different implementations of this relational database. One of which is carried out by Oracle. Another has been carried out by Microsoft’s SQL Server. Then there is open source implementation in the form of MySQL. Out of all these, Oracle implementation is possibly the best. So, different implementations of this RDBMS is done by different companies. Even though the implementations are different, the mechanism to use these different implementations remains same. We as programmers do not have to bother about how Oracle actually manages to store the data internally or how MS SQL manages to store the data internally. We have to look at the access mechanisms and these fortunately are standard. No

Page 24: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

matter what exactly is the implementation of the database. Communication that is carried out between different tiers, that we can never bypass a tier. Separation of layers ensures a good design for the application. If we separate our logic into these different layers, it’s much easier to manage the overall application.

31] Write about Database Management System with Example ?Database Management System commonly known as DBMS. It is known as relational

because it contains information about related data. For example, in our database there might be a list of customers. Then there might be a list of products which the customers may be interested in purchasing. Which customer places an order for which product, we will have to again store somewhere else. That means somehow the customer is related with product through the order. This relationship can vary from simple relationships to complex relationships. RDBMS is all about creating the meaningful relationships between the data of the application. This RDBMS is very convenient to use and efficient in performance. The efficiency concern is no longer, our concern. The moment we start making use of the DBMS technology, we have to just see how to access the data, maintaining it efficiently, storing it properly, letting you retrieve it in a meaningful way is takencare by database server software. So there is a separation of concerns that is happening. The moment we have separated the concerns and assigned the efficiency to each of these software pieces, the overall web application performance is bound to be good. Typically in database applications we can build variety of things. For example, a bank carries out the financial transactions using database applications. In airlines website, we carry out online reservations or we have access to schedules of flights. We can also keep track of which flight has originated from which place at what time. All this information is available on websites. eCommerce websites, also known as online stores, are there where we can go and purchase different products. In manufacturing, databases have large role to play. Typically in an automobile company, there would be 100s and 1000s of components that go into manufacturing of an automobile. There might be spares of different machine that are involved in the manufacturing process. So inventory of the products, that are being produced , issuing of that to the Production or manufacturing department, taking it back, issuing tools, issuing different materials which are necessary in the production of the end product, all that information ultimately has to be stored in a meaningful manner and for that database management system is used. In HR departments of companies where people keep track of the employee records or their salaries or their skill sets, when did they join the company, what is their experience level, how much they have gained in this company, all this information can easily be managed by using a database management system. For example, we are trying to order a product through Internet based banking account. In the middle of the payment, suppose it so happens that we try to make a payment, our account should get debited and the person who is going to sell us something his account is to get credited. In between these two operations; debiting our account and crediting the sellers account, suppose a crash happens. Then our account stands debited whereas his account will not be suitably credited. That means the transaction will be incomplete. Database management technology has features wherein it can put both these operations together in a transaction wherein if both the operations do not happen inthat case, it will simply roll back to the earlier state. That means if our account got debited and sellers account did not get credited and something went wrong, the debit that happened to our account will be rolled back to its earlier state. RDBMS is very easy to use; moreover it has becomea worldwide standard for handling the data. It is very robust and a proven technology. These are some examples of the DBMS.

32] Write about SQL ? With Examples?SQL is more correctly pronounced as SeQueL. This is used to interact with the business

layer. When this communication is carried out, it must be simple to do so. That is the reason why SQL has been created almost in English like fashion. It is very easy to make use of SQL. This is the popular way of communicating with the database. Database server accepts the commands that are there in SQL. Who created this SQL? Lot of forces in the industry, lot of companies

Page 25: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

together have created SQL. It was created in the year 1986 and it was coined as SQL1. It becamean ANSI standard in 1986. In 1992, more features were added to it. For example, features like counting how many records of a particular type exists in a database or comparison operators using which we can selectively extract data from the database or things like providing a average of a particular column in a database or doing a sum of some of the columns or trying to extract information based on range of dates using between clause. All of those features were added later on and SQL2 came into existence. In the year 1992 , is when SQL actually got so wide audience. It almost became necessary from there onwards for people to think of SQL to store their data, retrieve their data, so on. This effort in1992 was coordinated by Federation of Information Processing Standard or FIPS. Later on in the year 1999, SQL3 came into existence. Some extensions were added to SQL2 and that’s when it became an ISO standard rather than ANSI standard and a FIPS. But these extensions have not been accepted very whole heartedly. Different implementations provide different features of this SQL3. Not every implementation would provide every feature. So, most of the times SQL2 commands are to be used rather than SQL3, tocommunicate with a database.

There are three basic types of commands; one belongs to the Data Definition Language or DDL. Another belongs to the Data Manipulation Language or DML and 3rd set of commands belongs to Data Control Language or DCL. DDL allows to create different tables, make changes to them using ALTER command and even delete the table using a DROP command. DML is very useful to us. It provides commands like SELECT, INSERT, UPDATE and DELETE. DCL provides commands like GRANT, DENY and REVOKE.

33] Communication with Database ?There are three things that we need to consider when we want to communicate with the

database. First is how do we connect to the database. There are two ways to do so. If our database server software is at a remote place then we carry out the connection using a TCP/IP connection. That is a flexible way of doing it because once we are doing it over the network, then from which physical machine we connect it does not matter. So in that sense, it is more flexible. Hence from the web browser that is present on different machines, we connect to web server and that web server is present on the 2 nd machine, which will connect to the database server that is present on the third machine. During development when the web server and the database server are present on the same machine, the communication happens using a technology known as Named Pipes. When named pipes are used, replication of data gets avoided as it gets copied fromsource to target. Once we try to establish the connection, whosoever is going to get connected he has to be authenticated. Whether such a person is an authentic user of that database or not has tobe verified. For doing credential check, are we allowed or are we not allowed that can be figured out using the username and password that we use for logging into Windows. When we do that, it is known as Windows Built-in way of authenticating. As against this we say also try to connect to the database server by passing the username and password to the SQL server and SQL server internally maintains a table of valid users and their passwords. So every time a user connects along with his username and password, it would be figured out whether, is this an authenticated user or not. Once that is done, we have to now start communicating with the database and to do so, different commands are to be used. Earlier different commands were used for different database servers to be able to retrieve the data or store the data in a database. Now all of that hasbeen standardized in the form of a Structured Query Language or SQL. There are some non-standard extensions to SQL also available.

34] SQL classes Info ?Different classes that are available are SqlConnection, SqlCommand and SqlDataReader.

Along with that one important class is SqlParameters. The job of SqlConnection is, it lets us establish a connection with the Microsoft SQL Server. Unless we establish a connection with the database server, there is no question of issuing any commands to the database server. So, 1st job at hand is, always establish a connection with the database server and to do that SqlConnection

Page 26: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

class is used. Then once the connection stands established we need to issue the commands and to issue the commands we propose to make use of the SqlCommand class. We will have to send the command and then get a response for that command from the database server. That is managed for us by the SqlCommand class. The SqlDataReader class allows to read data rows that are returned after having executed the command using the SqlCommand class’s methods.

35] SQL Methods Info ?The three methods in SqlCommand class that are of our interest are ExecuteReader( ),

ExecuteNonQuery( ) and ExecuteScalar( ). Each one of the method has a different ability with them. Each one of them ultimately executes a SqlCommand which is commonly known as an SQLquery. Query word is used for SQL commands. So ExecuteReader( ), ExecuteNonQuery( ) and ExecuteScalar( ) is ultimately going to execute some or the other SQL command. When ExecuteReader( ) goes to work, it returns all the records that qualify a particular query. For example, we may fire a query which looks like Select * from Customers. When we say this query then Customers become the name of the table. * indicates all the columns in that table. This querygives all the records and fields present in that database table called Customers. Once we establish the connection with a particular database server, there onwards we have to deal only with the tables inside that database. So ExecuteReader( ) returns all the records that qualify a particular query. We can also do selective searches. We can say Select * from Customers where AmountOfPurchase > 10,000. Then not every record would qualify this query. The records which qualify this query only those records would be returned by this ExecuteReader( ). Then there is ExecuteNonQuery( ) which executes the query. Typically this query could be insertion of records into the database or updation of existing records. It returns back, how many rows in the database got affected as a result of executing this query. For example, we may decide to update all the records in the database based on certain condition. We wish to update all those records wherein amount purchased is more than 10,000, we propose to give 10% discount. Only some records would qualify this query and only some of them would get updated. Whenever that updation takes place, if we had done that using ExecuteNonQuery( ) then out of 1000 records if only 50 got affected then 50 will be returned in the form of a number which indicates the number of records or rows which got changed or affected. So the return value of ExecuteNonQuery( ) indicates how many rows really got affected as a result of execution of the query. Then we have ExecuteScalar( ) which returns the value of the first column of the first row whenever we fire a query. Typically ExecuteScalar( ) can be used to count how many records are there in the database which satisfy a particular criteria or we can use the Min command or the Max command to find out the minimum value that is there in a particular column or the maximum value that is there in a particular column or we can also think of finding out average of a particular column or sometimes we may want to update a particular record or may be insert a particular record. In all such cases, one value is to be returned i.e. the value present in the first column of the first row. If we have a ‘ordered table’ and we insert the ‘order information’ then first column will be the order id, that order id would be returned to us when this ExecuteScalar( ) method is called.

36] Contact List Class Info ?In the XML based contact book, the ContactList class was supposed to maintain, in the

memory a collection of XmlContact objects and then to perform operations on the ArrayList. We had functions like a 0-argument constructor and a 1-argument constructor. Then we have additional functions like LoadFromXmlFile( ) which is used to load all the contact information from XML file and build the ArrayList and SaveToXmlFile( ) is used to do the reverse. Whatever contacts are there in the ArrayList right now, we used to write them into an XML file using SaveToXmlFile( ). Then we had functions like Search( ), AddContact( ), DeleteContact( ) and UpdateContact( ) to carry out searching, addition, deletion and updation of an existing contact. Weare done with that. In the ContactList class that we propose to create in the SQL based contact book application; here we do not need 1-argument constructor. This is so because in the XML based contact book’s ContactList class’s 1-argument constructor, we used to load the contents of

Page 27: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

the XML file such that the contacts can be displayed whenever the webpage is requested, the current list of contacts used to get displayed. That is no longer necessary because all the contacts are there in the SQL database. We do not need to have a 1- argument constructor for it. We will have LoadFromSql( ) function which will load the contacts from the SQL database into the ArrayList. Then we will have Search( ), AddContact( ), DeleteContact( ) and UpdateContact( ) functions.

37] What is SQL injection and Parameterized Query ?SQL injection means, SQL statements get injected into existing SQL commands. For

example, the DELETE command gets injected within the INSERT command. INSERT INTO Contacts ( Name, Telephone, Mobile ) VALUES ('{0}', '{1}', '{2}'). Now it gets expanded to INSERT INTO Contacts (Name, Telephone, Mobile) VALUES ( 'Bad', '11223344', '11' ) ; DELETE FROM Contacts ; --' ).-- is a syntax that is used for giving a comment in a SQL command. So anything that begins with -- is treated as a comment. The moment he gave 11' ) ; DELETE FROM Contacts ; -- it got accepted as a valid mobile number. So INSERT command ends right there after11' ) then there is a ;. That ; is a facility of separating two SQL commands. But here it is being used to inject a new SQL command into our existing SQL command. Once the insertion is done, now the next SQL command is going to get executed and that’s going to delete all the records from the contact book. DELETE FROM Contacts is going to delete every single record that’s there,in the Contacts table. Both are separate command, but both got executed. Insertion did happen; deletion also took place. It’s a very common flaw. Moreover, the security implications of that are quite severe. To deal with this SQL injection attacks, we should never trust input that comes from the different textboxes, because that’s where the user types new input. Don't think that users will always use well-formed input. You got to validate, before using any input, in your database. We should never attempt to build a “query string” directly from the input, unless we have validated it. Moreover, instead of building the query string directly from the input, we should use parameterizedqueries which MS SQL provides to us. We should also try to reject special characters like ; ' --. These characters should not be accepted in an input. So, if we notice these characters in the input, reject them. We have to do this programmatically because, once the user enters it and the server receives it, we will have to validate it in a programmatic fashion. So better way to build a query is, to pass “parameters” to the INSERT command and those parameters should be type safe parameters and MS SQL Server supports parameterized queries. Once done, we can know thoroughly well that nobody is going to touch the data within the database.

38] Web Control categories with Examples ?The different categories of Web controls fall under five major categories. First amongst

them is the Standard Web Controls. For example, Textbox to receive name, telephone number, mobile number and Buttons. While using web controls in the application, we will find that there are parallels for these web controls in the form of HTML controls. HTML controls are older way of creating the WebPages whereas Web controls are more modern way of dealing with different controls in the webpage. So Textbox, Button these are standard controls. In addition to that we willalso see Radio buttons or a Drop Down ListBox very commonly used in a webpage. Apart from thestandard controls, there are many other controls. One of them is the Data control. There are very powerful controls under Data control category. One of them happens to be a GridView control and another is a SqlDataSource control. GridView is basically used to display the data in a columnar format whereas SqlDataSource is used for tying different controls with different data sources. The third category of controls is the Validation controls. Many times, when we visit a website and we are required to register ourselves there and when we do the registration process, we are being asked to do some form filling. In the form filling, we may be required to type name, email address, postal address, etc. All these details are to be filled. In the process of doing so one or two fields can be ignored. Then we click on the Submit button. When we click on the Submit button, we are immediately flashed an error, saying that one or two fields are being forgotten i.e. to enter data into it. Those are considered to be the required fields. This can be done using ReqdFieldValidator

Page 28: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

control. Next, we are required to enter things like Email addresses. For eg: If somebody enters theEmail address without the @ symbol then that’s an invalid Email address. So whenever Email addresses are received, it is verified whether that Email address is a valid Email address or not and that can be done by using a standard control called RegExpValidator. Many types of Validation Controls are present. In addition to that we have Navigation controls. For example, at the top of a webpage we see menu items through which we can navigate to different parts of a website. There is a SiteMapPath control available which lets the user see, at a glance what all is there in the website using. These controls are commonly used in all professional websites. We also have Login facilities at most of the sites and for getting that done, there are controls available in the form of Login control and then there is a ChangePassword control wherein whatever password we are using right now, if we think that, we want to login with new password then ChangePassword control is used. There is also a ForgottenPassword control through which if somebody forgets a password then through some mechanism the user is informed about the new password. Most of the commonly required operations that are to be done on a website can be handled using the different controls in the form of web controls that are made available to us.

39] Goal of Database Design ?The database should be simple to understand. Don’t create too many tables and then

establish complex relationships between those tables. We may be able to design a database but unless and until, it is easy to use later, in a programmatic fashion then the whole idea itself will get defeated. 2nd thing is we should not be required to change the design too often. If we are requiredto change the design too often then it shows a myopic vision of the programmer. It means that we have not given enough thought while designing the database in the first place. That is the reason why we are required to change it often. We should factor in the possibilities while designing the database. If we design it properly then we are not required to change it very often. So we should think carefully, give enough thought to different possibilities, factoring the newer things that may come up. As the application starts getting used by multiple users, i.e. once the website goes online, there onwards we cannot touch the database because we will be to dealing with a live website where people are interacting with it. That time we really do not have the time to change the database. So we have to think carefully when we sit down to do the database design. It shouldnot be an afterthought. While doing so, we should avoid duplication of data. Because the moment the data gets duplicated, the performance of the database will reduce drastically. It will occupy more space on the disk. Lastly, it should be possible to easily update the data that is there in the database. When we fire queries like UPDATE, it should not become too complicated.

40] DBMS Terminologies ?

Primary Key – A column whose value is guaranteed to be unique in each row of a table. Foreign Key – A column whose values are primary keys in other table.

Page 29: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

Identity Column – A numeric column whose value is automatically assigned by SQL server and incremented after every insertion.

Composite Primary Key – A combination of columns which together gives a unique value in each row of a table. Refers to cases, where more than one column is used to specify the primary key of a table.

41] Explain Primary Key and Foreign Key with an example ?

A FOREIGN KEY is a key used to link two tables together. A FOREIGN KEY is a column in one table that refers to the PRIMARY KEY in another

table. The table containing the foreign key is called the child table, and the table containing the

candidate key is called the parent table.

Look at the following two tables:

"Persons" table:

Page 30: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

"Orders" table:

Notice that the "PersonID" column in the "Orders" table points to the "PersonID" column in the "Persons" table.

The "PersonID" column in the "Persons" table is the PRIMARY KEY . The "PersonID" column in the "Orders" table is a FOREIGN KEY . The FOREIGN KEY constraint also prevents invalid data from being inserted into the

foreign key column, because it has to be one of the values contained in the table it points to.

Primary Key :

The PRIMARY KEY constraint uniquely identifies each record in a database table. Primary keys must contain UNIQUE values, and cannot contain NULL values. A table can have only one primary key, which may consist of single or multiple fields.

(above) For Single Primary Key

Page 31: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

In the example above there is only ONE PRIMARY KEY (PK_Person). However, the VALUE of theprimary key is made up of TWO COLUMNS (ID + LastName).

42] Explain Validation or Regular Expression validation ?ASP.NET validation controls validate the user input data to ensure that useless,

unauthenticated, or contradictory data are avoided.

ASP.NET provides the following validation controls:

RequiredFieldValidator RangeValidator CompareValidator RegularExpressionValidator CustomValidator ValidationSummary

RequiredFieldValidator ControlThe RequiredFieldValidator control ensures that the required field is not empty. It is generally tied to a text box to force input into the text box.

RangeValidator ControlThe RangeValidator control verifies that the input value falls within a predetermined range.

It has three specific properties:

CompareValidator ControlThe CompareValidator control compares a value in one control with a fixed value or a value in another control.

RegularExpressionValidatorThe RegularExpressionValidator allows validating the input text by matching against a pattern of a regular expression. The regular expression is set in the ValidationExpression property.

Page 32: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

ValidationSummaryThe ValidationSummary control does not perform any validation but shows a summary of all errorsin the page. The summary displays the values of the ErrorMessage property of all validation controls that failed validation.

43] Explain some Controls in asp.net ?

Calendar ControlThe calendar control is a functionally rich web control, which provides the following capabilities:

Displaying one month at a time Selecting a day, a week or a month Selecting a range of days Moving from month to month Controlling the display of the days programmatically

CheckBoxList Control The CheckBoxList control renders a list of check boxes. The check boxes can be rendered horizontally or vertically. Unlike the other List controls, a user can select multiple items when usinga CheckBoxList control.

FileUpload ControlASP.NET has a control that allows users to upload files to the web server. Once the server receives the posted file data, the application can save it, check it, or ignore it. FileUpload control automatically sets the encoding of the web-form. The FileUpload control allows the user to browsefor and select the file to be uploaded, providing a browse button and a text box for entering the filename. Once, the user has entered the filename in the text box by typing the name or browsing, the SaveAs method of the FileUpload control can be called to save the file

44] Write about Database Transaction ?Most applications deal with back-end databases, and we need the data to be atomic, which

means no anomalies in the data. For instance, you're supposed to insert data into master and child tables in the SQL Server. During the above task if you inserted one row into the master table and then some error occurred then what would happen to that task? Because of the error, child data is not inserted and you must rollback the master table data also; otherwise data inconsistencywill happen. Here transaction plays a vital role to make sure data operations that occur happen successfully.

A transaction is a single unit of work which means either ALL or NONE. If a transaction is successful, all of the data operations are committed and become a durable part of the database. If a transaction encounters errors/exceptions and must be canceled or rolled back, then all of the data modifications/operations need to be removed.

Example: Transfer money from Bank Account1 to Account2. It consists of two processes: Withdraw amount from Account1 and Deposit that amount to Account2.Transferring money will only be accurate and successful if both the processes are individually successful. If that is not happening, suppose process 1 succeeds but process 2 fails, then the money will be deducted from Account 1 but not deposited to Account 2. If that happens, it will be very bad and no one will accept it.

Page 33: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

Properties of Transaction

45] Explain Declarative approach ?Data that we are going to display or edit inside the webform is going to come from some

source. Sources could be of variety of nature. It could be a Microsoft SQL database, could be XMLfile, could be a Oracle database or it can be a MYSQL server database as well. It does not really matter, what exactly is the source of data. To be able to get that data and use it in ASP.NET, we need DataSource controls. DataSource controls connect to the database. Connection mechanisms could be different for each database server or each DataSource represented in the system. But most of these DataSources are connected using a connection string. Then these controls automatically have features to read the data from the source, write the data to the source,create a new record in the source and so on. So these controls are specialists in connecting to thedatabase and reading and writing data between the application and a database. We do not have to worry about connection mechanisms and actual procedures involved in reading and modifying the data. Although we use the word Controls here, remember that DataSource controls do not have any user interface. So as far as end user is concerned, he does not see anything visible on his page when he loads a ASP.NET form. So these controls have the sole purpose of getting the data and making changes to the data from the data source. So they act as an intermediary for a broker between the source and the controls called as DataBound controls. GridView happens to be a DataBound control. The word Bound indicates that they are somehow connected to the data. It is with the help of these DataSource controls that the DataBound controls connect to the data. So they do not connect to the DataSource directly. They use these DataSource controls as an intermediate. To specify which DataSource control, we are using, we have to use a property calledas DataSourceId property. So this property allows us to specify the Id for the DataSource control within the page which is responsible for connecting to the data source and loading the data along with modifications if any. DataSource has the data. DataSource controls have the ability to work with the data and DataBound controls have the specialty in displaying the data to the end user. Because the DataBound controls also generate the markup i.e. HTML required to, allow user to interact with the web application. They are the ones which are actually seen by the user. User never sees the database. User never sees the DataSource controls. But user definitely sees the DataBound controls.

Page 34: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

46] Explain Data-Binding model ?When we talk about a source for data, three primary sources are available; SQL server

which could be Microsoft SQL server, XML which is a XML file. To fetch the data from these sources in ASP.NET 3.5, there are several DataSource controls. So there is a SQL DataSource control. There is an object DataSource which allows to connect, to something that is really an object of a class in C#. XML DataSource for fetching the data from an XML file, writing data to a XML file and the new trend is LINQ DataSource. LINQ stands for Language Integrated Query. These four primary DataSource controls feed into the popular DataBound controls that we have in ASP.NET 3.5. We have seen ListBox, CheckBoxList and DropDownList. There are several others like DetailsView, GridView, TreeView, a Menu control and FormView. There is large number of such DataBound controls. Their ability to manipulate the display of data, received from any one of these DataSource controls, makes them special. For example, now the GridView control might be displaying the data from the SQL server database but the GridView is capable of displaying data even from an Object source. So DataSource control is a generic mechanism whose purpose is to feed the data to the corresponding DataBound controls. So this three layer separation between theDataSource and the DataBound controls allows to plug-in different kinds of sources that feed to various DataBound controls.

47] What are the operations supported by GridVeiw?

A GridView is a graphical control element that presents a tabular view of data.

Operation Supported :

Sorting Editing Deleting Selection Paging

48] What is DetailsVeiw Control ?DetailsView control is a control in which the items in a record are displayed one row at a

time and these items are displayed in such a manner that title of the column or heading of the column appears as the left column whereas the value appears as the right column. So this is a rowby row layout where each row contains only two columns; on left we have the heading column, on right we have the value column. So Contact record which is being displayed in a DetaisView will have Name, Telephone and Mobile as the headings for individual rows and their corresponding values in the 2nd column in those rows. GridView control has the purpose of displaying one record in the database that we are trying to connect to. GridView occupies the width of the screen quite heavily and if the number of columns in a database table is too many, then GridView will not fit in the horizontal width of the browser without having to do scrolling. DetailsView has a column by column layout where each column is displayed as a row in the DetailsView table. It does not matter how many columns are there, we can comfortably display the details using a DetailsView control and hence the name DetailsView. If GridView and DetailsView are present on the same webform, not all the columns would be displayed in the GridView control but if somebody selects acorresponding record from the GridView, every single detail about that record is displayed in a DetailsView control that appears below that control.

Page 35: ASP.NET Questions and Answers - WordPress.com · ASP.NET it is possible to use different themes for different websites. Usage of modules, for providing functionality to the website,

Recommended