Differentiate between Master Page and Content Page
| Basis | Master Page | Content Page |
|---|---|---|
| Definition | Defines the common layout and structure of multiple ASP.NET pages. | A page that uses the Master Page and provides the actual page-specific content. |
| Extension | Uses .master extension. | Usually uses .aspx extension. |
| Content | Contains common elements such as header, menu, footer, etc. | Contains controls and content specific to that particular page. |
| Relationship | Acts as the template. | Fills the defined ContentPlaceHolder areas of the Master Page. |
| Purpose | Maintains a consistent design across the website. | Displays individual page content while following the common layout. |
Explain GridView and its Features
GridView is an ASP.NET server control used to display data from a data source in a tabular format. It is commonly used to display records retrieved from databases.
Features of GridView
AutoGenerateColumns.BoundField, TemplateField, ButtonField, etc.Example
<asp:GridView ID="GridView1"
runat="server"
AutoGenerateColumns="true">
</asp:GridView>
Explain RequiredFieldValidator and its Use
RequiredFieldValidator is an ASP.NET validation control used to ensure that a specified input field is not left empty. It checks whether the user has entered a value before the form is submitted.
Important Properties
Example
<asp:TextBox ID="txtName" runat="server" />
<asp:RequiredFieldValidator
ID="rfvName"
runat="server"
ControlToValidate="txtName"
ErrorMessage="Name is required." />
Explain AutoPostBack with a Suitable Example
AutoPostBack is a property of ASP.NET server controls that determines whether a control should automatically submit the page back to the server when its value changes.
When AutoPostBack="true", the control immediately causes a postback when the relevant event occurs.
Example
<asp:DropDownList ID="ddlCity"
runat="server"
AutoPostBack="true"
OnSelectedIndexChanged="ddlCity_SelectedIndexChanged">
<asp:ListItem>Ahmedabad</asp:ListItem>
<asp:ListItem>Surat</asp:ListItem>
</asp:DropDownList>
Code-behind:
protected void ddlCity_SelectedIndexChanged(
object sender, EventArgs e)
{
// Code executes automatically after selection changes
}
Here, when the user selects a different city, the page automatically posts back to the server and the SelectedIndexChanged event is executed.
AutoPostBack="true" allows a control to automatically send the page to the server when its value changes.
Explain Web.config and its Importance in ASP.NET
Web.config is an XML configuration file used in ASP.NET applications to store and manage application-level settings and configuration information.
Importance of Web.config
- 01Stores database connection strings.
- 02Configures authentication and authorization.
- 03Controls session state and application settings.
- 04Helps configure custom error handling.
- 05Allows application settings to be changed without modifying the source code.
Example
<configuration>
<appSettings>
<add key="SiteName" value="My Website"/>
</appSettings>
</configuration>
Differentiate between Web Server Controls and HTML Server Controls
| Basis | Web Server Controls | HTML Server Controls |
|---|---|---|
| Definition | ASP.NET controls that run on the server and generate HTML for the browser. | Standard HTML elements that are made accessible to the server using runat="server". |
| Syntax | Uses ASP.NET tags such as <asp:TextBox>, <asp:Button>. | Uses normal HTML tags such as <input>, <button>, <select>. |
| Features | Provide rich properties, events, state management, and data binding. | Provide more basic server-side control over standard HTML elements. |
| Events | Support server-side events such as Click, TextChanged, etc. | Can also be accessed and handled on the server when runat="server" is specified. |
| Example | <asp:Button ID="btn1" runat="server" Text="Click" /> | <input id="btn1" type="button" runat="server" /> |
Differentiate between Master Page and Content Page (Revisited)
| Basis | Master Page | Content Page |
|---|---|---|
| Definition | Provides the common layout and structure for multiple pages. | Provides the specific content for an individual page. |
| File Extension | Uses .master file. | Usually uses .aspx file. |
| Content | Contains common elements such as header, navigation and footer. | Contains page-specific controls and information. |
| ContentPlaceHolder | Defines ContentPlaceHolder controls where content can be inserted. | Provides content for the Master Page's ContentPlaceHolder. |
| Purpose | Maintains a consistent design throughout the website. | Displays different content while using the common design. |
Explain the Login Control with its Important Properties and a Suitable Example
The Login Control in ASP.NET is a ready-made server control used to provide a username and password login interface. It integrates with the ASP.NET Membership Provider, so developers do not need to create the complete login form manually.
Important Properties
- 01UserName — Gets or sets the username entered by the user.
- 02Password — Gets or sets the password entered by the user.
- 03RememberMeSet — Determines whether the user's login should be remembered.
- 04RememberMeText — Specifies the text displayed for the Remember Me option.
- 05DestinationPageUrl — Specifies the page to which the user is redirected after successful login.
- 06FailureText — Specifies the message displayed when login authentication fails.
Example
<asp:Login ID="loginCtrl" runat="server"
DestinationPageUrl="~/Dashboard.aspx"
FailureText="Invalid username or password. Try again." />
This creates a login form with username, password, and Remember Me functionality. If authentication is successful, the user is redirected to Dashboard.aspx; otherwise, the specified failure message is displayed.
Other ASP.NET Login Controls
Differentiate between Client-Side Validation and Server-Side Validation
Validation is the process of checking whether the data entered by the user is correct and follows the required rules. ASP.NET supports both client-side and server-side validation.
| Basis | Client-Side Validation | Server-Side Validation |
|---|---|---|
| Execution | Performed in the user's browser. | Performed on the web server. |
| Technology | Generally uses JavaScript. | Uses server-side code, such as C#. |
| Speed | Faster because no request is sent to the server. | Slower because data must be sent to the server for validation. |
| Server Load | Reduces server requests and load. | Increases server processing and requests. |
| Security | Less secure because client-side validation can be bypassed. | More secure because validation is performed on the server. |
| Use | Useful for immediate feedback to the user. | Essential for validating data before processing or storing it. |
| Example | Checking whether an email has the correct format in the browser. | Checking submitted data against database/business rules on the server. |
Example
ASP.NET validation controls can perform client-side validation using JavaScript and also perform server-side validation. Server-side validation should always be used for security because client-side validation can be bypassed.
<asp:RequiredFieldValidator
ID="rfvName"
runat="server"
ControlToValidate="txtName"
ErrorMessage="Name is required." />
Explain Validation Controls in ASP.NET with Suitable Examples
Validation Controls are ASP.NET server controls used to validate user input before the form is submitted or processed. They help ensure that the data entered by the user is correct and meets the required conditions.
Types of Validation Controls
Checks whether a required field has been left empty.
<asp:TextBox ID="txtName" runat="server" />
<asp:RequiredFieldValidator
ID="rfvName"
runat="server"
ControlToValidate="txtName"
ErrorMessage="Name is required." />
Compares the value of one control with another control or a specified value.
<asp:CompareValidator
ID="cvPassword"
runat="server"
ControlToValidate="txtConfirm"
ControlToCompare="txtPassword"
ErrorMessage="Passwords do not match." />
Checks whether the entered value falls within a specified range.
<asp:RangeValidator
ID="rvAge"
runat="server"
ControlToValidate="txtAge"
MinimumValue="18"
MaximumValue="60"
Type="Integer"
ErrorMessage="Age must be between 18 and 60." />
Validates input according to a specified regular expression pattern, such as an email or phone number format.
<asp:RegularExpressionValidator
ID="revEmail"
runat="server"
ControlToValidate="txtEmail"
ValidationExpression="^[^@\s]+@[^@\s]+\.[^@\s]+$"
ErrorMessage="Enter a valid email." />
Allows the developer to define custom validation logic when the built-in validators are not sufficient.
<asp:CustomValidator
ID="cvCustom"
runat="server"
ControlToValidate="txtCode"
ErrorMessage="Invalid code."
OnServerValidate="ValidateCode" />
Displays the validation error messages together in one place.
<asp:ValidationSummary
ID="ValidationSummary1"
runat="server" />
Common Properties
Explain Theme in ASP.NET
An ASP.NET Theme is a mechanism used to provide a consistent appearance and styling to an ASP.NET web application. A Theme can define properties of server controls, such as colors, fonts, backgrounds and other control properties. It uses .skin files along with CSS files and is stored inside the App_Themes folder.
1. Theme Folder
Themes are stored in the special App_Themes folder. For example:
App_Themes/
BlueTheme/
BlueTheme.skin
Site.css
The .skin file defines default properties for ASP.NET server controls, while CSS files can define the styling of the rendered HTML.
2. Creating a Theme
In Visual Studio: Right-click Project → Add → Add ASP.NET Folder → Theme. A theme folder is created inside App_Themes. It can then be renamed, for example, to BlueTheme.
3. Applying a Theme
A Theme can be applied in three ways.
To apply the Theme to the entire website:
<system.web>
<pages theme="BlueTheme" />
</system.web>
To apply it to a particular page:
<%@ Page Theme="BlueTheme" %>
A Theme can also be assigned in the Page_PreInit event:
protected void Page_PreInit(object sender, EventArgs e)
{
Page.Theme = "BlueTheme";
}
Page_PreInit, not Page_Load, because by Page_Load it is too late to apply the Theme to the controls.4. .skin File
A .skin file defines the default appearance and properties of ASP.NET server controls. For example:
<asp:Button runat="server"
BackColor="Blue"
ForeColor="White"
Font-Bold="true" />
This can automatically apply the specified properties to Button controls using the Theme. A SkinID can also be used when different styles are required for the same type of control:
<asp:Button
runat="server"
SkinID="DangerButton"
Text="Delete" />
Thus, multiple skins can be created for the same control type within one Theme.
5. Theme vs StylesheetTheme
| Theme | StylesheetTheme |
|---|---|
| Has higher priority. | Has lower priority. |
| Overrides a control's own property settings. | Can be overridden by the control's own properties. |
| Used when a consistent appearance must be enforced. | Used when default styles should be provided but controls may customize them. |
For example, if a Button has its own BackColor and the Theme also specifies BackColor, the Theme overrides the control's setting, whereas with StylesheetTheme, the control's explicit setting can override the theme.
Advantages of ASP.NET Themes
- 01Provides a consistent look and feel throughout the application.
- 02Allows styles for server controls to be defined centrally.
- 03Reduces repeated styling code.
- 04Makes it easier to change the appearance of an entire website.
- 05Supports multiple skins for the same type of server control using SkinID.
What is Master-Detail Relationship in Terms of Data Binding Controls? Demonstrate with an Example
A Master-Detail relationship in ASP.NET data binding is a relationship where one data-bound control displays a list of records (Master) and another data-bound control displays the details of the record selected in the Master control.
For example, in a college application:
- 01Master: List of students displayed in a GridView.
- 02Detail: Details of the selected student displayed in a DetailsView or another data-bound control.
ASP.NET provides data-binding controls such as GridView, FormView and Repeater for displaying data.
Example: Student Master-Detail
Suppose we have a Students table:
| StudentID | Name | Course |
|---|---|---|
| 1 | Rahul | BCA |
| 2 | Priya | BCA |
| 3 | Amit | BBA |
The GridView can act as the Master control and display all students. When the user selects Rahul, the Detail control can display Rahul's complete information.
Master Control — GridView
<asp:GridView ID="gvStudents"
runat="server"
AutoGenerateColumns="False"
AutoGenerateSelectButton="True"
DataKeyNames="StudentID"
OnSelectedIndexChanged="gvStudents_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="StudentID"
HeaderText="ID" />
<asp:BoundField DataField="Name"
HeaderText="Name" />
<asp:BoundField DataField="Course"
HeaderText="Course" />
</Columns>
</asp:GridView>
The GridView displays the master list and provides a Select option for choosing a record.
Detail Control
A DetailsView can then display the selected student's detailed information:
<asp:DetailsView ID="dvStudent"
runat="server"
AutoGenerateRows="true">
</asp:DetailsView>
Code-Behind
When the user selects a student, the selected student's ID can be used to retrieve the corresponding record:
protected void gvStudents_SelectedIndexChanged(
object sender, EventArgs e)
{
int id = Convert.ToInt32(
gvStudents.DataKeys[
gvStudents.SelectedIndex].Value);
// Fetch student details using id
// and bind them to dvStudent
}
The basic flow is:
Database
↓
GridView (Master)
↓
User selects a Student
↓
StudentID
↓
DetailsView (Detail)
↓
Selected Student's Details
Advantages of Master-Detail Binding
- 01Easy navigation: Users can select a record from a list and immediately view its details.
- 02Better organization: Large amounts of data can be divided into a summary list and detailed information.
- 03Improved usability: Users do not need to display all information in one large table.
- 04Efficient data presentation: The master control shows only important fields while the detail control displays complete information.
CSS (Cascading Style Sheets)
CSS (Cascading Style Sheets) is a stylesheet language used to define the appearance and layout of web pages. It controls properties such as colors, fonts, spacing, borders, backgrounds, and positioning of HTML elements.
In ASP.NET, CSS can be used to style both normal HTML elements and ASP.NET server controls through the CssClass property.
Example
CSS file – Site.css:
.header {
background: #003366;
color: white;
text-align: center;
padding: 15px;
}
.content {
padding: 20px;
}
Using CSS in an ASP.NET page:
<link href="Site.css" rel="stylesheet" />
For an ASP.NET server control:
<asp:TextBox ID="txtName"
runat="server"
CssClass="input-field" />
Here, CssClass="input-field" applies the CSS class to the TextBox.
Types of CSS
Advantages of CSS
- 01Provides a consistent design throughout a website.
- 02Separates presentation from HTML structure.
- 03Makes pages easier to maintain.
- 04Reduces repeated styling code.
- 05Allows the same stylesheet to be used across multiple pages.
In ASP.NET, linking a CSS file in a Master Page allows all content pages using that Master Page to automatically receive the same styling.