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" />