ASP.NET Interview Questions & Answers:-
Q-What is ASP.Net? What are
the advantages ASP.Net Technologies?
A-ASP.Net is a server side
Technology to develop a web based applications.ASP.Net will make use of .Net
framework features.
Advantages of ASP.Net
ASP.NET makes development simpler and easier
to maintain with an event-driven, server-side programming model
ASP.NET offers built-in security features
through windows authentication or other authentication methods.
Content and program logic are separated
which reduces the inconveniences of program maintenance.
Built-in caching features.
Q-What are different stages of
ASP.Net Page Life cycle?
A-Each ASP.Net Web page
performs following stages/events
Page Initialization (Page_Init event)
Page Loading (Page_Load event)
Page Prerender (Page_Prerender)
Page Render (Page_Render)
Page Unload (Page_Unload)
Q-How do you validate Input
data on web page?
A-Before submitting a web page
to server, Input validation on web page is one of the important task.ASP.Net
provides below validation controls to validate data in web controls and shows
user friendly Messages to the user.
Q-ASP.Net validation Controls
A-Required field validator
control
Compare validator control
Q-what are the different state
management techniques in ASP.Net?
A-Asp.Net state management can
be maintained in two ways as below
Client- Side State Management
ASP.Net provides following
techniques to store state information. This will improve application
performance by minimizing server resource utilization
1.View state
2. Hidden Fields
3. Cookies
4. Query Strings
Server – Side State Management
With respect to Server Side
State Management ASP.Net uses “Application state” and “Session state” objects
to store data or user state.
Q-What are the differences
between custom Web control and user control?
A-Custom Web control is a
control that inherits from web server control available in ASP.Net.
A Custom Web Control could be
compiled into separate .dll file. This custom Web control can be shared across
all application by installing this dll in to Global Assembly Catch.
User Control is a file (.ascx
file) that contains a set of ASP.Net controls and code grouped together to
provide common functionality across the application. User control can be used
on different web pages of the application.
Q-Explain ASP.Net Catching?
What are different catching mechanisms available in ASP.Net?
A-ASP.Net catching one of the
important performance factor for large web applications.
ASP.Net Catching stores
frequently accessed data in to catch object.
There are two different types
catching in ASP.Net
1.Application Catching
2.Page Output Catching
What is ASP?
What is ASP?
A-Active Server Pages (ASP),
also known as Classic ASP, is a Microsoft's server-side technology, which helps
in creating dynamic and user-friendly Web pages. It uses different scripting
languages to create dynamic Web pages, which can be run on any type of browser.
The Web pages are built by using either VBScript or JavaScript and these Web
pages have access to the same services as Windows application, including ADO
(ActiveX Data Objects) for database access, SMTP (Simple Mail Transfer
Protocol) for e-mail, and the entire COM (Component Object Model) structure
used in the Windows environment. ASP is implemented through a dynamic-link
library (asp.dll) that is called by the IIS server when a Web page is requested
from the server.
Q-What is ASP.NET?
A-ASP.NET is a specification
developed by Microsoft to create dynamic Web applications, Web sites, and Web
services. It is a part of .NET Framework. You can create ASP.NET applications
in most of the .NET compatible languages, such as Visual Basic, C#, and J#. The
ASP.NET compiles the Web pages and provides much better performance than
scripting languages, such as VBScript. The Web Forms support to create powerful
forms-based Web pages. You can use ASP.NET Web server controls to create
interactive Web applications. With the help of Web server controls, you can
easily create a Web application.
Q-What is the basic
difference between ASP and ASP.NET?
A-The basic difference between
ASP and ASP.NET is that ASP is interpreted; whereas, ASP.NET is compiled. This
implies that since ASP uses VBScript; therefore, when an ASP page is executed,
it is interpreted. On the other hand, ASP.NET uses .NET languages, such as C#
and VB.NET, which are compiled to Microsoft Intermediate Language (MSIL).
Q- In which event are the controls fully loaded?
Q- In which event are the controls fully loaded?
A-Page load event guarantees
that all controls are fully loaded. Controls are also accessed in Page_Init
events but you will see that view state is not fully loaded during this event
Q-How can we identify that
the Page is Post Back?
Page object has an
"IsPostBack" property, which can be checked to know that is the page
posted back.
Q. What is the lifespan for
items stored in ViewState?
The items stored in ViewState
live until the lifetime of the current page expires including the postbacks to
the same page.
Q. How information about the
user's locale can be accessed?
A-The information regarding a
user's locale can be accessed by using the System.Web.UI.Page.Culture property.
Q. What is the difference
between SQL notification and SQL invalidation?
A-The SQL cache notification
generates notifications when the data of a database changes, on which your
cache item depends. The SQL cache invalidation makes a cached item invalid when
the data stored in a SQL server database changes.
Q. Which is the parent class
of the Web server control?
A-The System.Web.Ul.Control class is the parent class for all Web server controls.
A-The System.Web.Ul.Control class is the parent class for all Web server controls.
Q. Can you set which type of
comparison you want to perform by the CompareValidator control?
A-Yes, by setting the Operator
property of the CompareValidator control.
Q. What is the behavior of a
Web browser when it receives an invalid element?
A-The behavior of a Web browser
when it receives an invalid element depends on the browser that you use to
browse your application. Most of the browsers ignore the invalid element;
whereas, some of them display the invalid emelents on the page.
Q. What are the advantages of
the code-behind feature?
A-The code-behind feature of
ASP.NET offers a number of advantages:
Makes code easy to understand and debug by
separating application logic from HTML tags
Provides the isolation of effort between
graphic designers and software engineers
Removes the problems of browser
incompatibility by providing code files to exist on the Web server and
supporting Web pages to be compiled on demand.
Q. How do you sign out from
forms authentication?
A-The
FormsAuthentication.Signout() method is used to sign out from the forms
authentication.
Q. What is AutoPostBack?
A-If you want a control to
postback automatically when an event is raised, you need to set the
AutoPostBack property of the control to True.
Q. What is the function of
the ViewState property?
A-The ASP.NET 4.0 introduced a
new property called ViewStateMode for the Control class. Now you can enable the
view state to an individual control even if the view state for an ASP.NET page
is disabled.
Q. Why do you use the
App_Code folder in ASP.NET?
A-The App_Code folder is
automatically present in the project. It stores the files, such as classes,
typed data set, text files, and reports. If this folder is not available in the
application, you can add this folder. One of the important features of the
App_Code folder is that only one dll is created for the complete folder,
irrespective of how many files it contains.
Q. Define a multilingual Web
site.
A-A multilingual Web site serves
content in a number of languages. It contains multiple copies for its content
and other resources, such as date and time, in different languages.
Q. What is an ASP.NET Web
Form?
A-ASP.NET Web forms are designed
to use controls and features that are almost as powerful as the ones used with
Windows forms, and so they are called as Web forms. The Web form uses a
server-side object model that allows you to create functional controls, which
are executed on the server and are rendered as HTML on the client. The
attribute, runat="server", associated with a server control indicates
that the Web form must be processed on the server.
Q. What is the difference
between a default skin and a named skin?
A-The default skin is applied to
all the Web server controls in a Web form, which are of similar type, and it
does not provide a Skin ID attribute. The named skin provides a Skin ID
attribute and users have to set the Skin ID property to apply it.
Q. What is IIS? Why is it
used?
A-Internet Information Services
(IIS) is created by Microsoft to provide Internet-based services to ASP.NET Web
applications. It makes your computer to work as a Web server and provides the
functionality to develop and deploy Web applications on the server. IIS handles
the request and response cycle on the Web server. It also offers the services
of SMTP and FrontPage server extensions. The SMTP is used to send emails and
use FrontPage server extensions to get the dynamic features of IIS, such as
form handler.
Q. What is Query String? What
are its advantages and limitations?
A-The Query String helps in
sending the page information to the server.
The Query String has the
following advantages:
Every browser works with Query Strings.
It does not require server resources and so
does not exert any kind of burden on the server.
The following are the
limitations of Query String:
Information must be within the limit
because URL does not support many characters.
Information is clearly visible to the user,
which leads to security threats.
Q. What is actually returned
from server to the browser when a browser requests an .aspx file and the file
is displayed?
A-When a browser requests an
.aspx file then the server returns a response, which is rendered into a HTML
string.
Q-How can you display all validation messages in one control?
Q-How can you display all validation messages in one control?
A-The ValidationSummary control
displays all validation messages in one control.
Q. Which two new properties
are added in ASP.NET 4.0 Page class?
A-The two new properties added
in the Page class are MetaKeyword and MetaDescription.
Q. What is tracing? Where is
it used?
A-Tracing displays the details
about how the code was executed. It refers to collecting information about the
application while it is running. Tracing information can help you to
troubleshoot an application. It enables you to record information in various
log files about the errors that might occur at run time. You can analyze these
log files to find the cause of the errors.
In .NET, we have objects
called Trace Listeners. A listener is an object that gets the trace output and
stores it to different places, such as a window, a file on your locale drive,
or a SQL Server.
The System.Diagnostics
namespace contains the predefined interfaces, classes, and structures that are
used for tracing. It supplies two classes, Trace and Debug, which allow you to
write errors and logs related to the application execution. Trace listeners are
objects that collect the output of tracing processes.
Q. What is the difference
between authentication and authorization?
A-Authentication verifies the
identity of a user and authorization is a process where you can check whether
or not the identity has access rights to the system. In other words, you can
say that authentication is a procedure of getting some credentials from the
users and verify the user's identity against those credentials. Authorization
is a procedure of granting access of particular resources to an authenticated
user. You should note that authentication always takes place before
authorization.
Q. How can you register a
custom server control to a Web page?
A-You can register a custom
server control to a Web page using the @Register directive.
Q. Which ASP.NET objects
encapsulate the state of the client and the browser?
A-The Session object
encapsulates the state of the client and browser.
Q. Differentiate
globalization and localization.
A-The globalization is a
technique to identify the specific part of a Web application that is different
for different languages and make separate that portion from the core of the Web
application. The localization is a procedure of configuring a Web application
to be supported for a specific language or locale.
Q. What is ViewState?
A-The ViewState is a feature
used by ASP.NET Web page to store the value of a page and its controls just
before posting the page. Once the page is posted, the first task by the page
processing is to restore the ViewState to get the values of the controls.
Q. Which method is used to
force all the validation controls to run?
A-The Page.Validate() method is
used to force all the validation controls to run and to perform validation.
Q. Which method has been
introduced in ASP.NET 4.0 to redirect a page permanently?
A-The RedirectPermanent() method
added in ASP.NET 4.0 to redirect a page permanently.
RedirectPermanent("/path/Aboutus.aspx");
Q. How can you send an email
message from an ASP.NET Web page?
A-You can use the
System.Net.Mail.MailMessage and the System.Net.Mail.SmtpMail classes to send an
email in your Web pages. In order to send an email through your mail server,
you need to create an object of the SmtpClient class and set the server name,
port, and credentials.
Q. What is the difference
between the Response.Write() and Response.Output.Write() methods?
A-The Response.Write() method
allows you to write the normal output; whereas, the Response.Output.Write()
method allows you to write the formatted output.
Q. What does the Orientation
property do in a Menu control?
A-Orientation property of the
Menu control sets the horizontal or vertical display of a menu on a Web page.
By default, the orientation is vertical.
36. Differentiate between
client-side and server-side validations in Web pages.
A-Client-side validations take
place at the client end with the help of JavaScript and VBScript before the Web
page is sent to the server. On the other hand, server-side validations take
place at the server end.
37. How does a content page
differ from a master page?
A-A content page does not have
complete HTML source code; whereas a master page has complete HTML source code
inside its source file.
Q. Suppose you want an
ASP.NET function (client side) executed on the MouseOver event of a button.
Where do you add an event handler?
A-The event handler is added to
the Add() method of the Attributes property.
39. What is the default
timeout for a Cookie?
A-The default time duration for
a Cookie is 30 minutes.
40. What are HTTP handlers in
ASP.NET?
A-HTTP handlers, as the name
suggests, are used to handle user requests for Web application resources. They
are the backbone of the request-response model of Web applications. There is a
specific event handler to handle the request for each user request type and
send back the corresponding response object.
Each user requests to the IIS
Web server flows through the HTTP pipeline, which refers to a series of
components (HTTP modules and HTTP handlers) to process the request. HTTP
modules act as filters to process the request as it passes through the HTTP
pipeline. The request, after passing through the HTTP modules, is assigned to
an HTTP handler that determines the response of the server to the user request.
The response then passes through the HTTP modules once again and is then sent
back to the user.
You can define HTTP handlers
in the <httpHandlers> element of a configuration file. The <add>
element tag is used to add new handlers and the <remove> element tag is
used to remove existing handlers. To create an HTTP handler, you need to define
a class that implements the IHttpHandler interface.
Q. What are the events that
happen when a client requests an ASP.NET page from IIS server?
A-The following events happen
when a client requests an ASP.NET page from the IIS server:
User requests for an application resource.
The integrated request-processing pipeline
receives the first user request.
Response objects are created for each user
request.
An object of the HttpApplication class is
created and allocated to the Request object.
The HttpApplication class processes the
user request.
Q. Explain file-based
dependency and key-based dependency.
A-In file-based dependency, you
have to depend on a file that is saved in a disk. In key-based dependency, you
have to depend on another cached item.
Q. How can you implement the
postback property of an ASP.NET control?
A-You need to set the
AutoPostBack property to True to implement the PostBack property of controls.
Q. Explain how Cookies work.
Give an example of Cookie abuse.
A-The server tells the browser
to put some files in a cookie, and the client then sends all the cookies for
the domain in each request. An example of cookie abuse is large cookies
affecting the network traffic.
Q. Explain login controls.
A-Login controls are built-in
controls in ASP.Net for providing a login solution to ASP.NET application. The
login controls use the membership system to authenticate a user credentials for
a Web site.
Q.There are many controls in
login controls.
A-ChangePassword control - Allows users to
change their password.
CreateUserWizard control - Provides an
interface to the user to register for that Web site.
Login control - Provides an interface for
user authentication. It consists of a set of controls, such as TextBox, Label,
Button, CheckBox, HyperLink.
LoginView control - Displays appropriate
information to different users according to the user's status.
LoginStatus control - Shows a login link to
users, who are not authenticated and logout link, who are authenticated
LoginName control - Displays a user name,
if the user logs in.
PasswordRecovery control - Allows users to
get back the password through an e-mail, if they forget.
Q. What is the use of
PlaceHolder control? Can we see it at runtime?
A-The PlaceHolder control acts
as a container for those controls that are dynamically generated at runtime. We
cannot see it at runtime because it does not produce any visible output. It
used only as a container.
Q. What setting must be added
in the configuration file to deny a particular user from accessing the secured
resources?
A-To deny a particular user form
accessing the secured resources, the web.config file must contain the following
code:
<authorization >
<deny users="username"
/>
</authorization>
Q. What are the event
handlers that can be included in the Global.asax file?
A-The Global.asax file contains
some of the following important event handlers:
->Application_Error ,->Application_Start,->Application_End,->Session_Start,->Session_End
Q. What is the difference
between page-level caching and fragment caching?
A-In the page-level caching, an
entire Web page is cached; whereas, in the fragment caching, a part of the Web
page, such as a user control added to the Web page, is cached.
Q. Make a list of all
templates of the Repeater control.
A-The Repeater control contains
the following templates:
ItemTemplate
AlternatingltemTemplate
SeparatorTemplate
HeaderTemplate
FooterTemplate
Q. Describe the complete
lifecycle of a Web page.
A-When we execute a Web page, it
passes from the following stages, which are collectively known as Web page
lifecycle:
Page request - During this stage, ASP.NET
makes sure the page either parsed or compiled and a cached version of the page
can be sent in response
Start - During this stage sets the Request
and Response page properties and the page check the page request is either a
postback or a new request
Page Initialization - During this stage,
the page initialize and the control's Unique Id property are set
Load - During this stage, if the request is
postback, the control properties are loaded without loading the view state and
control state otherwise loads the view state
Validation - During this stage, the
controls are validated
Postback event handling - During this
stage, if the request is a postback, handles the event
Rendering - During this stage, the page
invokes the Render method to each control for return the output
Unload - During this stage, when the page
is completely rendered and sent to the client, the page is unloaded.
Q. How can you assign page
specific attributes in an ASP.NET application?
A-The @Page directive is
responsible for this.
Q. Which method is used to
post a Web page to another Web page?
A-The Respose.Redirect method is
used to post a page to another page, as shown in the following code snippet:
Response.Redirect("DestinationPageName.aspx");
Q. What is a Cookie? Where is
it used in ASP.NET?
A-Cookie is a lightweight
executable program, which the server posts to client machines. Cookies store
the identity of a user at the first visit of the Web site and validate them
later on the next visits for their authenticity. The values of a cookie can be
transferred between the user's request and the server's response.
Q. What are Custom User
Controls in ASP.NET?
A-The custom user controls are
the controls that are defined by developers. These controls are a mixture of
custom behavior and predefined behavior. These controls work similar to other
Web server controls.
Q. What does the .WebPart
file do?
A-The .WebPart file explains the
settings of a Web Parts control that can be included to a specified zone on a
Web page.
Q. How can you enable
impersonation in the web.config file?
A-To enable impersonation in the
web.confing file, you need to include the <identity> element in the
web.config file and set the impersonate attribute to true as shown in the
following code snippet:
<identity impersonate =
"true" />
Q. How can you identify that
the page is PostBack?
A-The Page object uses the
IsPostBack property to check whether the page is posted back or not. If the
page is postback, this property is set to true.
Q. In which database is the
information, such as membership, role management, profile, and Web parts
personalization, stored?
A-The aspnetdb database stores
all information.
60. What is State Management?
How many ways are there to maintain a state in .NET?
A-State management is used to
store information requests. The state management is used to trace the
information or data that affect the state of the applications.
There are two ways to maintain
a state in .NET, Client-Based state management and Server-Based state
management.
The following techniques can
be used to implement the Client-Based state management:
>View State
>Hidden Fields
>Cookies
>Query Strings
>Control State
The following techniques can
be used to implement Server-Based state management:
>Application State
>Session State
>Profile Properties
Q. What do you understand by
aggregate dependency?
A-Aggregate dependency allows
multiple dependencies to be aggregated for content that depends on more than
one resource. In such type of dependency, you need to depend on the sum of all
the defined dependencies to remove a data item from the cache.
Q. How can you ensure that no
one has tampered with ViewState in a Web page?
A-To ensure that no one has
tampered with ViewState in a Web page, set the EnableViewStateMac property to
True.
Q. What is the difference
between adding items into cache through the Add() method and through the
Insert() method?
A-Both methods work in a similar
way except that the Cache.Add() function returns an object that represents the
item you added in the cache. The Cache.Insert() function can replace an
existing item in the cache, which is not possible using the Cache.Add() method.
Q. Explain the cookie less
session and its working.
A-ASP.NET manages the session
state in the same process that processes the request and does not create a
cookie. It is known as a cookie less session. If cookies are not available, a
session is tracked by adding a session identifier to the URL. The cookie less
session is enabled using the following code snippet: <sessionState
cookieless="true" />
Q. What is a round trip?
A-The trip of a Web page from
the client to the server and then back to the client is known as a round trip.
Q. What are the major
built-in objects in ASP.NET?
A-The major built-in objects in
ASP.NET are as follows:
->Application, ->Request,->Response,->Server,->Session,->Context,
->Trace
Q. Where should the data
validations be performed-at the client side or at the server side and why?
A-Data validations should be
done primarily at the client side and the server-side validation should be
avoided because it makes server task overloaded. If the client-side validation
is not available, you can use server-side validation. When a user sends a
request to the server, the validation controls are invoked to check the user
input one by one.
Q. Why do we need nested
master pages in a Web site?
A-When we have several
hierarchical levels in a Web site, then we use nested master pages in the Web
site.
Q. How can you dynamically
add user controls to a page?
A-User controls can be
dynamically loaded by adding a Web User Control page in the application and
adding the control on this page.
Q. What is the appSettings
Section in the web.config file?
A-The web.config file sets the
configuration for a Web project. The appSettings block in configuration file
sets the user-defined values for the whole application.
For example, in the following
code snippet, the specified ConnectionString section is used throughout the
project for database connection:
<configuration>
<appSettings>
<add
key="ConnectionString" value="server=indiabixserver;
pwd=dbpassword; database=indiabix" />
</appSettings>
Q. What type of code,
client-side or server-side, is found in a code-behind file of a Web page?
A-A code-behind file contains
the server-side code, which means that the code contained in a code-behind file
is executed at the server.
Q. To which class a Web form
belongs to in the .NET Framework class hierarchy?
A-A Web form belongs to the
System.Web.UI.Page class.
Q. What does the
"EnableViewState" property do? Why do we want it On or Off?
A-The EnableViewState property
enables the ViewState property on the page. It is set to On to allow the page
to save the users input between postback requests of a Web page; that is,
between the Request and corresponding Response objects. When this property is
set to Off, the page does not store the users input during postback.
Q. Which event determines
that all the controls are completely loaded into memory?
A-The Page_Load event determines
that all the controls on the page are fully loaded. You can also access the
controls in the Page_Init event; however, the ViewState property does not load
completely during this event.
Q. What is the function of
the CustomValidator control?
A-It provides the customize
validation code to perform both client-side and server-side validation.
Q. What is Role-based
security?
A-In the Role-based security, you can assign a role to every user and grant the privilege according to that role. A role is a group of principal that restricts a user's privileges. Therefore, all the organization and applications use role-based security model to determine whether a user has enough privileges to perform a requested task.
A-In the Role-based security, you can assign a role to every user and grant the privilege according to that role. A role is a group of principal that restricts a user's privileges. Therefore, all the organization and applications use role-based security model to determine whether a user has enough privileges to perform a requested task.
Q. Which data type does the
RangeValidator control support?
A-The data types supported by
the RangeValidator control are Integer, Double, String, Currency, and Date.
Q. What are the HTML server
controls in ASP.NET?
A-HTML server controls are
similar to the standard HTML elements, which are normally used in HTML pages.
They expose properties and events that can be used programmatically. To make
these controls programmatically accessible, you need to specify that the HTML
controls act as a server control by adding the runat="server"
attribute.
Q. Why a SiteMapPath control
is referred to as breadcrumb or eyebrow navigation control?
A-The SiteMapPath control
displays a hierarchical path to the root Web page of the Web site. Therefore,
it is known as the breadcrumb or eyebrow navigation control.
Q. Where is the ViewState
information stored?
A-The ViewState information is
stored in the HTML hidden fields.
Q. Which namespaces are
necessary to create a localized application?
A-The System.Globalization and
System.Resources namespaces are essential to develop a localized application.
Q. What is the difference
between an HtmlInputCheckBox control and an HtmlInputRadioButton control?
A-You can select more than one
HtmlInputCheckBox control from a group of HtmlInputCheckBox controls; whereas,
you can select only a single HtmllnputRadioButton control from a group of
HtmlInputRadioButton controls.
Q. What is the difference
between HTML and Web server controls?
A-HTML controls are client-side
controls; therefore, all the validations for HTML controls are performed at the
client side. On the other hand, Web server controls are server-side controls;
therefore, all the validations for Web server controls are performed at the
server side.
Q. Explain the AdRotator
Control.
A-The AdRotator is an ASP.NET
control that is used to provide advertisements to Web pages. The AdRotator
control associates with one or many advertisements, which randomly displays one
by one at a time when the Web page is refreshed. The AdRotator control
advertisements are associated with links; therefore, when you click on an
advertisement, it redirects you to other pages.
The AdRotator control is
associated with a data source, which is normally an xml file or a database
table. A data source contains all the information, such as advertisement
graphics reference, link, and alternate text. Therefore, when you use the
AdRotator control, you should first create a data source and then associate it
with the AdRotator control.
Q. What do you understand by
the culture?
A-The culture denotes a
combination of a language and optionally a region or a country. The contents of
a Web page of a multilingual Web site are changed according to the culture
defined in the operating system of the user accessing the Web page.
Q. What is the difference
between absolute expiration and sliding-time expiration?
A-The absolute expiration
expires a cached item after the provided expiration time. The sliding time does
not expire the cached items because it increments the specified time.
Q. What is the code-behind
feature in ASP.NET?
A-The code-behind feature of
ASP.NET enables you to divide an ASP.NET page into two files - one consisting
of the presentation data, and the second, which is also called the code-behind
file, consisting of all the business logic. The presentation data contains the
interface elements, such as HTML controls and Web server controls, and the
code-behind contains the event-handling process to handle the events that are
fired by these controls. The file that contains the presentation data has the
.aspx extension. The code behind file has either the .cs extension (if you are
using the programming language C#) or the .vb (if you are using the programming
language Visual Basic .NET) extension.
Q. How can you check if all
the validation controls on a Web page are valid and proper?
A-You can determine that all the
validation controls on a Web page are properly working by writing code in the
source file of the Web page using a scripting language, such as VBScript or
JavaScript. To do this task, you have to loop across validators collection of
pages and check the IsValid property of each validation control on the Web page
to check whether or not the validation test is successful.
Q. Explain the validation
controls. How many validation controls in ASP.NET 4.0?
A-Validation controls are
responsible to validate the data of an input control. Whenever you provide any
input to an application, it performs the validation and displays an error
message to user, in case the validation fails.
ASP.NET 4.0 contains the
following six types of validation controls:
CompareValidator - Performs a comparison
between the values contained in two controls.
CustomValidator - Writes your own method to
perform extra validation.
RangeValidator- Checks value according to
the range of value.
RegularExpressionValidator - Ensures that
input is according to the specified pattern or not.
RequiredFieldValidator - Checks either a
control is empty or not.
ValidationSummary - Displays a summary of
all validation error in a central location.
Q. What is difference between
a Label control and a Literal control?
The Label control's final html
code has an HTML tag; whereas, the Literal control's final html code contains
only text, which is not surrounded by any HTML tag.
Q . How many types of Cookies are available in
ASP.NET?
A-There are two types of Cookies
available in ASP.NET.Thats are :1-Session Cookie - Resides on the client
machine for a single session until the user does not log out.2-Persistent
Cookie - Resides on a user's machine for a period specified for its expiry, such
as 10 days, one month, and never. The user can set this period manually.
Q. What is the use of the
Global.asax file?
A-The Global.asax file executes
application-level events and sets application-level variables.
Q. What are the Culture and
UICulture values?
A-The Culture value determines
the functions, such as Date and Currency, which are used to format data and
numbers in a Web page. The UICulture value determines the resources, such as
strings or images, which are loaded for a Web page in a Web application.
Q. What is the difference
between ASP session and ASP.NET session?
A-ASP does not support
cookie-less sessions; whereas, ASP.NET does. In addition, the ASP.NET session
can span across multiple servers.
Q. Which control will you use
to ensure that the values in two different controls match?
A-You should use the
CompareValidator control to ensure that the values in two different controls
match.
Q. What is the difference
between a page theme and a global theme?
A-A page theme is stored inside
a subfolder of the App_Themes folder of a project and applied to individual Web
pages of that project. Global themes are stored inside the Themes folder on a
Web server and apply to all the Web applications on the Web server.
Q. What do you mean by a
neutral culture?
A-When you specify a language
but do not specify the associated country through a culture, the culture is
called as a neutral culture.
Q. What is the use of the
<sessionState> tag in the web.config file?
A-The <sessionState> tag
is used to configure the session state features. To change the default timeout,
which is 20 minutes, you have to add the following code snippet to the
web.config file of an application: <sessionState timeout="40"/>
Q. Can you post and access
view state in another application?
A-Yes, you can post and access a
view state in other applications. However, while posting a view state in
another application, the PreviousPage property returns null.
Q. Which method do you use
to kill explicitly a users session?
A-The Session.Abandon() method
kills the user session explicitly.
Q. Which class is inherited
when an ASP.NET server control is added to a Web form?
A-The System.Web.UI.WebControls
class is inherited when an ASP.NET server control is added to a Web form.
Q. What events are fired
when a page loads?
A-The following events fire when
a page loads:
Init() - Fires when the page is
initializing.
LoadViewState() - Fires when the view state
is loading.
LoadPostData() - Fires when the postback
data is processing.
Load() - Fires when the page is loading.
PreRender() - Fires at the brief moment
before the page is displayed to the user as HTML.
Unload() - Fires when the page is
destroying the instances of server controls.
Q. Write three common
properties of all validation controls.
A-Three common properties of
validation controls are as follows:
ControlToValidate - Provides a control to
validate
ErrorMessage - Displays an error message
IsValid - Specifies if the control's validation
has succeeded or not
Text - Displays a text for validation
control before validation.
Q. What are navigation controls? How many navigation controls are there in ASP.NET 4.0?
Q. What are navigation controls? How many navigation controls are there in ASP.NET 4.0?
A-Navigation controls help you
to navigate in a Web application easily. These controls store all the links in
a hierarchical or drop-down structure; thereby facilitating easy navigation in
a Web application.
There are three navigation
controls in ASP.Net 4.0.
->SiteMapPat , -> Menu ,->TreeView
Q. What happens if an ASP.NET
server control with event-handling routines is missing from its definition?
A-The compilation of the
application fails.
Q. What are server-side
comments?
A-Server-side comments are
included in an ASP.NET page for the purpose of documentations as shown in the
following code snippet:
<%--This is an example of
server-side comments --%>
The server-side comments begin
with <%-- and end with --%>.
Q. How can we provide the
WebParts control functionality to a server control?
A-We can provide the WebParts
controls functionality to a server control by setting the CreateWebPart
property of WebPartManger.
Q. How do you prevent a
validation control from validating data at the client end?
A-You can prohibit a validation
control to validate data at the client side by setting the EnableClientScript
property to False.
Q. What is cross-page
posting in ASP.NET?
A-The Server.Transfer() method
is used to post data from one page to another. In this case, the URL remains
the same. However, in cross page posting, data is collected from different Web
pages and is displayed on a single page. To do so, you need to set the
PostBackUrl property of the control, which specifies the target page. In the
target page, you can access the PreviousPage property. For this, you need to
use the @PreviousPageType directive. You can access the controls of previous
page by using the FindControl() method.
Q. Which ASP.NET
configuration options are supported in the ASP.NET implementation on the shared
Web hosting platform?
A-There are many ASP.NET configuration
choices, which are not able to configure at the site, application, or child
directory level on the shared hosting environment. Some options can produce
security, performance, and stability problem to the server and therefore cannot
be changed.
The following settings are the
only ones that can be changed in the web.config file(s) of your Web site:
--->browserCaps
--->clientTarget
--->>pages ,--->customErrors ,--->globalization ,---->authorization ,----->authentication , ----->webControls ,----->webServices
Q. Explain the Application
and Session objects in ASP.NET.
A-Application state is used to
store data corresponding to all the variables of an ASP.NET Web application.
The data in an application state is stored once and read several times.
Application state uses the HttpApplicationState class to store and share the data
throughout the application. You can access the information stored in an
application state by using the HttpApplication class property. Data stored in
the application state is accessible to all the pages of the application and is
the same for all the users accessing the application. The HttpApplicationState
class provides a lock method, which you can use to ensure that only one user is
able to access and modify the data of an application at any instant of time.
Each client accessing a Web
application maintains a distinct session with the Web server, and there is also
some specific information associated with each of these sessions. Session state
is defined in the <sessionState> element of the web.config file. It also
stores the data specific to a user session in session variables. Different
session variables are created for each user session. In addition, session
variables can be accessed from any page of the application. When a user
accesses a page, a session ID for the user is created. The session ID is transferred
between the server and the client over the HTTP protocol using cookies.
Q. How will you
differentiate a submaster page from a top-level master page?
A-Similar to a content page, a
submaster page also does not have complete HTML source code; whereas, a
top-level master page has complete HTML source code inside its source file.
Q. What are Web server
controls in ASP.NET?
A-The ASP.NET Web server
controls are objects on the ASP.NET pages that run when the Web page is
requested. Many Web server controls, such as button and text box, are similar
to the HTML controls. In addition to the HTML controls, there are many
controls, which include complex behavior, such as the controls used to connect
to data sources and display data.
Q. What is the difference
between a HyperLink control and a LinkButton control?
A-A HyperLink control does not
have the Click and Command events; whereas, the LinkButton control has these
events, which can be handled in the code-behind file of the Web page.
Q. What are the various ways
of authentication techniques in ASP.NET?
A-There are various techniques
in ASP.NET to authenticate a user. You can use one of the following ways of
authentication to select a built-in authentication provider:
1-> Windows Authentication - This mode works as
the default authentication technique. It can work with any form of Microsoft
Internet Information Services (IIS) authentication, such as Basic, Integrated
Windows authentication (NTLM/Kerberos), Digest, and certificates. The syntax of
Windows authentication mode is given as follows: <authentication
mode="windows" />.
2-> Forms Authentication - You can specify this mode as a default authentication mode by using the following code snippet: <authentication mode="Forms"/> .
3-> Passport - This mode works with Microsoft Passport authentication, as shown in the following code snippet: <authentication mode = "Passport"/>
2-> Forms Authentication - You can specify this mode as a default authentication mode by using the following code snippet: <authentication mode="Forms"/> .
3-> Passport - This mode works with Microsoft Passport authentication, as shown in the following code snippet: <authentication mode = "Passport"/>
Q. What are the different
ways to send data across pages in ASP.NET?
A-The following two ways are
used to send data across pages in ASP.NET:
-> Session
-> Public properties
Q. What does the
WebpartListUserControlPath property of a DeclarativeCatalogPart control do?
A-The WebpartListUserControlPath
property sets the route of the user defined control to a DeclarativeCatalogPart
control.
Q. What do you mean by the
Web Part controls in ASP.NET?
A-The Web Part controls are the
integrated controls, which are used to create a Web site. These controls allow
the users to change the content, outlook, and state of Web pages in a Web
browser.
Q. What type of the
CatalogPart control enables users to restore the Web Parts that have been
removed earlier by the user?
A-The PageCatalogPart control.
Q. What is the use of
web.config? What is the difference between machine.config and web.config?
A-ASP.NET configuration files
are XML-based text files for application-level settings and are saved with the
name web.config. These files are present in multiple directories on an ASP.NET
Web application server. The web.config file sets the configuration settings to
the directory it is placed in and to all the virtual sub folders under it. The
settings in sub directories can optionally override or change the settings
specified in the base directory.
The difference between the
web.config and machine.config files is given as follows:
--><WinDir>\Microsoft.NET\Framework\<version>\config\machine.config
provides default configuration settings for the entire machine. ASP.NET
configures IIS to prohibit the browser directly from accessing the web.config files
to make sure that their values cannot be public. Attempts to access those files
cause ASP.NET to return the 403: Access Forbidden error.
-->
ASP.NET uses these web.config configuration files at runtime to compute
hierarchically a sole collection of settings for every URL target request.
These settings compute only once and cached across further requests. ASP.NET
automatically checks for changing file settings and do not validate the cache
if any of the configuration changes made.
Q. Explain the concept of
states in ASP.NET?
A-State is quite an innovative
concept in Web development because it eliminates the drawback of losing state
data due to reloading of a Web page. By using states in a Web application, you
can preserve the state of the application either at the server or client end.
The state of a Web application helps you to store the runtime changes that have
been made to the Web application. For example, as already described earlier, a
change in the data source of the Web application might be initiated by a user
when he/she selects and saves some products in the shopping cart.
If you are not using states,
these changes are discarded and are not saved. You may think that the whole
concept of storing states is optional. However, under certain circumstances,
using states with applications is imperative. For example, it is necessary to
store states for Web applications, such as an e-commerce shopping site or an
Intranet site of a company, to keep track of the requests of the users for the
items they have selected on the shopping site or the days requested for
vacation on the Intranet site.
Q. Can we validate a
DropDownList by RequiredFieldValidator?
A-Yes, we can validate a
DropDownList by RequiredFieldValidator. To perform this validation, we have to
set the InitialValue property of RequiredFieldValidator control.
Q. List the features of the
Chart control.
A-The following are the features
of the Chart control:
-> Bounds a chart with any data source.
-> Simple manipulation of chart data, such as
copying, merging, grouping,
sorting, searching, and filtering.
-> Support many statistical and financial
formulas for data analysis.
-> Provide advanced chart outlook, such as
2-D, 3-D, lighting,and
perspective
-> Support events and customizations.
-> Includes interactivity with Microsoft AJAX.
-> Supports AJAX Content Delivery Network
(CDN).
ADO.NET Questions and Answers:
Q.What is ADO.NET?
ADO.NET is a part of the
Microsoft .NET Framework. This framework provides the set of classes that deal
with data communication between various layers of the software architecture and
the database. It provides a continuous access to different data source types
such as SQL Server versions 7, 2000, 2005. It also provides connectivity
options to data sources through OLE DB and XML. Connectivity may be established
with other databases like Oracle, MySQL etc. as well.
ADO.NET has the ability to separate data access mechanisms, data manipulation mechanisms and data connectivity mechanisms.
ADO.NET introduces along with it the disconnected architecture. In a disconnected architecture, data may be stored in a DataSet. It contains providers for connecting to databases, commands for execution and retrieval of results.
The classes for ADO.NET are stored in the DLL System.Data.dll.
ADO.NET has the ability to separate data access mechanisms, data manipulation mechanisms and data connectivity mechanisms.
ADO.NET introduces along with it the disconnected architecture. In a disconnected architecture, data may be stored in a DataSet. It contains providers for connecting to databases, commands for execution and retrieval of results.
The classes for ADO.NET are stored in the DLL System.Data.dll.
Q.can we connect two dataadapters to same data source
using single connection at same time?
yes,we can connect two
dataadapters to same datasource using single connection at same time.
There is a technology in ado.net 2.0 called MARS usinng Mars in connection string we can do it.
for eg:
cn.ConnectionString = "server=(local); database=employee; integrated security=sspi; MultipleActiveResultSets=True";
There is a technology in ado.net 2.0 called MARS usinng Mars in connection string we can do it.
for eg:
cn.ConnectionString = "server=(local); database=employee; integrated security=sspi; MultipleActiveResultSets=True";
Q.Can we do database operations without using any of
the ADO.net objects?
No its not at all
possible.
Q.If we are not returning any records from the
database, which method is to be used?
There is a method called
Execute Non Query. This method executes the Update, Delete etc. This does not
return any rows but will give the number of rows affected.
Q. how can i retrieve two tables of data at a time by
using data reader?
Data reader read and forward only, how is it possible to get 2 tables of data at a time?
Data reader read and forward only, how is it possible to get 2 tables of data at a time?
yes this is possible
If we execute 2 select command either in stored procedure or in select command and then executereader method fired of command object. it return 2 tables in datareader.
like :
string str="Select * from a;select * from b";
cmd.commandtext=str;
dr=cmd.executereader();
Now it return 2 tables in datareader (dr).
If we execute 2 select command either in stored procedure or in select command and then executereader method fired of command object. it return 2 tables in datareader.
like :
string str="Select * from a;select * from b";
cmd.commandtext=str;
dr=cmd.executereader();
Now it return 2 tables in datareader (dr).
Q.Explain ExecuteNonQuery?
//
Summary:
// Executes a Transact-SQL statement against the connection and returns the number of rows affected.
// Returns:
// The number of rows affected.
// Executes a Transact-SQL statement against the connection and returns the number of rows affected.
// Returns:
// The number of rows affected.
Q.What is the ExecuteScalar
method?
//
Summary:
Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
// Returns:
The first column of the first row in the result set, or a null reference (Nothing in Visual Basic) if the result set is empty.
Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
// Returns:
The first column of the first row in the result set, or a null reference (Nothing in Visual Basic) if the result set is empty.
Q.Which one of the following
objects is a high-level abstraction of the Connection and Command objects in
ADO.NET?
DataReader
DataSet DataTable DataView DataAdapter
A- DataAdapter
A- DataAdapter
Q.How can we load multiple tables
in to Dataset?
A-DataSet
ds=new DataSet();
SqlDataAdapter dap=new SqlDataAdapter(Select * from <tablename>,<connection1>);
dap.Fill(ds,"TableOne");
SqlDataAdapter dap1=new SqlDataAdapter(Select * from <tablename>,<connection1>);
dap1.Fill(ds,"tableTwo");
SqlDataAdapter dap=new SqlDataAdapter(Select * from <tablename>,<connection1>);
dap.Fill(ds,"TableOne");
SqlDataAdapter dap1=new SqlDataAdapter(Select * from <tablename>,<connection1>);
dap1.Fill(ds,"tableTwo");
Q.What is connection String?
connection
String - a string which contains address of the database we want to connect to.
Q.What is Delegate?
Q.What is Delegate?
Delegate
is an important element of C# and is extensively used in every type of .NET
application. A delegate is a class whose object (delegate object) can store a
set of references to methods.
Q.How do you update a Dataset in
ADO.Net and How do you update database through Dataset?
a.
Update a dataset;
Dataset ds = new dataset();
SqlDataAdapter adp = new SqlDataAdapter(Query,connection);
Adp.fill(ds);
Again you can add/update Dataset as below
SqlDataAdapter adp1 = new SqlDataAdapter(Query1,connection);
Adp1.fill(ds);
b. Update database through dataset.
SqlCommandBuilder mySqlCommandBuilder = new SqlCommandBuilder(mySqlDataAdapter);
Foreach(datarow dr in ds.table[0].rows)
{
Dr[“column Name”] = “value”;
mySqlDataAdapter.Update(ds);
}
Dataset ds = new dataset();
SqlDataAdapter adp = new SqlDataAdapter(Query,connection);
Adp.fill(ds);
Again you can add/update Dataset as below
SqlDataAdapter adp1 = new SqlDataAdapter(Query1,connection);
Adp1.fill(ds);
b. Update database through dataset.
SqlCommandBuilder mySqlCommandBuilder = new SqlCommandBuilder(mySqlDataAdapter);
Foreach(datarow dr in ds.table[0].rows)
{
Dr[“column Name”] = “value”;
mySqlDataAdapter.Update(ds);
}
Q. What are the steps to connect
to a database?
1.
Create a connection. This requires a connection string, which can be given
declaratively or put in a well defined place like the .config files. Advantage
of keeping in .config files is that it enables use of Connection Pooling by
.Net framework, else even one small change in connection string will cause CLR
to think it's not the same connection and will instantiate new connection for
other request.
2. Open the connection and keep it open until done, typically done as using (con) { //use }
3. If using connected data model, create a SqlCommand object, decorate it with desired command, command type (stored procedure for eg), add any parameters and their values to the command, and then consume the command by using ExcuteReader or ExecuteScalar. In case of ExecuteReader, we will get back a handle to a fast-forward, read only pointer to the recordset. We can also decorate Command object with multiple recordsets in 2.0 and execute one by one (MARS - Multiple Active Record Sets)
4. If using disconnected data model, create a DataAdapter object, decorate it with desired SELECT, INSERT, UPDATE, DELETE commands, add parameters as necessary and then fill up a DataSet or DataTable using the DataAdapter. Subsequent SQL can be executed using insert, update, delete commands on the dataset.
2. Open the connection and keep it open until done, typically done as using (con) { //use }
3. If using connected data model, create a SqlCommand object, decorate it with desired command, command type (stored procedure for eg), add any parameters and their values to the command, and then consume the command by using ExcuteReader or ExecuteScalar. In case of ExecuteReader, we will get back a handle to a fast-forward, read only pointer to the recordset. We can also decorate Command object with multiple recordsets in 2.0 and execute one by one (MARS - Multiple Active Record Sets)
4. If using disconnected data model, create a DataAdapter object, decorate it with desired SELECT, INSERT, UPDATE, DELETE commands, add parameters as necessary and then fill up a DataSet or DataTable using the DataAdapter. Subsequent SQL can be executed using insert, update, delete commands on the dataset.
Q. How do you connect to SQL
Server Database without using sqlclient?
you
can connect sql using oledbname space .
Q.What is Partial class?
A
Partial class is a class that can be split into two or more classes. This means
that a class can be physically separated into other parts of the class within
the same namespace. All the parts must use the partial keyword. All the other
classes should also have the same access modifier. At the compile time, all the
partial classes will be treated as a single class. Let us list some advantages
of having partial classes.
Q.what are the advantages and
disadvantages of using datalist?
Adv:
the DataList's display is defined via templates,DataList allows for much more
customization of the rendered HTML markup , by which it is more user-friendly
displays of data.
DisAdv:
adding such functionality with the DataList takes more development time than with the DataGrid, as,
1. The Edit/Update/Cancel buttons that can be created in a DataGrid via the EditCommandColumn column type, must be manually added to the DataList, and
2. The DataGrid BoundColumn column types automatically use a TextBox Web control for the editing interface, whereas with the DataList you must explicitly specify the editing interface for the item being edited via the EditItemTemplate.
3. we can't do the paging and sorting with datalist controls.
DisAdv:
adding such functionality with the DataList takes more development time than with the DataGrid, as,
1. The Edit/Update/Cancel buttons that can be created in a DataGrid via the EditCommandColumn column type, must be manually added to the DataList, and
2. The DataGrid BoundColumn column types automatically use a TextBox Web control for the editing interface, whereas with the DataList you must explicitly specify the editing interface for the item being edited via the EditItemTemplate.
3. we can't do the paging and sorting with datalist controls.
Q.What is the difference between
data reader and data adapter?
A-DateReader
is an forward only and read only cursor type if you are accessing data through
DataRead it shows the data on the web form/control but you can not perform the
paging feature on that record(because it's forward only type). Reader is best
fit to show the Data (where no need to work on data)
DataAdapter is not only connect with the Databse(through Command object) it provide four types of command (InsertCommand, UpdateCommand, DeleteCommand, SelectCommand), It supports to the disconnected Architecture of .NET show we can populate the records to the DataSet. where as Dataadapter is best fit to work on data.
DataAdapter is not only connect with the Databse(through Command object) it provide four types of command (InsertCommand, UpdateCommand, DeleteCommand, SelectCommand), It supports to the disconnected Architecture of .NET show we can populate the records to the DataSet. where as Dataadapter is best fit to work on data.
Q.What is the difference between
data reader and data set?
1)
DataSet is disconnected object type. It uses XML to store data.
2) It fetches all data from the data source at a time
3) Modifications can be updated to the actual database
4) It will reduce the application performance.
2) It fetches all data from the data source at a time
3) Modifications can be updated to the actual database
4) It will reduce the application performance.
No,
each have its own functionality,
ex : for sql client , there is SqlConnection object
and for oledb client , there is OleDBConnection
ex : for sql client , there is SqlConnection object
and for oledb client , there is OleDBConnection
It
has no such feature.
ADO.NET Questions and Answers:
a) SQLCommand is used to
execute all kind of SQL queries like DML(Insert, update,Delete) & DDL
like(Create table, drop table etc)
b)SQLCommandBuilder object is used to build & execute SQL (DML) queries like select, insert, update & delete.
b)SQLCommandBuilder object is used to build & execute SQL (DML) queries like select, insert, update & delete.
.net doesn't support the
mutiple inheritance, perhaps you may talk about multi-level inheritance.
In the later case, if a class is inherited from another class, at the time of creating instance, it will obviously give a call to its base class constructor (ie bottom - top approach). Like wise the constructor execution is takes place in top down approach (ie. base class constructor is executed and the derived class constructor is executed).
So for GC, it will collect only when an object does not have any reference. As we see previously, the derived is constructed based on base class. There is a reference is set to be. Obviously GC cannot be collected.
In the later case, if a class is inherited from another class, at the time of creating instance, it will obviously give a call to its base class constructor (ie bottom - top approach). Like wise the constructor execution is takes place in top down approach (ie. base class constructor is executed and the derived class constructor is executed).
So for GC, it will collect only when an object does not have any reference. As we see previously, the derived is constructed based on base class. There is a reference is set to be. Obviously GC cannot be collected.
First Excute Sql Quries
in Query Analzer,see How much time 2 take Excute , if Less then the ur desired
Time, then it will Optimize query
it is possible
DataSet ds;
sqlAdap.Fill(ds);
Datatable dt = ds.Tables[0].copy();
//now the structure and data are copied into 'dt'
ds.Tables.remove(ds.Table[0]);
//now the source is removed from the 'ds'
DataSet ds;
sqlAdap.Fill(ds);
Datatable dt = ds.Tables[0].copy();
//now the structure and data are copied into 'dt'
ds.Tables.remove(ds.Table[0]);
//now the source is removed from the 'ds'
executescalar()
executereader()
executenonquery()
these comes with Begin and End like Beginexecutescalr() Endexecutescalar().......
by using these command we can achieve asynch comm in ado.net
executereader()
executenonquery()
these comes with Begin and End like Beginexecutescalr() Endexecutescalar().......
by using these command we can achieve asynch comm in ado.net
A
DataSet can be Typed or Untyped. The difference between the two lies in the
fact that a Typed DataSet has a schema and an Untyped DataSet does not have
one. It should be noted that the Typed Datasets have more support in Visual
studio.
By
Using the Transactions we can check the Exact Numbers of the rows to be updated
and if the updation fails then the Transaction will be rollbacked.
data
reader can hold data from multiple tables and datareader can hold more than one
table.
string query="select * from employee; select * from student";
sqlcommand cmd=new sqlcommand(query, connection);
sqldatareader dr=cmd.executeReader();
if(dr.hasrows)
{
dr.read();
gridview1.DataSource=dr;
gridview1.Databind();
if(dr.nextresult)
{
gridview2.datasource=dr;
gridview2.databind();
}
}
dr.colse();
connection.close();
string query="select * from employee; select * from student";
sqlcommand cmd=new sqlcommand(query, connection);
sqldatareader dr=cmd.executeReader();
if(dr.hasrows)
{
dr.read();
gridview1.DataSource=dr;
gridview1.Databind();
if(dr.nextresult)
{
gridview2.datasource=dr;
gridview2.databind();
}
}
dr.colse();
connection.close();
DO.NET
Command Object - The Command object is similar to the old ADO command object.
It is used to store SQL statements that need to be executed against a data source.
The Command object can execute SELECT statements, INSERT, UPDATE, or DELETE statements, stored procedures, or any other statement understood by the database.
It is used to store SQL statements that need to be executed against a data source.
The Command object can execute SELECT statements, INSERT, UPDATE, or DELETE statements, stored procedures, or any other statement understood by the database.
all
heavy controls like grid view,datagrid or datalist,repeater controls cantains
the chield controls like button or link button, when we click this button then
the event will be raised, that events are handled by parant controls,that is
called event bubbling,means event is bubbled from bottom(chield)to up(parant).
Q. If a table contains 20000
records . In a page at each time 100 records to be displayed.
What are the steps u will take to improve performance? will you use dataset or datareader?
What are the steps u will take to improve performance? will you use dataset or datareader?
we
have to use a dataset because on using datareader forward only paging can be
achieved.
Suppose if you are at 1000 page and you want to go back to 999th page, if you use datareader it cannot be achieved, since it does not support backward navigation.
Dataset supports forward and backward navigation
Suppose if you are at 1000 page and you want to go back to 999th page, if you use datareader it cannot be achieved, since it does not support backward navigation.
Dataset supports forward and backward navigation
Q. What is data access layer?
Data
Access layer is actually a part of Architecture layer. It has 2 tier,3 tier or
N tier Layer. Generally we use 3 tier Layer 1) Presentation layer,Business
Logic layer and then Data Access Layer. Data Access layer is a medium to talk
between database and Business Logic layer.
It helps to maintain flexibility,resuablity and even secuity also. In security SQL Injection can be stopped with 3 iter Archietcture.
Q. What are the different row versions available in table?
It helps to maintain flexibility,resuablity and even secuity also. In security SQL Injection can be stopped with 3 iter Archietcture.
Q. What are the different row versions available in table?
A-There
are four types of Rowversions.
Current:
The current values for the row. This row version does not exist for rows with a RowState of Deleted.
Default :
The row the default version for the current DataRowState. For a DataRowState value of Added,
Modified or Current, the default version is Current. For a DataRowState of Deleted, the version is Original.
For a DataRowState value of Detached, the version is Proposed.
Original:
The row contains its original values.
Proposed:
The proposed values for the row. This row version exists during an edit operation on a row, or for a
row that is not part of a DataRowCollection.
Current:
The current values for the row. This row version does not exist for rows with a RowState of Deleted.
Default :
The row the default version for the current DataRowState. For a DataRowState value of Added,
Modified or Current, the default version is Current. For a DataRowState of Deleted, the version is Original.
For a DataRowState value of Detached, the version is Proposed.
Original:
The row contains its original values.
Proposed:
The proposed values for the row. This row version exists during an edit operation on a row, or for a
row that is not part of a DataRowCollection.
Q-What are the two fundamental
objects in ADO.NET?
A-Datareader
and Dataset are the two fundamental objects in ADO.NET
Q-What we do with the object of
ado.net dataset after using it?Can we dispose it or can we set it nothing?Is it
must or not?
A-we
use dispose
Q What provider ADO.net use by
default?
A-Ado.net
uses no Dataprovider by default and this is absulotely correct answere. there
is no other choice for this question
QWhat is the provider and
namespaces being used to access oracle database?
A-The
provider name is oledb and the namespace is system.data.oledb
Q-Explain acid properties?
A-The
term ACID conveys the role transactions play in mission-critical applications.
Coined by transaction processing pioneers, ACID stands for atomicity,
consistency, isolation, and durability.
These properties ensure predictable behavior, reinforcing the role of transactions as all-or-none propositions designed to reduce the management load when there are many variables.
These properties ensure predictable behavior, reinforcing the role of transactions as all-or-none propositions designed to reduce the management load when there are many variables.
Q-What is Atomicity?
A
transaction is a unit of work in which a series of operations occur between the
BEGIN TRANSACTION and END TRANSACTION statements of an application. A transaction
executes exactly once and is atomic ?
all the work is done or none of it is.
Operations associated with a transaction usually share a common intent and are interdependent.
By performing only a subset of these operations, the system could compromise the overall intent of the
transaction. Atomicity eliminates the chance of processing a subset of operations.
Q-What is Isolation?
all the work is done or none of it is.
Operations associated with a transaction usually share a common intent and are interdependent.
By performing only a subset of these operations, the system could compromise the overall intent of the
transaction. Atomicity eliminates the chance of processing a subset of operations.
Q-What is Isolation?
A
transaction is a unit of isolation ? allowing concurrent transactions to behave
as though each were the only transaction running in the system.Isolation requires that each transaction appear to be the only transaction
manipulating the data store, even though other transactions may be running at
the same time. A transaction should never see the intermediate stages of
another transaction.Transactions attain the highest level of isolation when they are serializable.
At this level, the results obtained from a set of concurrent transactions are
identical to the results obtained by running each transaction serially. Because a high degree of isolation can limit the number of concurrent
transactions, some applications reduce the isolation level in exchange for
better throughput.
Q-what is data Adapter?
A-Data
adapter is bridge between Connection and DataSet , Data adapter in passing the
sql query and fill in dataset
Q-what is a session?
A session is the time for which a particular user interacts with a web
application. During a session the unique identity of the user is maintained
internally. A session ends if there is a session timeout or if you end the
visitor session in code.
Q-What’s the use of sessions?
Q-What’s the use of sessions?
A-Sessions helps to preserve data
across successive accesses. These can be done on a per user basis, via the use
of session objects. Session objects give us the power to preserve user
preferences and other user information when browsing a web application. To
better understand the use of sessions, consider an example: Suppose you own a
website in which you give the visitors the option to choose the background
color of the pages they will browse. In such a case you need to remember the user’s
choice on each of the page. This task can be accomplished using sessions.
A more practical example is the case
of an e-commerce website where the visitor browses through many pages and wants
to keep track of the products ordered.
Sessions in ASP.NET are simply hash
tables in the memory with a timeout specified. Consider the following examples
Session(“username”) = “Aayush Puri”
Session(“color”) = “Blue”
This assigns the values “Aayush Puri”
and “Blue” to the session variables “username” and “color”, respectively. If I
need to know the “username” or “color” in subsequent pages, I can use
Session(“username”), Session(“color”).
Sessions in ASP.NET are identified using 32-bit long integers known as Session IDs. The ASP engine generates these session ID’s so that uniqueness is guaranteed.
Let’s now see how you can configure the session object depending on the requirements of your Web Application.
Sessions in ASP.NET are identified using 32-bit long integers known as Session IDs. The ASP engine generates these session ID’s so that uniqueness is guaranteed.
Let’s now see how you can configure the session object depending on the requirements of your Web Application.
Session
Type
|
What
it does
|
Example
|
Session.Abandon
|
Abandons (cancels) the current
session.
|
|
Session.Remove
|
Delete an item from the
session-state collection.
|
Session(“username”) = “Aayush
Puri”
(Initialize a session variable)
Session.Remove(“username”)
(Deletes the session variable “username”) |
Session.RemoveAll
|
Deletes all session state items
|
|
Session.Timeout
|
Set the timeout (in minutes) for a session
|
Session.Timeout=30 (If a user does
NOT request a page of the ASP.NET application within 30 minutes then the
session expires.)
|
Session.SessionID
|
Get the session ID (read only
property of a session) for the current session.
|
|
Session.IsNewSession
|
This is to check if the visitor’s
session was created with the current request i.e. has the visitor just
entered the site. The IsNewSession property is true within the first page of
the ASP.NET application.
|
As we saw in the previous section,
sessions help us preserve data on a per user basis. What if we want to
initialize variables that are available in a session and that are the same for
all users? This means that a change in the value of an application variable is
reflected in the current sessions of all users. For example, we may like to fix
variables like tax rate, discount rate, company name, etc., that will be
specified once for all variables we can access in a session. This is where application variables come
in. Heck, they can even be used to show legal notices at the bottom of every
page!
Creating an application variable is
similar to session variables.
Application(“legal_notice”) = “No part of this article may be reproduced without prior permission”
There is a concern when changing the
value of an application variable: at any particular instant, multiple sessions
might be trying to change the value, although only one session can be allowed
to change it. ASP.NET has an in built mutual exclusion for dealing with these
types of problems.
- Application.Lock – Locks the application variables
- Application.Unlock – Unlocks the application variables
Once application variables are
locked sessions that attempt to change them have to wait.
You might need to redirect the
visitor to a particular page if some error has occurred. On the redirected
page, you’ll need to display the error message. A session variable initialized
to an error message fits the bill. Here’s an example: Suppose you are writing a
function check_string() (as a part of page named page1.aspx) which accepts no
other string than “ASP.NET Rocks!” If the string passed as an argument does not
match, then you need to redirect to a page (“page2.aspx”) and display the
error.
Page1.aspx:
Page1.aspx:
Public Sub check_string(ByVal str As String)
If Not Str.equals("ASP.NET Rocks") Then
Session("error_message") = "The string was NOT ""ASP.NET Rocks"" "
Response.Redirect("page2.aspx")
End If
End Sub
Page2.aspx This next fucntion will display the error
message.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Session("message") <> "" Then
Response.Write(Session("message"))
Session.Remove("message") 'Make the session variable null
End If
End Sub
I include this piece of code in the
function “Page_load” to check for any error message on every visit to this
page.
Here’s a personal example of having to use sessions: I had to design a website which had three types of users, all requiring authorization. All users were divided into three categories, and each category had a well defined set of rules and permissions.
Here’s a personal example of having to use sessions: I had to design a website which had three types of users, all requiring authorization. All users were divided into three categories, and each category had a well defined set of rules and permissions.
While writing server-side scripts, I
had to ensure that a particular script run only for qualified users. The
information in the database showed which user belonged to which category.
Querying the database was too cumbersome, so a simple and elegant solution was
to use session variables.
At the time of authorization I
queried the category of the user and stored the result in a session variable.
At the time of authorization also fetch the category type
Session(“category”) = Get_category(username)
And that’s it--small, quick, and to
the point. Would that all were as simple as sessions… but that’s neither here
nor there. Enjoy!
This is exactly what I wanted to read, hope in future you will continue sharing such an excellent article.
ReplyDeletedot net training center in chennai
dot net classes in chennai