Professional Documents
Culture Documents
Ans: Mainly all controls are accessible in Page_Init event except “ViewState” because it doesn’t fully
loaded during this event. The Page_Load event guarantees that all the controls are fully loaded and
ready to use.
The main difference between ASP and ASP.NET is that ASP is Interpreted Language because ASP
uses VBScript; whereas ASP.NET is Compiled Language because ASP.NET uses .NET Languages like
C#, Vb.net, which are compiled to MSIL (Microsoft Intermediate Language).
6. Which is the parent class used for the web server control?
Ans: The System.Web.UI.Control class is used for all the web server control.
12. How can you pass the value from one page to another?
Ans: Following are the two common ways to pass the values from one page to another page.
•Session
•QueryString
23. How can you call the connection string from Web.config file?
Ans: You can get and use connection string this way but what if you had specified your
connection string in Web.config and want to get from Web.config file? You can do this by using following
single line of code, like this.
//For C#: Include Namespace – using System.Configuration;
string con = ConfigurationManager.ConnectionStrings["mystring"].ConnectionString;
//For Vb.net: Include Namespace – Imports System.Configuration
Dim con As String = ConfigurationManager.ConnectionStrings("mystring").ConnectionString
24. Define PRIMARY KEY, UNIQUE KEY and FOREIGN KEY?
Ans: A PRIMARY KEY constraint is a unique identifier for a row within a database table. It ensures that
all the records have their own distinct values. Primary key constraints don’t allow NULL values, so you
guaranteed that each record has its own unique populated value.
A UNIQUE KEY constraint enforces the entity integrity and the uniqueness of the values in a set of
columns; so no duplicate values are entered.
On the other hand, FOREIGN KEY constraints are used to enforce referential integrity. A Foreign Key in
one table points to a “primary key” or “unique key” on another related database table. It prevent actions
that would change rows with foreign key values when there are no primary keys in related table with
that same value.
26. What are the differences between PRIMARY KEY and UNIQUE KEY?
Ans: A PRIMARY KEY is also a UNIQUE KEY internally, but a primary key cannot allow NULL values;
whereas UNIQUE KEY allows a single NULL value but does not allows multiple NULL values over the
columns. Following are some other differences between them:
•Primary Key:
– A primary key can be only once in a table
– A primary key never allow NULL values
– A primary key is a unique key identifier and cannot be NULL and must be UNIQUE
•Unique Key:
– A unique key can be more than once in one table
– A unique key can allow NULL values but not multiple NULL values
– A unique key can be NULL and may not be UNIQUE
– A unique key cannot be a candidate key
27. What is a NOT NULL Constraint?
Ans: A NOT NULL constraint enforces that the column will not allow or accept NULL values. It is used
to enforce domain integrity.
•Framework Class Library (FCL): The .NET Framework Class Library is a comprehensive, object-
oriented collection of reusable types that you can use to develop applications. The .NET
Framework class library includes ADO.NET, ASP.NET, and Windows Forms. It has a
collection of 7000+ classes and data type that enable .NET applications to access
databases, read & write files, processing XML, GUI, drawing, web services and many more.
Some of the examples are System.Data, System.Web, System.SqlClient etc.
•Common Language Runtime (CLR): The CLR is the execution engine for .NET applications &
servers as the interface between .NET applications and the operating system. Following
are the key features of the CLR:
– Loads & execute code, which includes conversion of intermediate language to native
machine code
– Separates process and memory
– Memory and Objects Management
•Page Request: When the page is requested by a user, ASP.NET determines whether the page
needs to be parsed and compiled or whether a cached version of the page can be sent in
response without running the page. The page request done before the page life cycle
starts.
•Start: In this stage, the Request and Response objects are set. If the request is an old
request or post back, the IsPostBack property of the page is set to true.
The UICulture property of the page is also set.
•Initialization: In this stage, the page initialize and the control’s UniqueID property are set.
•Load: In this stage, if the current request is a post back, control properties are loaded with
information recovered from view state and control state.
•Validation: In this stage, if all server controls on the webpage validates and runs
successfully, the IsValid property of the page is set to “true” (which let you to post data on
the server) else set to “false” (which prevent you to post data on the server).
•Postback Event Handling: In this stage, if the request is a post back, the related event handler
is called.
•Rendering: Before rendering, ViewState is saved for the page and all controls. During the
rendering stage, the page calls the “Render” method for each control, providing a text
writer that writes its output to the OutputStream object of the page’s Response property.
•Unload: In this stage, the rendered page is sent to the client and page properties, such
asResponse and Request are unloaded and all cleanup done.
•PreInit: The PreInit is the first event in page life cycle. It checks the IsPostBack property
and determines whether the page is a postback. It sets the themes and master pages,
creates dynamic controls and gets and sets profile property values. This event can be
handled by overloading the OnPreInit method or creating a Page_PreInit handler.
•Init: The Init event fires when the page is initializing.
•InitComplete: The InitComplete event fires when all the controls turn on view state tracking.
•LoadViewState: The LoadViewState event fires when the view state is loading.
•LoadPostData: The LoadPostData event fires when the post back data is processing.
•PreLoad: The PreLoad event fires after the page loads view state for itself and all controls,
and after it processes post back data that is included with the Request instance.
•Load: The Load event fires when the page is loading.
•Control events: Use these events to handle specific control events, such as
a Button control’sClick event or a TextBox control’s TextChanged event.
•LoadComplete: The LoadComplete event fires at the end of the event-handling stage. When
the loading process is completed, control event handlers are run and page validation takes
place. This event can be handled by overloading the OnLoadComplete method or creating
aPage_LoadComplete handler.
•PreRender: The PreRender event fire just before the output is rendered. By handling this
event, pages and controls can perform any updates before the output is rendered.
•PreRenderComplete: The PreRenderComplete event fires just after each data bound control
whose DataSourceID property is set calls its DataBind method.
•SaveStateComplete: The SaveStateComplete event fires after view state and control state have
been saved for the page and for all controls. Any changes to the page or controls at this
point affect rendering, but the changes will not be retrieved on the next post back.
•Render: Actually Render is not an event; but at this stage, the Page object calls this method
on each control. All the server controls have a Render method that writes out the control’s
markup to send to the browser.
•Unload: The Unload event fires when the page is destroying the instances of the server
controls.
37. What is actually returned from server to the browser when a browser
requests as .aspx file and the file is displayed?
Ans: When a browser requests .aspx file, then the server returns a response which is rendered into a
HTML string. Actually at that time all of the server controls are converted into HTML control format
because web browsers doesn’t understand the server controls; they only understand HTML strings to
display results.
39. Which two new properties are added in ASP.NET 4.0 Onwards in Page
Class?
Ans: The MetaDescription and MetaKeyword are the two properties introduced in Page Class in
ASP.NET 4.0 Onwards. To see an example, Read More from here.
44. What are Custom User Controls? How can you register it to a
webpage?
Ans: 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 works similar to other web server
controls.
The @Register directive is used to register a custom server control to a webpage.
//Register control using following statement right after @ Page directive
<%@ Register TagPrefix="myASP" TagName="myControl" Namespace="MyApp.Controls"
Assembly="MyApp" %>
//You can use like this in your .aspx page..
<myASP:myControl runat="server"/>
45. What are the difference between Abstract Class and Interface?
Ans: Following are the difference between both of them:
•Abstract Class:
– Abstract class does not support multiple inheritance
– Abstract class contains Data Member
– Abstract class contains Constructors
– An abstract class Contains both incomplete (abstract) and complete member
– An abstract class can contain access modifiers for the subs, functions, properties
– Only Complete Member of abstract class can be Static
•Interface:
– Interface can support multiple inheritance
– Interface doesn’t contains Data Member
– Interface doesn’t contains Constructors
– An interface contains only incomplete member (signature of member)
– An interface cannot have access modifiers by default everything is assumed as public
– Member of interface cannot be Static
49. How can you send an email message from an ASP.NET Webpage?
Ans: The MailMessage and SmtpMail classes of System.Net.Mail are used to send an email from
your ASP.NET webpage. You also need to create an object of the SmtpClient class to set the server
name, port, and credentials. To see an example, Read More from here.
51. Which method is used to force all the validation controls to run?
Ans: The Page.Validate() method is used to force all the validation server controls to run and to
perform validation.
52. How many Web.config files can we add in single project?
Ans: There might be more than one Web.config files for a single project depending on the hierarchy
levels of the project folders so we can add mostly one Web.config file for each folder hierarchy level.
54. What are the difference between value type and reference type?
Ans: A Value Type stores its contents in memory allocated on the stack. When you created a “value
type”, a single space in memory is allocated to store the value and that variable directly holds a value;
whereas a Reference Types are used by a reference which holds a reference or address to the object
but not the object itself because reference types represents the address of the variable rather than the
data itself, assigning a reference variable to another doesn’t copy the data.
Examples of reference types are Classes, Objects, Arrays, Indexers, and Interfaces etc; on the other
hand, Examples of reference types are Predefined datatypes, structures, enums etc.
•Advantages:
– It can reduce network traffic; results in improved performance of website
– It provides a public interface to a database
– Group of all queries at the same location, making it easier for DBAs to see how the
database is queried and optimize it accordingly.
– Reusability
– Security against SQL Injection
– Because scripts are in one location, updates and tracking of dependencies based on
schema changes becomes easier
•Advantages:
– Limited Coding Functionality
– Any data errors in handling Stored Procedures are not generated until runtime
– It is very difficult to debug Stored Procedure
– It is not efficient to use when we deal with complex logic
– If more than one application are using the same database server very frequently, it can
increase the load on server so that application becomes slow.
Note: In my opinion, We can use stored procedures to encapsulate complex queries, such as complex
joins, and complex conditions with “WHERE” clause etc but don’t use Stored Procedures for complex
application or website logic even don’t try Stored Procedures for CRUD operations with complex logic.
So, Stored Procedures should be used in a minority of cases rather than be the standard tool for all
queries in an application or website.
75. What are the templates can be used within Repeater Control?
Ans: The Repeater control contains the templates, such as HeaderTemplate, ItemTemplate,
SeparatorTemplate, AlternatingItemTemplate, FooterTemplate etc. To see an example, Read Morefrom
here.
– Indices are created in an existing table to locate rows more quickly and efficiently
– It is used to speed up queries
– It is used to improve query performance of a database application
82. Web form belongs to which class from .NET Framework Class
Library?
Ans: A Web form belongs to the System.Web.UI.Page Class from .NET Framework Class Library.
83. Which Data Type does the RangeValidator Control support?
Ans: Integer, String, Currency, Double, and Date.
87. What is the difference between Web Server and HTML Controls?
Ans: The Web Server controls are server-side controls so all the validations are performed at the
server-side; whereas the HTML controls are client-side controls so all the validations are performed at
the client-side. Web browser does not understand server controls so after page processing all the
server controls are converted into html controls to display results on the browser.
89. What is the difference between ASP.NET Label and Literal Control?
Ans: The Label control represents HTML tag; whereas the Literal control represents plain text (when it
converted, rendered and becomes ready to show data on the web browser) which is not surrounded by
any HTML tag.
Note: The round-trip is a process of a webpage from client to the server and then back from server to
the client, including client request to server response.
102. What is the difference between HAVING and WHERE Clause?
Ans: A HAVING clause used to specify a search condition for a “GROUP BY” or an Aggregate
functions, such as AVG, SUM etc; whereas a WHERE clause is applied to filter out each rows from the
table.
The main difference between both of them is that a HAVING clause can be used only with the SELECT
statement; whereas a WHERE clause can also be used with DELETE and UPDATE commands.
105. Which ASP.NET objects encapsulate the state of the client and the
browser?
Ans: The Session object encapsulates the state of the client and the web browser.