Professional Documents
Culture Documents
AASSPPDDOOTTNNEETT
AASSPPDDOOTTNNEETT
AASSPPDDOOTTNNEETT
There are 2 code models available in ASP.NET 2.0. One is the single-file page and
the other one is the code behind page.
Http is a stateless protocol. Hence the state of controls is not saved between
postbacks. Viewstate is the means of storing the state of server side controls
between postbacks. The information is stored in HTML hidden fields. In other
words, it is a snapshot of the contents of a page.
Page directives configure the runtime environment that will execute the page.
The complete list of directives is as follows:
@ Master - Identifies a page as a master page and defines attributes used by the
ASP.NET page parser and compiler and can be included only in .master files.
@ MasterType - Defines the class or virtual path used to type the Master property
of a page.
@ Page - Defines page-specific attributes used by the ASP.NET page parser and
compiler and can be included only in .aspx files.
@ Reference - Links a page, user control, or COM control to the current page or
user control declaratively.
@ Register - Associates aliases with namespaces and classes, which allow user
controls and custom server controls to be rendered when included in a requested
page or user control.
1
Explain the Validation Controls used in ASP.NET 2.0?
Validation controls allows you to validate a control against a set of rules. There
are 6 different validation controls used in ASP.NET 2.0.
By checking the IsPostBack property. If IsPostBack is True, the page has been
posted back.
Master pages is a template that is used to create web pages with a consistent
layout throughout your application. Master Pages contains content placeholders
to hold page specific content. When a page is requested, the contents of a
Master page are merged with the content page, thereby giving a consistent
layout.
By using the MasterPageFile attribute in the @Page directive and removing some markup.
<%@ Page Language="C#" MasterPageFile="~/Template.master" AutoEventWireup="true"
CodeFile="About.aspx.cs" Inherits="UI.About"
Title="Your Page Title" %>
How do you set the title of an ASP.NET page that is attached to a Master Page?
By using the Title property of the @Page directive in the content page. Eg:
<@Page MasterPageFile="Sample.master" Title="I hold content" %>
What is a nested master page? How do you create them?
A Nested master page is a master page associated with another master page. To
create a nested master page, set the MasterPageFile attribute of the @Master
directive to the name of the .master file of the base master page.
Themes are a collection of CSS files, .skin files, and images. They are text based
style definitions and are very similar to CSS, in that they provide a common look
and feel throughout the website.
A theme contains one or more skin files. A skin is simply a text file with a .skin
extension and contains definition of styles applied to server controls in an
ASP.NET page. For eg:
2
Defines a skin that will be applied to all buttons throughout to give it a
consistent look and feel.
Css is applied to HTML controls whereas skins are applied to server controls.
User controls are reusable controls, similar to web pages. They cannot be
accessed directly.
Create a file with .ascx extension and place the @Control directive at top
of the page.
Included the user control in a Web Forms page using a @Register directive
Custom controls are compiled components that run on the server and that
encapsulate user-interface and other related functionality into reusable
packages. They can include all the design-time features of standard ASP.NET
server controls, including full support for Visual Studio design features such as
the Properties window, the visual designer, and the Toolbox.
User controls have limited support for consumers who use a visual design tool
whereas custom controls have full visual design tool support for consumers.
A separate copy of the user control is required in each application that uses it
whereas only a single copy of the custom control is required, in the global
assembly cache, which makes maintenance easier.
A user control cannot be added to the Toolbox in Visual Studio whereas custom
controls can be added to the Toolbox in Visual Studio.
User controls are good for static layout whereas custom controls are good for
dynamic layout.
Can I deploy the application without deploying the source code on the server?
Yes. You can obfuscate your code by using a new precompilation process called
‘precompilation for deployment’. You can use the aspnet_compiler.exe to
precompile a site. This process builds each page in your web application into a
single application DLL and some placeholder files. These files can then be
deployed to the server.
You can also accomplish the same task using Visual Studio 2005 by using the
Build->Publish menu.
Does ViewState affect performance? What is the ideal size of a ViewState? How
can you compress a viewstate?
Viewstate stores the state of controls in HTML hidden fields. At times, this
information can grow in size. This does affect the overall responsiveness of the
page, thereby affecting performance. The ideal size of a viewstate should be not
more than 25-30% of the page size.
3
Viewstate can be compressed to almost 50% of its size. .NET also provides
the GZipStream orDeflateStream to compress viewstate. Another option is explained
by Scott Hanselmann over here.
You can also view ViewState information as described in this article How to view
information in ViewState using ASP.NET 2.0 and 3.5
Yes. Each page can be written with a different programming language in the
same application. You can create a few pages in C# and a few in VB.NET.
Can the App_Code folder contain source code files in different programming
languages?
No. All source code files kept in the root App_Code folder must be in the same
programming language.
Update: However, you can create two subfolders inside the App_Code and then
add both C# and VB.NET in the respective subfolders. You also have to add
configuration settings in the web.config for this to work.
ASP.NET configures IIS to deny access to any user that requests access to the
Machine.config or Web.config files.
How can I configure ASP.NET applications that are running on a remote machine?
You can use the Web Site Administration Tool to configure remote websites.
You can keep multiple web.config files in an application. You can place a
Web.config file inside a folder or wherever you need (apart from some
exceptions) to override the configuration settings that are inherited from a
configuration file located at a higher level in the hierarchy.
As quoted by Scott Hanselman, the short answer is that the latter gives you
String.Format-style output and the former doesn't.
By default, ASP.NET submits a form to the same page. In cross-page posting, the
form is submitted to a different page. This is done by setting the ‘PostBackUrl’
property of the button(that causes postback) to the desired page. In the code-
behind of the page to which the form has been posted, use the
‘FindControl’method of the ‘PreviousPage’ property to reference the data of the
control in the first page.
4
Yes. To change a master page, set the MasterPageFile property to point to the
.master page during the PreInit page event.
<system.web>
</system.web>
</configuration>
How do you exclude an ASP.NET page from using Themes?
To remove themes from your page, use the EnableTheming attribute of the Page
directive.
Your client complains that he has a large form that collects user input. He wants
to break the form into sections, keeping the information in the forms related.
Which control will you use?
What happens when you change the web.config file at run time?
ASP.NET invalidates the existing cache and assembles a new cache. Then
ASP.NET automatically restarts the application to apply the changes.
Yes. You can use ADSI, WMI, or COM interfaces to configure IIS programmatically.
As explained under the IIS documentation, when you run IIS 6.0 in worker
process isolation mode, you can separate different Web applications and Web
sites into groups known as application pools. An application pool is a group of
one or more URLs that are served by a worker process or set of worker
processes. Any Web directory or virtual directory can be assigned to an
application pool.
Every application within an application pool shares the same worker process.
Because each worker process operates as a separate instance of the worker
process executable, W3wp.exe, the worker process that services one application
pool is separated from the worker process that services another. Each separate
worker process provides a process boundary so that when an application is
assigned to one application pool, problems in other application pools do not
affect the application. This ensures that if a worker process fails, it does not
affect the applications running in other application pools.
Use multiple application pools when you want to help ensure that applications
and Web sites are confidential and secure. For example, an enterprise
organization might place its human resources Web site and its finance Web site
5
on the same server, but in different application pools. Likewise, an ISP that hosts
Web sites and applications for competing companies might run each company’s
Web services on the same server, but in different application pools. Using
different application pools to isolate applications helps prevent one customer
from accessing, changing, or using confidential information from another
customers site.
Web.config files are located in the application's root directory or inside a folder
situated in a lower hierarchy. The machine.config is located in the Windows
directory Microsoft.Net\Framework\Version\CONFIG.
Response.Redirect can be used for both .aspx and html pages whereas
Server.Transfer can be used only for .aspx pages.
Session.Abandon().
What is a webservice?
Web Services are applications delivered as a service on the Web. Web services
allow for programmatic access of business logic over the Web. Web services
typically rely on XML-based protocols, messages, and interface descriptions for
communication and access. Web services are designed to be used by other
programs or applications rather than directly by end user. Programs invoking a
Web service are called clients. SOAP over HTTP is the most commonly used
protocol for invoking Web services.
<%@ Page Language="C#" %>
<script runat="server">
void ImageButton1_Click(object sender, ImageClickEventArgs e) {
Label1.Text = "Postback!";
}
</script>
<html>
<head></head>
<body>
6
<form runat="server">
<p>
<asp:ImageButton id="ImageButton1"
onmouseover="this.src='button2.jpg'"
onclick="ImageButton1_Click"
onmouseout="this.src='button1.jpg'" runat="server"
ImageUrl="button1.jpg"></asp:ImageButton>
</p>
<p>
<asp:Label id="Label1" runat="server" />
</p>
</form>
</body>
</html>