1. What
is the sequence in which ASP.NET events are processed?
Below are the sequences in which
the events occur:
- Page_Init
- Page load
- Control events
- Page unload event
Page_init event
only occurs when first time the page is started, but Page Load occurs in
subsequent requests of the page.
Page load event guarantees that
all controls are fully loaded. Controls are also accessed in Page_Init events but ViewState is not fully loaded during
this event.
3. How can we identify that the Page is postback?
The Page object has an IsPostBack property which can be
checked to know if the page was posted back or not.
ASP.NET has multiple techniques for
maintaining state between requests.
The first one is ViewState where a hidden field is added to the form containing serialized data (so stored on the client) and deserialized on postback. This field contains values of ASP.NET controls among others.
Another level is the Session which allows you to persist user related data between multiple requests which is stored on the server (either in memory or out of process).
Yet another storage is the Cache and the Application where you can store application related data which will be shared among all users. Both are stored on the server.
The first one is ViewState where a hidden field is added to the form containing serialized data (so stored on the client) and deserialized on postback. This field contains values of ASP.NET controls among others.
Another level is the Session which allows you to persist user related data between multiple requests which is stored on the server (either in memory or out of process).
Yet another storage is the Cache and the Application where you can store application related data which will be shared among all users. Both are stored on the server.
5. What
is event bubbling?
Server controls like DataGrid,
DataList, and Repeater can have other child controls inside them. For example,
DataGrid can have a combobox inside DataGrid. These child controls do not raise
their events by themselves, rather they pass the event to the container parent
(which can be a DataGrid, DataList, Repeater), which are passed to the page as
an ItemCommand event. As the child control sends events to the parent it is
termed as event bubbling.
Page attributes are specified
using the @Page directive.
Using the @Page directive and
setting the EnableViewStateMac property to true.
@Register directive informs the
compiler of any custom server control added to the page.
It’s a feature provided by
ASP.NET to prevent flickering and redrawing when the page is posted back.
Note: This is only supported for the IE browser.
Project with browser compatibility requirements have to think of other ways to
avoid flickering.
The Web.config file
defines the configuration for a web project. Using the AppSetting section, we
can define user-defined values. The example below defines the “Connection
String” section which will be used throughout the project for the database
connection.
Hide Copy Code
<Configuration>
<appSettings>
<add
key="ConnectionString"
value="server=xyz;pwd=www;database=testing" />
</appSettings>
In the HTML hidden fields.
It is used for caching. See more
in the Caching article.
User controls are created using .ASCX
in ASP.NET. After the .ASCX file is created you need two things so that
the ASCX can be used in the project:
Hide Copy Code
<%@ Register tag prefix="Accounting"
Tag name="footer" Src="Footer.ascx" %>
Hide Copy Code
<Accounting: footer runat="server"
/>
- Register the ASCX control in the page using the <%@ Register directive. Example:
- Now to use the above accounting footer in the page, you can use the below directive:
There are six main types of
validation controls:
- RequiredFieldValidator: It checks whether the control has any value. It is used when you want the control to not be empty.
- RangeValidator: It checks if the value in the validated control is in that specific range. Example, TxtCustomerCode should not be more than eight lengths.
- CompareValidator: It checks that the value in the controls should match some specific value. Example, textbox TxtPie should be equal to 3.14.
- RegularExpressionValidator: When we want the control, the value should match with a specific regular expression.
- CustomValidator: It is used to define User Defined validation.
- ValidationSummary: It displays summary of all current validation errors on an ASP.NET page.
Note: It is rare that someone will ask step by step
about all the validation controls. Rather they will ask for what type of
validation a validator will be used. For example in one of the interviews I was
asked how to display the summary of all errors in a validation control... just
uttered one word: ValidationSummary.
If we want the control to
automatically post back in case of an event, we will need to check this
attribute as true. For example, on a ComboBox change, we need to send the event
immediately to the server side then set the AutoPostBack attribute to true.
Following are the things to be
done in order to enable paging in DataGrid:
- Set AllowPaging to true.
- In the PageIndexChanged event set the current page index clicked.
Note: The answers are very short, if you have
implemented them practically it is just a revision. If you are a fresher, just
make a sample code using a DataGrid and try to implement this functionality.
It allows executing ASP.NET
application level events and setting application-level variables.
Web.config files apply settings to each web application,
while Machine.config file apply settings to all ASP.NET applications.
The Session object stores
information between HTTP requests for a particular user, while the Application
object is global across users.
Comments
Post a Comment